<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>

                ## 創建實體類 1. 因為`POJO / VO / DTO`等等是會被其他模塊依賴引用的,所以我們需要把實體類建在`blade-demo-api`工程內。 ![](https://box.kancloud.cn/09248be00942b2311a36a9e84cdc937f_908x394.png) 2. 參照新建表的字段,我們給實體類增加如下字段。 ~~~ public class Blog { /** * 主鍵 */ private Integer id; /** * 標題 */ private String blogTitle; /** * 內容 */ private String blogContent; /** * 時間 */ private LocalDateTime blogDate; /** * 是否已刪除 */ private Integer isDeleted; } ~~~ ### 注: * 看到這里可能有小伙伴就有疑問了,為什么數據庫中字段以下劃線分割,到了實體類就變成了駝峰? * 因為這么做更加優雅,也更加規范。 * 比如Mysql數據庫字段命名為 blogTitle,乍一看沒問題,但到了oracle就變成了 BLOGTITLE,到了postgresql就變成了blogtitle,可讀性非常差。 * 比如實體類字段命名為blog_title,則get時變成了 getBlog_title(),也非常的不美觀。 * 但這都是為了代碼更加優雅才定的小規范,若覺得不妨礙整體美觀度,數據庫字段也可以變為駝峰,實體類也可以變為下劃線分割。 ## 實體類修飾 1. 可能會有小伙伴立馬給他加上`get set`的方法,如下 ~~~ public class Blog { /** * 主鍵 */ private Integer id; /** * 標題 */ private String blogTitle; /** * 內容 */ private String blogContent; /** * 時間 */ private LocalDateTime blogDate; /** * 是否已刪除 */ private Integer isDeleted; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getBlogTitle() { return blogTitle; } public void setBlogTitle(String blogTitle) { this.blogTitle = blogTitle; } public String getBlogContent() { return blogContent; } public void setBlogContent(String blogContent) { this.blogContent = blogContent; } public LocalDateTime getBlogDate() { return blogDate; } public void setBlogDate(LocalDateTime blogDate) { this.blogDate = blogDate; } public Integer getIsDeleted() { return isDeleted; } public void setIsDeleted(Integer isDeleted) { this.isDeleted = isDeleted; } } ~~~ 2. 針對于這種情況,有了`Lombok`后,可以大大減少代碼量了,只需一個 `@Data` 注解即可實現我們要的功能。 ~~~ @Data public class Blog { /** * 主鍵 */ private Integer id; /** * 標題 */ private String blogTitle; /** * 內容 */ private String blogContent; /** * 時間 */ private LocalDateTime blogDate; /** * 是否已刪除 */ private Integer isDeleted; } ~~~ 3. 一般實體類都需要用到緩存、序列化等等,所以要實現序列化接口 ~~~ public class Blog implements Serializable { private static final long serialVersionUID = 1L; } ~~~ 4. 加上`mybatis-plus`的注解,因為id為自增,所以不需要配置。若id為自定義,比如使用snow-flake算法,則需要在`private Integer id`上配置注解`@TableId(value = "id", type = IdType.ID_WORKER)`。最終版如下: ~~~ @Data @TableName("blade_blog") public class Blog implements Serializable { private static final long serialVersionUID = 1L; /** * 主鍵 */ private Integer id; /** * 標題 */ private String blogTitle; /** * 內容 */ private String blogContent; /** * 時間 */ private LocalDateTime blogDate; /** * 是否已刪除 */ private Integer isDeleted; } ~~~
                  <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>

                              哎呀哎呀视频在线观看