0.插件一个maven项目
1.导入jar包
2.写注解
3.运行
<!--提供依赖管理,引入以后再申明其他dependence的时候就不需要version了,而且还提供了很多别的依赖jar包--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
<!--spring-web的核心组件--> <!--springboot会自动集成springmvc,引入springboot-web依赖即可,不需要写版本了--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
创建一个类:
1.这个类上要有@RestController注解,这个@RestController=@Controller+@ResponseBody ,
这样子返回的值,不加@responseBody也是json数据,可以被页面解析。
2.EnableAutoConfiguration告诉spring根据我的jar依赖来对我的spring框架自动装配。(最好只写一个)
3.添加一个main方法,在里面写SpringApplication.run(这个启动类的Class,args)。标识为启动类。
4.右键运行,springBoot的端口号默认为8080,此时项目已经被打包并且启动了tomcat了,
在网页地址栏上打: localhost:808/hello,可以看到一个helloWorld
@RestController @EnableAutoConfiguration public class HelloController { @RequestMapping("/hello") public String index() { return "Hello World"; } public static void main(String[] args) { SpringApplication.run(HelloController.class, args); } }
全局绑定异常:
https://www.cnblogs.com/magicalSam/p/7198420.html