黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Java代碼生成的方法

Java代碼生成的方法

更新時間:2021-04-26 10:54:48 來源:動力節點 瀏覽1036次

使用idea的插件codehelper.generator進行代碼生成,可以根據entity,生成對應的

1.建表sql語句

2.dao.java文件

3.dao.xml文件

4.service.java文件

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

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

1.安裝

安裝插件codehelper.generator

2.案例

@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;
}

3.生成set

UserEntity user=new UserEntity();
//new了之后在下一行:點擊tool--codeHelper--GenAllSetter

4.生成代碼

點擊tool--codeHelper--tox Boxes--在彈窗中輸入entity,多個使用'|'分隔,就會在當前文件夾生成代碼

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.ucare.invoice.entity.user;

import org.apache.ibatis.annotations.Param;
import java.util.List;
import com.ucare.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.ucare.invoice.entity.user.UserEntityDao">

<!--auto generated Code-->
    <resultMap id="AllColumnMap" type="com.ucare.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

package com.ucare.invoice.entity.user;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.ucare.invoice.entity.user.UserEntity;
import com.ucare.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);
    }

}

以上就是動力節點小編介紹的“Java代碼生成的方法”的內容,希望對大家有幫助,如有疑問,請在線咨詢,有專業老師隨時為您服務。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: a4yy私人影院免费毛片 | 国产成人激情视频 | 久艹伊人 | 波多野结衣国产一区二区三区 | 黄短视频在线观看免费版 | 天天碰天天摸 | 欧美精品第1页www劲爆 | 欧美高清性xxxxxxx | 狠狠搞狠狠干 | 国产一区二区三区不卡免费观看 | 在线观看视频亚洲 | 黄色大片在线看 | 午夜性色吃奶添下面69影院 | 中国大陆毛片 | 欧美三级中文字幕hd | 国产一级特黄aa大片在线 | 亚洲福利天堂网福利在线观看 | 六月丁香激情综合成人 | 成人免费一级在线播放 | 免费看黄网站在线看 | 日本欧美韩国专区 | 三黄日本三级在线观看 | 午夜伦理片免费观看在线 | 视频精品一区 | 国产vr一区二区在线观看 | 香蕉视频在线观看网站 | 欧美人与牲动交a欧美精品 欧美人与日本人xx在线视频 | 最近最新中文字幕免费大全3 | 一级国产在线观看高清 | 日韩天堂在线观看 | 视频一区 中文字幕 | 一本久道久久综合多人 | 亚洲精品一卡2卡3卡三卡四卡 | 国产羞羞的视频在线观看免费 | www一级毛片| 永久免费的啪啪免费的网址 | 小明永久视频免费播放 | 天堂网www在线资源中文 | 成人一级黄色毛片 | 狠狠色噜噜综合社区 | 亚洲性hd |