springData Jpa

1. Annotation

   (1) @Data : Use @Data on beans to omit get and set methods

   (2) @Entity : Represents an entity class

   (3) @Table : Use @Table on the bean class (name="tableName") name is the database table name

   (4) @Id @GeneratedValue : used on the primary key field to represent the primary key

   (5) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") The time field sets the time format

 

   (6)  @Temporal: Attribute of Date type, which may be stored in the database as 'yyyy-MM-dd hh:MM:ss' To get the year, month, and day when querying, marking this attribute with @Temporal(TemporalType.DATE) will Get a date in the format 'yyyy-MM-dd',      @Temporal(TemporalType.TIME) will get a date in the format 'HH:MM:SS', @Temporal(TemporalType.TIMESTAMP) will get a date in the format ' yyyy- Date in MM-dd hh:MM:ss ' format

 

   (7)  @Column(name="zd",nullable=false,length=512):  Specify the field " zd 's length 512 ", and the value cannot be null

        @Column(name="zd", precision=12, scale=2)  is of type double with 12 digits of precision and 2 digits of decimal point .

        @Column(name="zd",columnDefinition="clob not null")  Customize the SQL statement for generating CLOB type fields, equivalent to contact_name clob (200) not null

      @Column(updatable=false)  When inserting data using " UPDATE " script, the value of this field does not need to be updated

      @Column( insertable = false )  Whether the value of this field needs to be inserted when inserting data using the " INSERT " script.

       (7-1)  The unique attribute indicates whether the field is a unique identifier, and the default value is false . If there is a field in the table that needs to be uniquely identified, you can use either that tag or @UniqueConstraint in the @Table tag .  

       ( 7-2   The nullableproperty indicates whether the field can be anullvalue, and the default istrue.

      ( 7-3   The insertableattribute indicateswhether the value of the field needs to be inserted when inserting dataINSERT

      ( 7-4   The updatableattribute indicates whether the value of this field needs to be updated when data is inserted using the "UPDATE" script. The insertableandupdatableattributes are generally used for read-only attributes, such as primary keys and foreign keys. The values ​​for these fields are usually automatically generated.

      ( 7-5     The columnDefinitionattribute indicates that when creating a table, theSQLstatement created by this field is generally used togenerate table definitionsEntity

       ( 7-6    The tableattribute represents the fields in the table of the specified table when mapping multiple tables. The default is the table name of the main table.

       (7-7   length属性表示字段的长度,当字段的类型为varchar时,该属性才有效,默认为255个字符。

      (7-8  precision属性和scale属性表示精度,当字段类型为double时,precision表示数值的总长度,scale表示小数点所占的位数。

 

     (8) @Query(value="hql")   hql 中 表明是对应的实体类名(即用实体类名代替表名 如 select  o from 实体类名 o where  zd =?1 (两处的o要一致))   2.索引值从1开始,查询中'?x'的个数要和方法的参数个数一致,且顺序也要一致

      @Query(value="select count(1) from 表名",nativeQuery=true)   :nativeQuery=true 表示hql中使用的是数据库表名查询

        (9) @Param :  如果在@Query 使用:cs的形式则在方法的需要用@Param 接收参数,如@Query(value=" SELECT b FROM OutLink b where URL like %:url%") 则接口的方法要这样写:void findByUrl(@Param(value = "url") String url);

        (10)@Modifying  在更新或删除时 在@Query 上加上该注解

        (11) @Transactional  事物管理 在更新或删除时 必须在servide层的实现类相应的方法上加上该注解,否则会报错

        (12)@RestController:相当于@ResponseBody + @Controller , 如果只是使用@RestController注解Controller,则Controller中的方法无法返回jsp页面,或者html,配置的视图解析器 InternalResourceViewResolver不起作用,返回的内容就是Return 里的内容。如果需要返回到指定页面,则需要用 @Controller配合视图解析器InternalResourceViewResolver才行,如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。 @RestController注解,相当于@Controller+@ResponseBody两个注解的结合,返回json数据不需要在方法前面加@ResponseBody注解了,但使用@RestController这个注解,就不能返回jsp,html页面,视图解析器无法解析jsp,html页面  这是springMvc的知识

 

比较详细的lianjie:http://www.360doc.com/content/15/0924/12/834950_501215239.shtml

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326007079&siteId=291194637