springboot常用注解的使用
2018-10-01 15:55
501 查看
Controller:
@Controller:处理http请求
@RestController :返回json格式的数据。相当于@Controller+@ResponseBody
@RequestMapping:配置URL映射
@PathVariable:获取URL中的数据
[code]//简洁请求方式:127.0.0.1:8080/hello/say/111 @RestController @RequestMapping("/hello") public class TestController{ @RequestMapping(value="/say/{id}",method = RequestMethod.GET) public String say(@PathVariable("id") Integer myId){ return "id:" + myId ; } }
@RequestParam:获取请求参数的值
[code]//传统请求方式:127.0.0.1:8080/hello/say?id=111 @RestController: @RequestMapping("/hello") public class TestController{ @RequestMapping(value="/say",method = RequestMethod.GET) // @GetMapping(value="/say") // public String say(@RequestParam(value="id") Integer myId){ public String say(@RequestParam(value="id",required=false,defaultValue="0") Integer myId){ //required =false 标示非必传参数 return "id:" + myId ; } }
@GetMapping:查询
@PostMapping 添加
@PutMapping 更新
@DeleteMapping 删除
Dao
//实体类可以自动生成表
[code]spring: profiles: active: dev datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/xxx username: root password: 123456 jpa: hibernate: ddl-auto: create //注意这个create每次启动都会删除表后新建表。如果是update也会新建表,原来有相同的表里面有数据,会保留数据创建表。create-drop表示应用停下来的时候会自动删除表。none什么都不做。validate 会验证类的属性和表的字段是否一致,不一致会报错 show-sql: true
@Entity 实体类映射表
@Id
@GeneratedValue 与@Id一起加到id属性上,id自增
阅读更多相关文章推荐
- spring boot 的常用注解使用小结
- spring boot 的常用注解使用 总结
- spring boot常用注解使用小结
- Spring Boot 2.0.0.M3使用案例,案例配置,常用命令,注解介绍,热部署
- spring boot 的常用注解使用 总结
- spring boot 的常用注解使用 总结
- SpringBoot | 第六章:常用注解介绍及简单使用
- Spring Boot中使用MyBatis注解配置详解
- Spring常用注解 使用注解来构造IoC容器
- Springboot 常用注解
- spring入门及常用注解的使用
- spring boot 计划任务,定时任务的注解的使用@Scheduled@EnableScheduling
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(六): 一些常用的数据库 注解
- Spring Boot常用注解
- (15)spring boot使用@Value,@PropertySource注解使用
- 在Spring Boot中使用 @ConfigurationProperties 注解
- Spring Boot中使用MyBatis注解配置详解
- SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍
- SpringBoot中MongoDB注解概念及使用
- 转载:注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(六): 一些常用的数据库 注解