09 Hibernate的Annotation注解

一、声明实体

@Entity
对实体注释。任何Hibernate映射对象都要有这个注释

@Table
声明此对象映射到数据库的数据表,通过它可以为实体指定表(talbe),该注释不是必须的,如果没有则系统使用默认值(实体的短类名)。

@Version
该注释可用于在实体Bean中添加乐观锁支持。
二、声明主键
@Id
声明此属性为主键。该属性值可以通过应该自身创建,但是Hibernate推荐通过Hibernate生成

@GeneratedValue
指定主键的生成策略。有如下四个值

  • TABLE:使用表保存id值
  • IDENTITY:identitycolumn(主键由数据库自动生成(主要是自动增长型))
  • SEQUENCR :sequence
  • AUTO:根据数据库的不同使用上面三个

@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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • MYSQL 基础知识 1 MySQL数据库概要 2 简单MySQL环境 3 数据的存储和获取 4 MySQL基本操...
    Kingtester阅读 12,341评论 5 116
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,146评论 0 13
  • 一、MySQL优化 MySQL优化从哪些方面入手: (1)存储层(数据) 构建良好的数据结构。可以大大的提升我们S...
    宠辱不惊丶岁月静好阅读 7,257评论 1 8
  • 一. Java基础部分.................................................
    wy_sure阅读 9,246评论 0 11
  • 作为正宗的陕西人,感觉不趁着年轻上华山,真的很可惜呢。 我们团队本来有四个女生,临行前一天,有个同学有些突发状况去...
    Ai叶zi阅读 4,292评论 0 2