亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用idea插件進行java代碼生成的操作

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

java代碼生成

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

1、建表sql語句

2、dao.java文件

3、dao.xml文件

4、service.java文件

同時這個插件還能在new了entity之后生成所有的set方法

多次生成,不會影響自己手動添加的代碼

安裝

安裝插件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了之后在下一行:點擊tool--codeHelper--GenAllSetter

生成代碼

點擊tool--codeHelper--tox Boxes--在彈窗中輸入entity,多個使用'|'分隔,就會在當(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);
  }

}

補充知識:IDEA 新建junit單元測試

1. 新建test目錄

在src同級目錄下新建test文件夾,右鍵test文件夾設(shè)置為Test Source Root

2. 創(chuàng)建測試類

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

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

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

這樣之后就會在test下新建一個測試類:

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

測試類中包含兩個函數(shù):

@Before

public void setUp() throws Exception

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

@Test

public void findUserById() throws Exception

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

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

相關(guān)文章

  • java編寫的簡單移動方塊小游戲代碼

    java編寫的簡單移動方塊小游戲代碼

    這篇文章主要介紹了java編寫的簡單移動方塊小游戲代碼,涉及Java簡單圖形繪制與事件響應(yīng)的相關(guān)技巧,需要的朋友可以參考下
    2015-12-12
  • Spring Security實現(xiàn)動態(tài)路由權(quán)限控制方式

    Spring Security實現(xiàn)動態(tài)路由權(quán)限控制方式

    這篇文章主要介紹了Spring Security實現(xiàn)動態(tài)路由權(quán)限控制方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • java理論基礎(chǔ)Stream性能論證測試示例

    java理論基礎(chǔ)Stream性能論證測試示例

    這篇文章主要為大家介紹了java理論基礎(chǔ)Stream性能論證的測試示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-03-03
  • Java中的魔法值解決

    Java中的魔法值解決

    這篇文章主要介紹了Java中的魔法值解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • IDEA中l(wèi)og4j 無法輸出到本地 properties配置無效問題

    IDEA中l(wèi)og4j 無法輸出到本地 properties配置無效問題

    這篇文章主要介紹了IDEA中l(wèi)og4j 無法輸出到本地 properties配置無效問題,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-10-10
  • Java中Arrays.sort()方法的比較器詳解

    Java中Arrays.sort()方法的比較器詳解

    這篇文章主要介紹了Java中Arrays.sort()方法的比較器詳解,Arrays.sort(Object[] a)此方法看似沒有要求我們實現(xiàn)比較器,對于基本數(shù)據(jù)類型,String類型確實如此,因為這些類型中已經(jīng)自帶了compareTo()方法,需要的朋友可以參考下
    2023-12-12
  • Spring Boot中配置文件application.properties使用

    Spring Boot中配置文件application.properties使用

    這篇文章主要介紹了Spring Boot中配置文件application.properties使用及spring boot讀取application.properties文件的方式,需要的朋友參考下吧
    2018-01-01
  • SWT JFace 小制作 文本閱讀器

    SWT JFace 小制作 文本閱讀器

    SWT JFace 小制作 文本閱讀器
    2009-06-06
  • 利用線程實現(xiàn)動態(tài)顯示系統(tǒng)時間

    利用線程實現(xiàn)動態(tài)顯示系統(tǒng)時間

    編寫Applet小程序,通過在HTML文檔中接收參數(shù),顯示當(dāng)前的系統(tǒng)時間,需要的朋友可以參考下
    2015-10-10
  • Java排序算法之選擇排序代碼實例

    Java排序算法之選擇排序代碼實例

    這篇文章主要介紹了Java排序算法之選擇排序代碼實例,從數(shù)組的第一個元素開始,每次遍歷數(shù)組找出一個最小值放在最左側(cè),第二次從第二個元素開始,依次類推,直到起始元素為數(shù)組的倒數(shù)第二個元素時,直接和最后一個元素比較,較小值放左邊,完成排序,需要的朋友可以參考下
    2023-11-11

最新評論