Java神鬼莫测之Mybatis--增删改查CRUD以及批量操作(二)
1.与allColumn定义
<resultMap id="sysuserDtoMap" type="com.bsj.wms.pojo.dto.SysuserDto"><result column="UserID" property="userid"/><result column="UserCode" property="usercode"/><result column="UserName" property="username"/><result column="UserPwd" property="userpwd"/><result column="UserType" property="usertype"/><result column="DEPID" property="depid"/><result column="UserAddress" property="useraddress"/><result column="UserMobile" property="usermobile"/><result column="UserPhone" property="userphone"/><result column="UserMail" property="usermail"/><result column="EMID" property="emid"/><result column="UserLock" property="userlock"/><result column="UserLockTime" property="userlocktime"/><result column="UserMemo" property="usermemo"/><result column="UserUpdate" property="userupdate"/><result column="TpUploading" property="tpuploading"/></resultMap><!--所有字段--><sql id="allColumn">UserID,UserCode,UserName,UserPwd,UserType,DEPID,UserAddress,UserMobile,UserPhone,UserMail,EMID,UserLock,UserLockTime,UserMemo,UserUpdate,TpUploading</sql>
2.正常CRUD操作 单条数据操作(以正常User表为例)
2.1.插入
<insert id="save" useGeneratedKeys="true" keyProperty="userid">insert into SysUser(UserCode,UserName,UserPwd,UserType,DEPID,UserAddress,UserMobile,UserPhone,UserMail,EMID,UserLock,UserLockTime,UserMemo,UserUpdate,TpUploading)values (<trim suffixOverrides=",">#{usercode},#{username},#{userpwd},#{usertype},#{depid},#{useraddress},#{usermobile},#{userphone},#{usermail},#{emid},#{userlock},#{userlocktime},#{usermemo},#{userupdate},#{tpuploading},</trim>)</insert>
2.2.通过ID物理删除
<delete id="deleteById">delete from SysUserwhere UserID = #{userid}
</delete>
2.3.根据多个条件物理删除
<delete id="delete">delete from SysUser where 1=1<if test="userid != null">and UserID = #{userid}</if><if test="usercode != null and ''!= usercode">and UserCode = #{usercode}</if><if test="username != null and ''!= username">and UserName = #{username}</if><if test="userpwd != null and ''!= userpwd">and UserPwd = #{userpwd}</if><if test="usertype != null and ''!= usertype">and UserType = #{usertype}</if><if test="depid != null">and DEPID = #{depid}</if><if test="useraddress != null and ''!= useraddress">and UserAddress = #{useraddress}</if><if test="usermobile != null and ''!= usermobile">and UserMobile = #{usermobile}</if><if test="userphone != null and ''!= userphone">and UserPhone = #{userphone}</if><if test="usermail != null and ''!= usermail">and UserMail = #{usermail}</if><if test="emid != null">and EMID = #{emid}</if><if test="userlock != null">and UserLock = #{userlock}</if><if test="usermemo != null and ''!= usermemo">and UserMemo = #{usermemo}</if><if test="tpuploading != null">and TpUploading = #{tpuploading}</if></delete>
2.4.通过ID逻辑删除
<update id="logicDeleteById">update SysUser<trim prefix="set" suffixOverrides=",">is_del = 2</trim>where UserID = #{userid}
</update>
2.5.根据多个条件逻辑删除
<update id="logicDelete">update SysUser<trim prefix="set" suffixOverrides=",">is_del = 2</trim>where 1=1<if test="usercode != null and ''!= usercode">and UserCode = #{usercode}</if><if test="username != null and ''!= username">and UserName = #{username}</if><if test="userpwd != null and ''!= userpwd">and UserPwd = #{userpwd}</if><if test="usertype != null and ''!= usertype">and UserType = #{usertype}</if><if test="depid != null">and DEPID = #{depid}</if><if test="useraddress != null and ''!= useraddress">and UserAddress = #{useraddress}</if><if test="usermobile != null and ''!= usermobile">and UserMobile = #{usermobile}</if><if test="userphone != null and ''!= userphone">and UserPhone = #{userphone}</if><if test="usermail != null and ''!= usermail">and UserMail = #{usermail}</if><if test="emid != null">and EMID = #{emid}</if><if test="userlock != null">and UserLock = #{userlock}</if><if test="usermemo != null and ''!= usermemo">and UserMemo = #{usermemo}</if><if test="tpuploading != null">and TpUploading = #{tpuploading}</if></update>
2.6.编辑
<update id="update">update SysUser<trim prefix="set" suffixOverrides=","><if test="usercode != null and ''!= usercode">UserCode = #{usercode},</if><if test="username != null and ''!= username">UserName = #{username},</if><if test="userpwd != null and ''!= userpwd">UserPwd = #{userpwd},</if><if test="usertype != null and ''!= usertype">UserType = #{usertype},</if><if test="depid != null">DEPID = #{depid},</if><if test="useraddress != null and ''!= useraddress">UserAddress = #{useraddress},</if><if test="usermobile != null and ''!= usermobile">UserMobile = #{usermobile},</if><if test="userphone != null and ''!= userphone">UserPhone = #{userphone},</if><if test="usermail != null and ''!= usermail">UserMail = #{usermail},</if><if test="emid != null">EMID = #{emid},</if><if test="userlock != null">UserLock = #{userlock},</if><if test="userlocktime != null">UserLockTime = #{userlocktime},</if><if test="usermemo != null and ''!= usermemo">UserMemo = #{usermemo},</if><if test="userupdate != null">UserUpdate = #{userupdate},</if><if test="tpuploading != null">TpUploading = #{tpuploading},</if></trim>where UserID = #{userid}</update>
2.7.单个查询
<select id="findOne" resultMap="sysuserDtoMap">select top 1<include refid="allColumn"/>from SysUserwhere 1=1<if test="sysuser.userid != null">and UserID = #{sysuser.userid}</if><if test="sysuser.usercode != null and ''!= sysuser.usercode">and UserCode = #{sysuser.usercode}</if><if test="sysuser.username != null and ''!= sysuser.username">and UserName = #{sysuser.username}</if><if test="sysuser.userpwd != null and ''!= sysuser.userpwd">and UserPwd = #{sysuser.userpwd}</if><if test="sysuser.usertype != null and ''!= sysuser.usertype">and UserType = #{sysuser.usertype}</if><if test="sysuser.depid != null">and DEPID = #{sysuser.depid}</if><if test="sysuser.useraddress != null and ''!= sysuser.useraddress">and UserAddress = #{sysuser.useraddress}</if><if test="sysuser.usermobile != null and ''!= sysuser.usermobile">and UserMobile = #{sysuser.usermobile}</if><if test="sysuser.userphone != null and ''!= sysuser.userphone">and UserPhone = #{sysuser.userphone}</if><if test="sysuser.usermail != null and ''!= sysuser.usermail">and UserMail = #{sysuser.usermail}</if><if test="sysuser.emid != null">and EMID = #{sysuser.emid}</if><if test="sysuser.userlock != null">and UserLock = #{sysuser.userlock}</if><if test="sysuser.usermemo != null and ''!= sysuser.usermemo">and UserMemo = #{sysuser.usermemo}</if><if test="sysuser.tpuploading != null">and TpUploading = #{sysuser.tpuploading}</if></select>
2.8.查询全部
<select id="findAll" resultMap="sysuserDtoMap">select<include refid="allColumn"/>from SysUserwhere 1=1<if test="sysuser.userid != null">and UserID = #{sysuser.userid}</if><if test="sysuser.usercode != null and ''!= sysuser.usercode">and UserCode = #{sysuser.usercode}</if><if test="sysuser.username != null and ''!= sysuser.username">and UserName = #{sysuser.username}</if><if test="sysuser.userpwd != null and ''!= sysuser.userpwd">and UserPwd = #{sysuser.userpwd}</if><if test="sysuser.usertype != null and ''!= sysuser.usertype">and UserType = #{sysuser.usertype}</if><if test="sysuser.depid != null">and DEPID = #{sysuser.depid}</if><if test="sysuser.useraddress != null and ''!= sysuser.useraddress">and UserAddress = #{sysuser.useraddress}</if><if test="sysuser.usermobile != null and ''!= sysuser.usermobile">and UserMobile = #{sysuser.usermobile}</if><if test="sysuser.userphone != null and ''!= sysuser.userphone">and UserPhone = #{sysuser.userphone}</if><if test="sysuser.usermail != null and ''!= sysuser.usermail">and UserMail = #{sysuser.usermail}</if><if test="sysuser.emid != null">and EMID = #{sysuser.emid}</if><if test="sysuser.userlock != null">and UserLock = #{sysuser.userlock}</if><if test="sysuser.usermemo != null and ''!= sysuser.usermemo">and UserMemo = #{sysuser.usermemo}</if><if test="sysuser.tpuploading != null">and TpUploading = #{sysuser.tpuploading}</if></select>
3.批量操作
3.1.批量物理删除
<delete id="deleteListByIds">delete from SysUserwhere UserID in<foreach collection="list" item="item" index="index" open="(" separator="," close=")">#{item}</foreach></delete>
批量逻辑删除
<update id="logicDeleteListByIds">update SysUser<trim prefix="set" suffixOverrides=",">is_del = 2</trim>where UserID in<foreach collection="list" item="item" index="index" open="(" separator="," close=")">#{item}</foreach></update>
批量保存数据
<insert id="saveList" useGeneratedKeys="true" keyProperty="userid">insert into SysUser(UserCode,UserName,UserPwd,UserType,DEPID,UserAddress,UserMobile,UserPhone,UserMail,EMID,UserLock,UserLockTime,UserMemo,UserUpdate,TpUploading)values<foreach collection="list" item="item" index="index" separator=",">(<trim suffixOverrides=",">#{item.usercode},#{item.username},#{item.userpwd},#{item.usertype},#{item.depid},#{item.useraddress},#{item.usermobile},#{item.userphone},#{item.usermail},#{item.emid},#{item.userlock},#{item.userlocktime},#{item.usermemo},#{item.userupdate},#{item.tpuploading},</trim>)</foreach></insert>
Java神鬼莫测之Mybatis--增删改查CRUD以及批量操作(二)相关推荐
- java实现对HDFS增删改查(CRUD)等操作
实现对HDFS增删改查CRUD等操作 1 查找 列出某个目录下的文件名称,hdfs命令如下所示: hdfs dfs –ls/usr/app java代码片段: [plain] view plain c ...
- 一步步实现:JPA的基本增删改查CRUD(jpa基于hibernate)
1.创建一个JPA工程 首先,创建一个JPA工程(若不知道JPA创建或出现at least one user library must be selected等错误,请参考http://blog.cs ...
- MyBatisPlus03_MyBatisPlus的增删改查CRUD
MyBatisPlus03_MyBatisPlus的增删改查CRUD 查询 无条件查询 List<User> list = mapper.selectList(null); eq查询 Qu ...
- php xml 增删改查,PHP实现对xml进行简单的增删改查(CRUD)操作示例
本文实例讲述了PHP实现对xml进行简单的增删改查(CRUD)操作.分享给大家供大家参考,具体如下: 假如有下面xml文件: 55.8 56 40 339 如何使用php对它进行CRUD?其实像这种简 ...
- Java连接Mysql数据库增删改查实现
Java连接Mysql数据库增删改查实现 时间比较赶,我这里只实现查询,有时间再添加另外两个 难度 : ⭐⭐⭐(全星5颗星的情况下) 新建一个动态的网站工程, 把jar包全部复制进去,主要要那个mys ...
- Spring Data JDBC自动生成的增删改查CRUD分页、排序SQL语句非常简洁没有多余的SQL
通过在application.properties文件中设置记录SQL日志 logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG ...
- mysql如何修改学生表_MySQL 详细单表增删改查crud语句
MySQL 增删改查语句 1.创建练习表 这里练习表没有满足三范式 第一范式(又称 1NF):保证每列的原子性 数据表中的每一列(字段),必须是不可拆分的最小单元,也就是确保每一列的原子性.满足第一范 ...
- JDBC:JAVA连接Mysql实现增删改查
总有特别赶的时候,小高叫你如何速通JAVA连接数据库Mysql实现增删改查.CV战士 一.前置准备工作 1. 安装IDEA,配置JAVA环境 2. 安装Mysql,配置Mysql环境变量 3. 安装S ...
- Java 实现Gbase数据库增删改查功能
Java 实现Gbase数据库增删改查功能 具体代码如下 主要: 要记得在官网下载驱动包gbase-connector-java-8.3-bin.jar package com.advance.JDB ...
- Mybatis——增删改查(CRUD)操作
java学习--Mybatis CRUD操作 mybatis是一个可以自定义SQL.存储过程和高级映射的持久层框架.上面这个定义是在百度上抄的,简单来说,Mybatis简化了我们对数据库的一系列操作, ...
最新文章
- qpython3可视图形界面_python GUI库图形界面开发之PyQt5窗口控件QWidget详细使用方法...
- 0 RabbitMQ概念
- Error: Cannot find module '@babel/core'
- 如何将学术经历整合为求职简历?
- 脚本语言(确认补遗)
- 升级域控制器-从Windows 2012升级到2016案例之1
- 2015年4月7号的日志
- Bailian3713 外星人翻译用数字转换模块【递归+映射】
- dedeindex php不显示_dede去掉(禁止)首页index.html默认访问 最终显示index.php
- 随笔记--深浅拷贝问题
- Masked Autoencoders Are Scalable Vision Learners (2021 何凯明老师组)
- 快速排序(填坑与交换)
- Little Dima and Equation
- 单独的html怎么实现微信分享,html静态页面实现微信分享思路
- 彻底解决阿里云图床上传图片,图片不显示问题
- DOH(DNS-over-HTTPs)服务器搭建
- 学前教育专业计算机实训室,学前教育模拟实训室
- thinkcmfx漏洞太大_thinkcmf漏洞集合
- 八、鼎捷T100生产管理之委外管理篇
- cesium中实现空间查询(思路解析加源码)