没有合适的资源?快使用搜索试试~ 我知道了~
2. mybatis mapper逆向生成代码结构以及作用1
需积分: 0 0 下载量 31 浏览量
2022-08-08
19:22:01
上传
评论
收藏 88KB DOCX 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/86357103/0001-ac746475a9fdc19e16f6f5e80d4de1a6_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
28页
2. mybatis mapper逆向生成代码结构以及作用1
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86357103/bg1.jpg)
1、了解逆向生成代码结构以及作用
1、TbUser.java 为数据库表 tb_user 对应的映射 java 实体类
public class TbUser {
private Long id;
private String username;
private String password;
private String phone;
private String email;
private Date created;
private Date updated;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
![](https://csdnimg.cn/release/download_crawler_static/86357103/bg2.jpg)
2、TbUserMapper.java
TbUserMapper.java
为数据持久层接口类,
类似于 hibernate 中的接口类。里面有自己的方法,可以直
接用来使用
public interface TbUserMapper {
int countByExample(TbUserExample example);
int deleteByExample(TbUserExample example);
int deleteByPrimaryKey(Long id);
int insert(TbUser record);
int insertSelective(TbUser record);
List<TbUser> selectByExample(TbUserExample example);
TbUser selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") TbUser record, @Param("example")
TbUserExample example);
int updateByExample(@Param("record") TbUser record, @Param("example") TbUserExample
example);
int updateByPrimaryKeySelective(TbUser record);
int updateByPrimaryKey(TbUser record);
}
![](https://csdnimg.cn/release/download_crawler_static/86357103/bg3.jpg)
3、TbUserMapper.xml
TbUserMapper.xml
,是实现接口中方
法的 sql 语句,与 Mapper 接口一一对应
<?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.taotao.mapper.TbUserMapper" >
<resultMap id="BaseResultMap" type="com.taotao.pojo.TbUser" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="username" property="username" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
<result column="created" property="created" jdbcType="TIMESTAMP" />
<result column="updated" property="updated" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
![](https://csdnimg.cn/release/download_crawler_static/86357103/bg4.jpg)
</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="(" suffix=")" prefixOverrides="and" >
<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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
id, username, password, phone, email, created, updated
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.taotao.pojo.TbUserExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from tb_user
<if test="_parameter != null" >
![](https://csdnimg.cn/release/download_crawler_static/86357103/bg5.jpg)
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from tb_user
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from tb_user
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.taotao.pojo.TbUserExample" >
delete from tb_user
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.taotao.pojo.TbUser" >
insert into tb_user (id, username, password,
phone, email, created,
updated)
values (#{id,jdbcType=BIGINT}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{created,jdbcType=TIMESTAMP},
#{updated,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.taotao.pojo.TbUser" >
insert into tb_user
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="username != null" >
username,
</if>
<if test="password != null" >
password,
</if>
<if test="phone != null" >
phone,
剩余27页未读,继续阅读
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![avatar](https://profile-avatar.csdnimg.cn/85f07023247944ce9fb28a24d5fae311_weixin_35789885.jpg!1)
嘻嘻哒的小兔子
- 粉丝: 27
- 资源: 321
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 数据库管理工具:dbeaver-ce-23.3.0-stable.x86-64.rpm
- 数据库管理工具:dbeaver-ce-23.3.0-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.3.0-macos-aarch64.dmg
- 数据库管理工具:dbeaver-ce-23.2.5-stable.x86-64.rpm
- 数据库管理工具:dbeaver-ce-23.2.5-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.5-macos-aarch64.dmg
- Kettle上连接HDFS,同步虚拟机上MySQL数据到HDFS
- 数据库管理工具:dbeaver-ce-23.2.4-x86-64-setup.exe
- 数据库管理工具:dbeaver-ce-23.2.4-stable.x86-64.rpm
- 含小数的十进制转N进制源代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0