SpringBoot 快速搭建web项目(s1)

pom.xml文件修改

  • 引入spring-boot支持

    org.springframework.boot
    spring-boot-starter-parent
    1.5.2.RELEASE
```
* 新增属性

1.8

* 添加依赖关系



org.springframework.boot
spring-boot-starter



org.springframework.boot
spring-boot-starter-test
test



org.springframework.boot
spring-boot-starter-web

springboot官方推荐我们使用spring-boot-starter-parent,spring-boot-starter-parent包含了以下信息:
* 使用java6编译级别
* 使用utf-8编码
* 实现了通用的测试框架 (JUnit, Hamcrest, Mockito).
* 智能资源过滤
* 智能的插件配置(exec plugin, surefire, Git commit ID, shade).
---
##S1.java(SpringMVC中的Controller)

package sbsc.s1.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class S1 {

@RequestMapping(value = "/demo", method = RequestMethod.GET)
public Map demo()
{
    Map ret = new HashMap<>();
    ret.put("ret", "hello world");
    return ret;
}

}

---
##App.java(启动程序)

package sbsc.s1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**

  • Hello world!

*/
@SpringBootApplication
public class App
{
public static void main(String[] args)
{
SpringApplication.run(App.class,args);
}
}

---
启动后访问http://127.0.0.1/demo
跟spring比较,开发web项目简单了很多。

你可能感兴趣的:(SpringBoot 快速搭建web项目(s1))