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

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

Java代碼生成的方法

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

使用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代碼生成的方法”的內容,希望對大家有幫助,如有疑問,請在線咨詢,有專業老師隨時為您服務。

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

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 高清欧美在线三级视频 | 日本欧美一区二区三区高清 | 天天噜天天干 | 婷婷免费在线 | 在线日韩亚洲 | 欧美成人观看视频在线 | 一区二区三区在线 | 网站 | 成人一区二区免费中文字幕 | 国产成人一区二区三区在线播放 | 在线视频一区二区三区四区 | 一级黄色播放 | 一级一黄在线观看视频免费 | 亚洲午夜精品在线 | 羞羞视频免费网站欧美 | 国产一区免费观看 | 高清中文字幕 | 国产精品福利无圣光一区二区 | 超薄全透明无内肉色丝袜 | 成人毛片免费观看视频大全 | 精品国产成人系列 | 一级一级一片免费 | 日韩射吧 | 成人免费视频观看无遮挡 | 日日操夜夜 | 色视频网站人成免费 | videosex久久麻豆 | 国产欧美国产精品第二区 | 国产成人区| 五月婷婷在线视频观看 | 天天操天天操 | 国产成人小视频在线观看 | 国产精品免费在线播放 | 一级特黄aaa大片在 一级特黄aaa大片在线观看 | 深夜福利一区二区 | 国产日韩一区二区三区在线观看 | 最新在线黄色网址 | 国产va免费精品观看 | 天堂中文字幕在线 | 日韩在线中文 | www.黄网 | 欧美首页 |