spring boot 入门

2017-08-14  本文已影响0人  hubeiqiyuan

前置知识:

1:注解了解

2:maven 基础知识

3:yaml 基础

新建spring initializr web项目,DemoApplication 运用到的注解 @SpringBootApplication @ComponentScan("com.example.demo")

编写controller 运用到的注解 @RestController @RequestMapping("properties")

编写属性配置 运用到的注解 @Value("${age}") 单个属性 若有多个属性编写bean 类 运用到的注解 @ConfigurationProperties(prefix="girl") @Component

属性配置类

注:这里运用application.yml 来替代application.property .文件名是固定的,否则访问不到

多环境配置 运用到的注解 spring.profiles.active

修改对应的属性文件名称

controller的使用 @RestController=@Controller+@ResponBody

@RequestMapping("properties") 配置Url 映射,就是访问的url 地址 可以是某各类或者某个方法 也可拼接

为请求设置参数 写在请求方法的参数中 @PathVariable 替换Url 指定的路径 @RequestParam(value="id",required=false,defaultValue="0") Integer id 

明天整一个用spring boot 的数据库的增删改查demo

上一篇 下一篇

猜你喜欢

热点阅读