springboot

来源:互联网 发布:arp s绑定mac 编辑:程序博客网 时间:2024/06/10 23:09

springboot的特点

  1. 化繁为简,简化配置
  2. 备受关注,是下一代框架
  3. 微服务的入门级微框

三种启动springboot方式

  1. 第一种是在编译器中启动app类。第二种是在原项目文件中mvn spring-boot:run的mvn方式启动。第三种是先在mvn install的maven编译,找到target目录中有一个jar包文件(版本号和名称与项目相同的),使用java -jar 文件名 的方式启动

3个注解的使用:postman

    a. @Value  从配置文件读取参数 
     @Value("${tea}")     private String tea;

  b. @ConfigurationProperties 把yml里面一组配置参数封装成一个类 c. @Component 向SpringBoot注册一个类
@Component@ConfigurationProperties(prefix = "student")public class Student {

                    开发环境-生产环境

      spring:        profiles:          active: dev@PathVariable   获取url中的数据     http://localhost:8080/{id}/hello    http://localhost:8080/12/hello    @RequestMapping(value = "/{id}/hello", method = RequestMethod.GET)    public String sayHello(@PathVariable("id") Integer id) {            return "id" + id;        }@RequestParam   获取请求参数的值    http://localhost:8080/hello?id=12    @RequestMapping(value = "/hello", method = RequestMethod.GET)        public String sayHello(@RequestParam(value = "id", required = false, defaultValue = "0") Integer myid) {            return "id" + myid;        }@GetMapping     组合注解    @GetMapping("hello")   等于    @RequestMapping(value = "/hello", method = RequestMethod.GET)    @PostMapping("hello")   等于    @RequestMapping(value = "/hello", method = RequestMethod.POST)