美文网首页
Spring 注解

Spring 注解

作者: 简书超级会员 | 来源:发表于2018-08-06 20:56 被阅读13次
1.Spring 注解
名称 用法 说明
@Aspect 使之成为切面类 AOP统一处理
@After 所拦截方法执行之后执行
@Around 同时在所拦截方法的前后执行
@AfterReturning @AfterReturning(returning = "object", pointcut = "log()") 增强处理
@AutoConfigureMockMvc 对于API的测试
@ Before @Before("log()") 所拦截方法执行之前执行
@ConfigurationProperties @ConfigurationProperties(prefix = "girl") 在类文件中读取全局配置
@Column @Column(length = 30) 默认长度
@Controller @Controller 处理http请求
@Component 不属于@Controller、@Services等的时候 使用他来标注这个类
@ControllerAdvice @ExceptionHandler一起使用 当抛出一个异常是@ControllerAdvice 和@ExceptionHandler都会生效
@Valid @Valid
@component
@Column @Column(nam=”category_name” length=20) Public void getCategoryName(){ Return this.categoryName; 声明该属性与数据库字段的映射关系。
@DynamicUpdate 创建实例更新时间 更新时间
@Entity 对实体注释 数据库
@GeneratedValue 指定主键的生成策略(TABLE、IDENTITY、SEQUENCR、AUTO) 根据数据库的不同使用上面三个
@GetMapping 简化@RequestMapping接口 推荐
@Id 该属性值可以通过应该自身创建 声明此属性为主键。
@JsonProperty @JsonProperty("name") 创建表字段的别名返回
@JsonInclude @JsonInclude(JsonInclude.Include.NON_NULL) 处理返回来的结果是null的不输出字段
@JsonIgnore @JsonIgnore 处理返回来的结果不包含方法
@Modifying 跟sql语句结合使用 可修改的
@Min @Min(value = 18,message = "未成年人禁止入内") 表单验证
@Pointcut @Pointcut("execution(public * com.hanxing.girl.controller.GirlController*(..))") 切入点
@PathVariable say(@PathVariable("id") Integer id) hello/100获取URL中的数据
@Query @Query(select o from Employee o where id = (select max(id) from Employee t1)) 使用注解在jpa中更加灵活
@Query @Query(value="select o from Employee o where o.name=?1 and o.age=?2") 按照条件(占位符)查询
@Query @Query(value="select o from Employee o where o.name=:name") 方法参数(@Param("name")String name )
@Query @Query(value = "select o from Girl o where o.cupSize like CONCAT('%',:cupSize ,'%') ") 模糊查询CONCAT('%',:cupSize ,'%')
@RestController @Controller + @ResponseBody相当于这两个注解同时使用 推荐
@RequestMapping @RequestMapping(value = {"/hello/:id","hi"}, method = RequestMethod.GET) value = "/hello" 配置url映射GET
@RequestParam @RequestParam(value = "id",required = false,defaultValue = "0") Integer id GET请求参数的值
@RequestBody @RequestBody Map<String,Integer> reqMap;接收reqMap.get("page") POST请求传递参数
@RunWith @RunWith(SpringRunner.class) 就是一个运行器
@Service
@SpringBootTest 启动Spring的工程
@Transactional 事物操作 同时操作多条数据
@Table @Table(name = "proud_category") 数据库的名字可以跟类型不一致
@Table @Table(name = "proud_category") 数据库的名字可以跟类型不一致
@Value @Value("${CupSize}") 读取全局变量
@Valid
@RequestBody@Valid OrderForm orderForm,BindingResultbindingResult if(bindingResult.hasErrors()){return null}验证
@CacheConfig @CacheConfig(cacheNames = "BuyerOrder") 全局缓存名称
@Cacheable @Cacheable(key = "list"),动态添加key@Cacheable(key = "#list",condition = "#openId.length()>2",unless = "result.getCode()!=0") 缓存key[key\condition\unless]
@CachePut @ CachePut(key = "list") 更新缓存key
@ CacheEvict @CacheEvict(key = "list") 移除缓存key
2.mybatis常用标签
3.Repository中查询方法定义规则和使用

w

相关文章

网友评论

      本文标题:Spring 注解

      本文链接:https://www.haomeiwen.com/subject/fxxgmftx.html