<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### JPA對象注解 * @Table - 映射表名 * @Id - 主鍵 * @GeneratedValue(strategy=GenerationType.IDENTITY) - 自動遞增生成 * @Column(name = "dict_name",columnDefinition="varchar(100) COMMENT '字典名'") - 字段名、類型、注釋 * @UpdateTimestamp - 更新時自動更新時間 * @CreationTimestamp - 創建時自動更新時間 * @Version - 版本號,更新時自動加1 ### 用法: ``` @Entity @Table(name="c_user") public class User { @Id @GeneratedValue private Long id; @NotNull @Column(length = 50) private String userName; @NotNull @Column(length = 20 , unique = true, nullable = false) private Long mobile; @Column(length = 20 , unique = true) private String email; @NotNull @Column(columnDefinition="tinyint") private Integer status; private String password; private String nickname; private Integer companyId; private Integer departmentId; private Date regTime; private String regIp; private Integer loginNum; ... } ``` ## @Table @Table注解用來標識實體類與數據表的對應關系,默認和類名一致。 ## @Column @Column注解來標識實體類中屬性與數據表中字段的對應關系。共有10個屬性,這10個屬性均為可選屬性: * name屬性定義了被標注字段在數據庫表中所對應字段的名稱; * unique屬性表示該字段是否為唯一標識,默認為false。如果表中有一個字段需要唯一標識,則既可以使用該標記,也可以使用@Table標記中的@UniqueConstraint。 * nullable屬性表示該字段是否可以為null值,默認為true。如果屬性里使用了驗證類里的@NotNull注釋,這個屬性可以不寫。 * insertable屬性表示在使用“INSERT”腳本插入數據時,是否需要插入該字段的值。 * updatable屬性表示在使用“UPDATE”腳本插入數據時,是否需要更新該字段的值。insertable和updatable屬性一般多用于只讀的屬性,例如主鍵和外鍵等。這些字段的值通常是自動生成的。 * columnDefinition屬性表示創建表時,該字段創建的SQL語句,一般用于通過Entity生成表定義時使用。若不指定該屬性,通常使用默認的類型建表,若此時需要自定義建表的類型時,可在該屬性中設置。(也就是說,如果DB中表已經建好,該屬性沒有必要使用。) * table屬性定義了包含當前字段的表名。 * length屬性表示字段的長度,當字段的類型為varchar時,該屬性才有效,默認為255個字符。 * precision屬性和scale屬性表示精度,當字段類型為double時,precision表示數值的總長度,scale表示小數點所占的位數。 ### 可以標注在getter方法或屬性前: 標注在屬性前: ``` @Column(name = " c_name ") private String name; public String getName() { return name; } ``` 標注在getter方法前: ``` private String name; @Column(name = " c_name ") public String getName() { return name; } ``` ### 例子: 指定字段“contact_name”的長度是“512”,并且值不能為null。 ``` @Column(name="ct_name",nullable=false,length=512) private String name; ``` 指定字段“price”月收入的類型為double型,精度為12位,小數點位數為2位。 ``` @Column(name="price",precision=12, scale=2) private BigDecimal price; ``` ### 字段的默認值 很簡單聲明的時候直接賦值即可: ``` @Column(columnDefinition="tinyint") private Integer status = 1; ``` 還有另外一種寫法: ``` @Column(name="state", nullable=false, columnDefinition="tinyint default 0") private Interger state; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看