MybatisCodeHelpPro生成持久层代码
链接:https://pan.baidu.com/s/18-ZMVW6WjW8oUbCUlzJI9A
提取码:8ruy
1.链接数据库

2.详细配置
生成方式

文件生成目录配置

生成注解、方法配置


File-Settings设置选项中配置:接口后缀名,设置为Dao 则生成的即可名为MytestDao ;Mapper则为MyTestMapper

3.生成后的代码
提示:这里我建的表名为mytest 生成的规则是首字母大写,如果想要达到MyTest这种效果,则在建表示已下划线分割即可 my_test ——> MyTest
1.接口—Mytest
package com.zds.tbl.dao;
import com.zds.tbl.po.Mytest;
import com.zds.tbl.po.MytestExample;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface MytestDao {
long countByExample(MytestExample example);
int deleteByExample(MytestExample example);
int deleteByPrimaryKey(Integer id);
int insert(Mytest record);
int insertOrUpdate(Mytest record);
int insertOrUpdateSelective(Mytest record);
int insertSelective(Mytest record);
List<Mytest> selectByExample(MytestExample example);
Mytest selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Mytest record, @Param("example") MytestExample example);
int updateByExample(@Param("record") Mytest record, @Param("example") MytestExample example);
int updateByPrimaryKeySelective(Mytest record);
int updateByPrimaryKey(Mytest record);
int updateBatch(List<Mytest> list);
int updateBatchSelective(List<Mytest> list);
int batchInsert(@Param("list") List<Mytest> list);
}
2.实体—Mytest
package com.zds.tbl.po;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel(value="com-zds-tbl-po-Mytest")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Mytest {
@ApiModelProperty(value="id")
private Integer id;
@ApiModelProperty(value="名称")
private String name;
}
3.xml—MytestDao.xml
DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zds.tbl.dao.MytestDao">
<resultMap id="BaseResultMap" type="com.zds.tbl.po.Mytest">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
foreach>
when>
choose>
foreach>
trim>
if>
foreach>
where>
sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
foreach>
when>
choose>
foreach>
trim>
if>
foreach>
where>
sql>
<sql id="Base_Column_List">
id, `name`
sql>
<select id="selectByExample" parameterType="com.zds.tbl.po.MytestExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
if>
<include refid="Base_Column_List" />
from mytest
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
if>
<if test="orderByClause != null">
order by ${orderByClause}
if>
select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from mytest
where id = #{id,jdbcType=INTEGER}
select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from mytest
where id = #{id,jdbcType=INTEGER}
delete>
<delete id="deleteByExample" parameterType="com.zds.tbl.po.MytestExample">
delete from mytest
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
if>
delete>
<insert id="insert" parameterType="com.zds.tbl.po.Mytest">
insert into mytest (id, `name`)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR})
insert>
<insert id="insertSelective" parameterType="com.zds.tbl.po.Mytest">
insert into mytest
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
if>
<if test="name != null">
`name`,
if>
trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
if>
trim>
insert>
<select id="countByExample" parameterType="com.zds.tbl.po.MytestExample" resultType="java.lang.Long">
select count(*) from mytest
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
if>
select>
<update id="updateByExampleSelective" parameterType="map">
update mytest
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
if>
set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
if>
update>
<update id="updateByExample" parameterType="map">
update mytest
set id = #{record.id,jdbcType=INTEGER},
`name` = #{record.name,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
if>
update>
<update id="updateByPrimaryKeySelective" parameterType="com.zds.tbl.po.Mytest">
update mytest
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
if>
set>
where id = #{id,jdbcType=INTEGER}
update>
<update id="updateByPrimaryKey" parameterType="com.zds.tbl.po.Mytest">
update mytest
set `name` = #{name,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
update>
<update id="updateBatch" parameterType="java.util.List">
update mytest
<trim prefix="set" suffixOverrides=",">
<trim prefix="`name` = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.name,jdbcType=VARCHAR}
foreach>
trim>
trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
foreach>
update>
<update id="updateBatchSelective" parameterType="java.util.List">
update mytest
<trim prefix="set" suffixOverrides=",">
<trim prefix="`name` = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.name != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.name,jdbcType=VARCHAR}
if>
foreach>
trim>
trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
foreach>
update>
<insert id="batchInsert" parameterType="map">
insert into mytest
(id, `name`)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=INTEGER}, #{item.name,jdbcType=VARCHAR})
foreach>
insert>
<insert id="insertOrUpdate" parameterType="com.zds.tbl.po.Mytest">
insert into mytest
(id, `name`)
values
(#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR})
on duplicate key update
id = #{id,jdbcType=INTEGER},
`name` = #{name,jdbcType=VARCHAR}
insert>
<insert id="insertOrUpdateSelective" parameterType="com.zds.tbl.po.Mytest">
insert into mytest
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
if>
<if test="name != null">
`name`,
if>
trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
if>
trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
if>
trim>
insert>
mapper>