最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用idea插件進(jìn)行java代碼生成的操作

 更新時(shí)間:2020年10月21日 15:06:55   作者:紫月java  
這篇文章主要介紹了使用idea插件進(jìn)行java代碼生成的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

java代碼生成

使用idea的插件codehelper.generator進(jìn)行代碼生成,可以根據(jù)entity,生成對(duì)應(yīng)的

1、建表sql語(yǔ)句

2、dao.java文件

3、dao.xml文件

4、service.java文件

同時(shí)這個(gè)插件還能在new了entity之后生成所有的set方法

多次生成,不會(huì)影響自己手動(dòng)添加的代碼

安裝

安裝插件codehelper.generator

案例

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserEntity {
  @Id
  private Integer id;

  private String name;

  /**
   * 1啟用,0停用
   */
  private Integer state;

  private String remark;
  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date addtime;
  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date stoptime;
}

生成set

UserEntity user=new UserEntity();

//new了之后在下一行:點(diǎn)擊tool--codeHelper--GenAllSetter

生成代碼

點(diǎn)擊tool--codeHelper--tox Boxes--在彈窗中輸入entity,多個(gè)使用'|'分隔,就會(huì)在當(dāng)前文件夾生成代碼

sql

-- auto Generated on 2020-01-14 12:49:57 
-- DROP TABLE IF EXISTS `user_entity`; 
CREATE TABLE user_entity(
  `id` INTEGER(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
  `name` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'name',
  `state` INTEGER(12) NOT NULL DEFAULT -1 COMMENT '1啟用,0停用',
  `remark` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'remark',
  `addtime` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT 'addtime',
  `stoptime` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT 'stoptime',
  PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'user_entity';

dao

package com.demo1.invoice.entity.user;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import com.demo1.invoice.entity.user.UserEntity;

public interface UserEntityDao {

  int insert(@Param("pojo") UserEntity pojo);
  int insertList(@Param("pojos") List< UserEntity> pojo);
  List<UserEntity> select(@Param("pojo") UserEntity pojo);
  int update(@Param("pojo") UserEntity pojo);
}

xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.demo1.invoice.entity.user.UserEntityDao">

<!--auto generated Code-->
  <resultMap id="AllColumnMap" type="com.demo1.invoice.entity.user.UserEntity">
    <result column="id" property="id"/>
    <result column="name" property="name"/>
    <result column="state" property="state"/>
    <result column="remark" property="remark"/>
    <result column="addtime" property="addtime"/>
    <result column="stoptime" property="stoptime"/>
  </resultMap>

<!--auto generated Code-->
  <sql id="all_column">
    id,
    name,
    state,
    remark,
    addtime,
    stoptime
  </sql>

<!--auto generated Code-->
  <insert id="insert">
    INSERT INTO user_entity
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pojo.id != null"> id, </if>
      <if test="pojo.name != null"> name, </if>
      <if test="pojo.state != null"> state, </if>
      <if test="pojo.remark != null"> remark, </if>
      <if test="pojo.addtime != null"> addtime, </if>
      <if test="pojo.stoptime != null"> stoptime, </if>
    </trim>
    VALUES
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pojo.id != null"> #{pojo.id}, </if>
      <if test="pojo.name != null"> #{pojo.name}, </if>
      <if test="pojo.state != null"> #{pojo.state}, </if>
      <if test="pojo.remark != null"> #{pojo.remark}, </if>
      <if test="pojo.addtime != null"> #{pojo.addtime}, </if>
      <if test="pojo.stoptime != null"> #{pojo.stoptime}, </if>
    </trim>
  </insert>

<!--auto generated Code-->
  <insert id="insertList">
    INSERT INTO user_entity(
    <include refid="all_column"/>
    )VALUES
    <foreach collection="pojos" item="pojo" index="index" separator=",">
      (
      #{pojo.id},
      #{pojo.name},
      #{pojo.state},
      #{pojo.remark},
      #{pojo.addtime},
      #{pojo.stoptime}
      )
    </foreach>
  </insert>

<!--auto generated Code-->
  <update id="update">
    UPDATE user_entity
    <set>
      <if test="pojo.id != null"> id = #{pojo.id}, </if>
      <if test="pojo.name != null"> name = #{pojo.name}, </if>
      <if test="pojo.state != null"> state = #{pojo.state}, </if>
      <if test="pojo.remark != null"> remark = #{pojo.remark}, </if>
      <if test="pojo.addtime != null"> addtime = #{pojo.addtime}, </if>
      <if test="pojo.stoptime != null"> stoptime = #{pojo.stoptime} </if>
    </set>
     WHERE id = #{pojo.id}
  </update>

<!--auto generated Code-->
  <select id="select" resultMap="AllColumnMap">
    SELECT <include refid="all_column"/>
    FROM user_entity
    <where>
      <if test="pojo.id != null"> AND id = #{pojo.id} </if>
      <if test="pojo.name != null"> AND name = #{pojo.name} </if>
      <if test="pojo.state != null"> AND state = #{pojo.state} </if>
      <if test="pojo.remark != null"> AND remark = #{pojo.remark} </if>
      <if test="pojo.addtime != null"> AND addtime = #{pojo.addtime} </if>
      <if test="pojo.stoptime != null"> AND stoptime = #{pojo.stoptime} </if>
    </where>
    LIMIT 1000 
  </select>

<!--auto generated Code-->
  <delete id="delete">
    DELETE FROM user_entity where id = #{id}
  </delete>
</mapper>

service

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.demo1.invoice.entity.user.UserEntity;
import com.demo1.invoice.entity.user.UserEntityDao;

@Service
public class UserEntityService {

  @Resource
  private UserEntityDao userEntityDao;

  public int insert(UserEntity pojo){
    return userEntityDao.insert(pojo);
  }

  public int insertList(List< UserEntity> pojos){
    return userEntityDao.insertList(pojos);
  }

  public List<UserEntity> select(UserEntity pojo){
    return userEntityDao.select(pojo);
  }

  public int update(UserEntity pojo){
    return userEntityDao.update(pojo);
  }

}

補(bǔ)充知識(shí):IDEA 新建junit單元測(cè)試

1. 新建test目錄

在src同級(jí)目錄下新建test文件夾,右鍵test文件夾設(shè)置為T(mén)est Source Root

2. 創(chuàng)建測(cè)試類(lèi)

選中要?jiǎng)?chuàng)建單元測(cè)試的實(shí)現(xiàn)類(lèi),并將焦點(diǎn)放在編輯器中(鼠標(biāo)在編輯器中點(diǎn)擊一下),菜單欄選擇Navigate----Test(Mac快捷鍵:Cmd+shift+t):

選擇創(chuàng)建新的測(cè)試:

選中要測(cè)試的方法,以及生成@Before:

這樣之后就會(huì)在test下新建一個(gè)測(cè)試類(lèi):

3. 測(cè)試函數(shù)介紹

測(cè)試類(lèi)中包含兩個(gè)函數(shù):

@Before

public void setUp() throws Exception

這個(gè)是測(cè)試方法執(zhí)行前執(zhí)行的函數(shù),假如在測(cè)試方法中需要使用該類(lèi)中的成員變量,那么可以在該函數(shù)中定義該成員變量。

@Test

public void findUserById() throws Exception

這個(gè)便是測(cè)試函數(shù)。點(diǎn)擊編輯器左列的小工具即可發(fā)起測(cè)試。

以上這篇使用idea插件進(jìn)行java代碼生成的操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java事務(wù)的個(gè)人理解小結(jié)

    Java事務(wù)的個(gè)人理解小結(jié)

    數(shù)據(jù)庫(kù)操作的事務(wù)習(xí)慣上就稱(chēng)為Java事務(wù)
    2013-03-03
  • Java下載文件中文文件名亂碼的解決方案(文件名包含很多%)

    Java下載文件中文文件名亂碼的解決方案(文件名包含很多%)

    Java下載文件時(shí),文件名中文亂碼問(wèn)題通常是由于編碼不正確導(dǎo)致的,使用`URLEncoder.encode(filepath, "UTF-8")`可以解決在提示下載框中正確顯示漢字文件名的問(wèn)題,但在選擇直接打開(kāi)時(shí),文件名會(huì)變成亂碼,解決這個(gè)問(wèn)題的方法
    2025-02-02
  • 從ElasticSearch中刪除數(shù)據(jù)的幾種常見(jiàn)方式

    從ElasticSearch中刪除數(shù)據(jù)的幾種常見(jiàn)方式

    這篇文章主要給大家介紹了關(guān)于從ElasticSearch中刪除數(shù)據(jù)的幾種常見(jiàn)方式,在Elasticsearch中刪除數(shù)據(jù)可以通過(guò)刪除索引或刪除文檔兩種方式實(shí)現(xiàn),需要的朋友可以參考下
    2024-10-10
  • java的io操作(將字符串寫(xiě)入到txt文件中)

    java的io操作(將字符串寫(xiě)入到txt文件中)

    這篇文章主要介紹了java的io操作示例,將字符串寫(xiě)入到txt文件中,需要的朋友可以參考下
    2014-04-04
  • 詳解Spring?Security?捕獲?filter?層面異常返回我們自定義的內(nèi)容

    詳解Spring?Security?捕獲?filter?層面異常返回我們自定義的內(nèi)容

    Spring?的異常會(huì)轉(zhuǎn)發(fā)到?BasicErrorController?中進(jìn)行異常寫(xiě)入,然后才會(huì)返回客戶(hù)端。所以,我們可以在?BasicErrorController?對(duì)?filter異常進(jìn)行捕獲并處理,下面通過(guò)本文給大家介紹Spring?Security?捕獲?filter?層面異常,返回我們自定義的內(nèi)容,感興趣的朋友一起看看吧
    2022-05-05
  • Resttemplate上傳文件500異常的原因及解決方法

    Resttemplate上傳文件500異常的原因及解決方法

    使用 Resttemplate 調(diào)用 DMS 文件服務(wù)器 Http 接口,出現(xiàn) 500 異常報(bào)錯(cuò),所以本文給大家介紹了Resttemplate上傳文件500異常的原因及解決方法,需要的朋友可以參考下
    2024-08-08
  • Java動(dòng)態(tài)獲取實(shí)現(xiàn)類(lèi)的方式詳解

    Java動(dòng)態(tài)獲取實(shí)現(xiàn)類(lèi)的方式詳解

    這篇文章主要介紹了Java動(dòng)態(tài)獲取實(shí)現(xiàn)類(lèi)的方式詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2024-01-01
  • Spring中容器創(chuàng)建的四種方式示例

    Spring中容器創(chuàng)建的四種方式示例

    這篇文章主要介紹了Spring中容器創(chuàng)建的四種方式示例,Spring容器是Spring框架的核心部分,它負(fù)責(zé)管理和組織應(yīng)用程序中的對(duì)象,它提供了一種輕量級(jí)的、非侵入式的方式來(lái)實(shí)現(xiàn)對(duì)象的創(chuàng)建、依賴(lài)注入和生命周期管理,需要的朋友可以參考下
    2023-10-10
  • Mybatis通過(guò)數(shù)據(jù)庫(kù)表自動(dòng)生成實(shí)體類(lèi)和xml映射文件

    Mybatis通過(guò)數(shù)據(jù)庫(kù)表自動(dòng)生成實(shí)體類(lèi)和xml映射文件

    這篇文章主要介紹了Mybatis通過(guò)數(shù)據(jù)庫(kù)表自動(dòng)生成實(shí)體類(lèi)和xml映射文件的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Mybatis多表關(guān)聯(lián)查詢(xún)的實(shí)現(xiàn)(DEMO)

    Mybatis多表關(guān)聯(lián)查詢(xún)的實(shí)現(xiàn)(DEMO)

    本節(jié)要實(shí)現(xiàn)的是多表關(guān)聯(lián)查詢(xún)的簡(jiǎn)單demo。場(chǎng)景是根據(jù)id查詢(xún)某商品分類(lèi)信息,并展示該分類(lèi)下的商品列表,需要的朋友可以參考下
    2017-02-02

最新評(píng)論

靖远县| 六安市| 三明市| 疏附县| 高安市| 塔河县| 凤山县| 汉沽区| 丰县| 辽阳县| 平遥县| 龙游县| 阿尔山市| 仁化县| 延吉市| 辽阳县| 云浮市| 搜索| 海阳市| 平罗县| 交口县| 益阳市| 噶尔县| 绥中县| 吉安市| 寻乌县| 绵阳市| 惠东县| 牟定县| 铜梁县| 余庆县| 南充市| 工布江达县| 汉川市| 盐池县| 瓦房店市| 应用必备| 远安县| 锦屏县| 博乐市| 莲花县|