pom.xml
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.8.RELEASE</version></parent><dependencies><!--web依赖开始 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
启动类建议放在根目录下
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.servlet.config.annotation.EnableWebMvc;/*** @Author sunli* @Date /8/15 10:51*/@SpringBootApplication@EnableWebMvc//开启webpublic class Starter {public static void main(String[] args) {SpringApplication.run(Starter.class,args);}}控制层controller类package .sddz.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/*** @Author sunli* @Date /8/15 10:55*/@RestControllerpublic class TestController { //解决乱码的一种方式@RequestMapping(value = "/test" ,produces="application/json;charset=UTF-8")public String home() {System.out.println("springboot项目启动成功!");return "springboot项目启动成功!";}}