SpringBoot 入门学习 慕课网

SpringBoot的属性配置

  • 建议将application.properties换成application.yml

  • yaml通过缩进行 对齐进行表示层次关系 如下表示girl.cupSize和girl.age属性

    girl: cupSize: D age: 18

*在spring的controller中使用配置文件中的属性

    @Value("${cupSize}")
    private  String cupSize;
  • 还可以在配置文件中使用配置文件中的属性 如下在context中使用了girl.age属性

    girl: cupSize: D age: 18 context: "age: ${girl.age}"

controller的使用

输入图片说明

输入图片说明

  • PathVariable的使用:用来获取在路径中的参数 如下:

    //访问方式 http://localhost:8080/hello/110
    @RequestMapping("/hello/{id}")
    public String sayHello(@PathVariable("id") Integer id){
       return id+"";
    }
    
  • GetMapping是RequestMapping注解的简写 指定了访问方法为Get 类似还有Post等

数据库操作 唉 不会jpa在等等吧

学习视频地址:https://www.imooc.com/video/13592

评论

暂无评论