一、聲明實體
@Entity
對實體注釋。任何Hibernate映射對象都要有這個注釋
@Table
聲明此對象映射到數(shù)據(jù)庫的數(shù)據(jù)表,通過它可以為實體指定表(talbe),該注釋不是必須的,如果沒有則系統(tǒng)使用默認值(實體的短類名)。
@Version
該注釋可用于在實體Bean中添加樂觀鎖支持。
二、聲明主鍵
@Id
聲明此屬性為主鍵。該屬性值可以通過應該自身創(chuàng)建,但是Hibernate推薦通過Hibernate生成
@GeneratedValue
指定主鍵的生成策略。有如下四個值
- TABLE:使用表保存id值
- IDENTITY:identitycolumn(主鍵由數(shù)據(jù)庫自動生成(主要是自動增長型))
- SEQUENCR :sequence
- AUTO:根據(jù)數(shù)據(jù)庫的不同使用上面三個
@Aspect :使之成為切面類 (AOP統(tǒng)一處理)
@After:所攔截方法執(zhí)行之后執(zhí)行
@Around:同時在所攔截方法的前后執(zhí)行
@AfterReturning:@AfterReturning(returning = "object", pointcut = "log()")
(增強處理)
@AutoConfigureMockMvc (對于API的測試)
@ Before:@Before("log()") (所攔截方法執(zhí)行之前執(zhí)行)
@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; 聲明該屬性與數(shù)據(jù)庫字段的映射關系。
@DynamicUpdate 創(chuàng)建實例更新時間 更新時間
@Entity 對實體注釋 數(shù)據(jù)庫
@GeneratedValue 指定主鍵的生成策略(TABLE、IDENTITY、SEQUENCR、AUTO) 根據(jù)數(shù)據(jù)庫的不同使用上面三個
@GetMapping 簡化@RequestMapping接口 推薦
@Id 該屬性值可以通過應該自身創(chuàng)建 聲明此屬性為主鍵。
@JsonProperty @JsonProperty("name") 創(chuàng)建表字段的別名返回
@JsonInclude @JsonInclude(JsonInclude.Include.NON_NULL) 處理返回來的結果是null的不輸出字段
@JsonIgnore @JsonIgnore 處理返回來的結果不包含方法
@Modifying 跟sql語句結合使用 可修改的
@Min @Min(value = 18,message = "未成年人禁止入內(nèi)") 表單驗證
@Pointcut @Pointcut("execution(public * com.hanxing.girl.controller.GirlController*(..))") 切入點
@PathVariable say(@PathVariable("id") Integer id) hello/100獲取URL中的數(shù)據(jù)
@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") 方法參數(shù)(@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請求參數(shù)的值
@RequestBody @RequestBody Map<String,Integer> reqMap;接收reqMap.get("page") POST請求傳遞參數(shù)
@RunWith @RunWith(SpringRunner.class) 就是一個運行器
@Service @SpringBootTest 啟動Spring的工程
@Transactional 事物操作 同時操作多條數(shù)據(jù)
@Table @Table(name = "proud_category") 數(shù)據(jù)庫的名字可以跟類型不一致
@Table :@Table(name = "proud_category") 數(shù)據(jù)庫的名字可以跟類型不一致
@Value @Value("${CupSize}") 讀取全局變量
@Valid
@RequestBody@Valid OrderForm orderForm,BindingResultbindingResult if(bindingResult.hasErrors()){return null}驗證
@CacheConfig @CacheConfig(cacheNames = "BuyerOrder") 全局緩存名稱
@Cacheable @Cacheable(key = "list"),動態(tài)添加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