網站首頁 編程語言 正文
MybatisCodeHelpPro生成持久層代碼
鏈接:https://pan.baidu.com/s/18-ZMVW6WjW8oUbCUlzJI9A
提取碼:8ruy
1.鏈接數據庫
2.詳細配置
生成方式
文件生成目錄配置
生成注解、方法配置
File-Settings設置選項中配置:接口后綴名,設置為Dao 則生成的即可名為MytestDao ;Mapper則為MyTestMapper
3.生成后的代碼
提示:這里我建的表名為mytest 生成的規(guī)則是首字母大寫,如果想要達到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 {
/**
* 根據條件查詢總數
* @param example
* @return
*/
long countByExample(MytestExample example);
/**
* 根據條件進行刪除
* @param example 可以組裝條件
* @return
*/
int deleteByExample(MytestExample example);
/**
* delete by primary key 根據主鍵進行刪除
* @param id primaryKey
* @return deleteCount
*/
int deleteByPrimaryKey(Integer id);
/**
* 全量插入實體類字段值到表中
* insert record to table
* @param record the record
* @return insert count
*/
int insert(Mytest record);
/**
*主鍵或唯一索引在現有表中已經存在,則會執(zhí)行更新操作
* @param record
* @return
*/
int insertOrUpdate(Mytest record);
/**
* 主鍵或唯一索引在現有表中已經存在,則會執(zhí)行更新操作
* 選擇性的插入或者更新,如果字段值!=null則進行更新或者插入
* @param record
* @return
*/
int insertOrUpdateSelective(Mytest record);
/**
* 選擇性的插入,如果字段值!=null則插入
* insert record to table selective
* @param record the record
* @return insert count
*/
int insertSelective(Mytest record);
/**
* 根據條件進行查詢
* @param example
* @return
*/
List<Mytest> selectByExample(MytestExample example);
/**
* 根據主鍵進行查詢
* select by primary key
* @param id primary key
* @return object by primary key
*/
Mytest selectByPrimaryKey(Integer id);
/**
* 根據條件進行更新
* @param record 實體,字段值!=null的進行更新
* @param example 更新條件
* @return
*/
int updateByExampleSelective(@Param("record") Mytest record, @Param("example") MytestExample example);
/**
* 根據條件全量表更新
* @param record 實體,全量表更新即使字段值為null也會進行更新
* @param example 更新條件
* @return
*/
int updateByExample(@Param("record") Mytest record, @Param("example") MytestExample example);
/**
* 根據主鍵進行選擇性更新
* update record selective
* @param record the updated record
* @return update count
*/
int updateByPrimaryKeySelective(Mytest record);
/**
* 根據主鍵進行表全量更新
* update record
* @param record the updated record
* @return update count
*/
int updateByPrimaryKey(Mytest record);
/**
* 根據主鍵集,批量全表更新
* @param list
* @return
*/
int updateBatch(List<Mytest> list);
/**
* 根據主鍵集,選擇性批量更新
* @param list 字段值!=null的進行更新
* @return
*/
int updateBatchSelective(List<Mytest> list);
/**
* 批量插入
* @param list
* @return
*/
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 {
/**
* id
*/
@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>
原文鏈接:https://blog.csdn.net/qq_44981526/article/details/124848142
- 上一篇:Spring-IOC—基于注解配置Bean
- 下一篇:C#隊列的簡單使用_C#教程
相關推薦
- 2022-03-19 nginx?rtmp模塊編譯?arm版本的問題_nginx
- 2022-10-05 VScode中C++頭文件問題的終極解決方法詳析_C 語言
- 2022-03-27 PostgreSQL中的日期/時間函數詳解_PostgreSQL
- 2022-07-10 table列表中輸入框input與文本span切換的實現
- 2023-04-20 正則表達式:判斷是否符合USD格式
- 2022-08-12 Python學習之字典的創(chuàng)建和使用_python
- 2022-04-17 css absolute絕對定位 讓 top 和bottom 同時生效
- 2022-06-22 C語言進階教程之函數指針詳解_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支