spring boot之常用注解(二)
Controller常用注解
@Controller
处理http请求
@RestController
Spring4之后新加的注解,原来返回json数据需要@ResponseBody配合@Controller,现在合并成@RestController
@RequestMapping
配置url映射,value配置url方法路径,method配置请求方式, 例:@RequestMapping(value="hello",method = RequestMethod.GET)
@PathVariable
获取url中的数据,,请求的url方式 : url路径/value ,例: http://localhost:8080/hi/1 ,请求方式相对于@RequestParam简洁
@RequestParam
获取请求参数的值,@RequestParam(value = "id",required = false,defaultValue = "1") value即传参名称,required = false不是必须传入(默认为true),defaultValue 当不传入参数时的默认值
请求的url方式 : url路径?key=value 例: http://localhost:8080/hi?id=1
@GetMapping和@PostMapping
组合注解,@GetMapping等同于@RequestMapping(method = RequestMethod.GET),@PostMapping等同于@RequestMapping(method = RequestMethod.POST)
即@GetMapping接收的是get请求,@PostMapping接收的是post请求
Repository注解
@Entity 对实体类的注释,表明此类映射数据库的表
对属性的注释:
1.@Id此属性为主键
2.@GenerateaValue 设置为自增列
3.@Column(name = "password",unique = true,nullable = false,length = 255) 可设置列名、唯一属性、不为空、长度等。
4.@Min/Max 设置最小值或最大值
...
Service注解
@Service 对实体类的注释,表明此类为业务层。
@Transactional 可对实体类或方法进行注释,对实体类注释表明此类的全部方法都是用事务。一般使用在方法中有多条执行更新数据库的语句。以防执行错误导致数据错误。
其他注解
@Component 表明此类将注入Spring容器给予管理,而@Repository、@Service和@Controller的注解接口都使用了@Component
下面是Spring的@Service注解接口
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Component public @interface Service { String value() default ""; }
- spring boot 的常用注解使用 总结
- SpringBoot 中常用注解@Controller/@RestController/@RequestMapping介绍(转)
- spring boot之spring mvc常用注解(2)
- spring boot 实体类常用注解范例
- springboot常用注解(包含spring及MVC)
- springboot常用注解
- SpringBoot中常用注解@Controller/@RestController/@RequestMapping的区别
- Spring Boot---(5)SpringBoot常用注解
- Spring Boot常用注解
- SpringBoot | 第六章:常用注解介绍及简单使用
- Springboot 常用注解
- SpringBoot中常用的注解
- Springboot 常用注解
- springboot常用注解总结
- springboot部分常用注解
- 11-SpringBoot——Spring MVC基础-常用注解
- Spring boot 中常用的注解
- spring boot 的常用注解使用 总结
- Springboot 常用注解
- springBoot Restfull 常用注解