updateprimarykey 和updateprimaryKeySelective
updateprimarykey 会对左右的字段都进行更新,updateprimaryKeySelective 只会对不为null的字段进行更新。。所以在填表的web项目需要注意这个两个方法的选择,因为有的选项会传null,如果允许传null,那么第二个方方法就没有更新效果。
int updateByPrimaryKeySelective(TbItem record);
int updateByPrimaryKey(TbItem record);
上面的是逆转工程生成的Mapper接口
对应的xml为
<update id="updateByPrimaryKeySelective" parameterType="com.taotao.pojo.TbItem">
update tb_item
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.taotao.pojo.TbItem">
update tb_item
set title = #{title,jdbcType=VARCHAR},
where id = #{id,jdbcType=BIGINT}
</update>
updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。
updateByPrimaryKey对你注入的字段全部更新
参考文章:https://blog.csdn.net/a670941001/article/details/54619432
updateprimarykey 和updateprimaryKeySelective的更多相关文章
- 9.Spring的IOC+MyBaits+log4j+Servlet
1.创建如下mysql脚本 drop table if exists book_info; create table if not exists book_info( book_id ) primar ...
随机推荐
- vue页面跳转拦截器
登录拦截逻辑 第一步:路由拦截 首先在定义路由的时候就需要多添加一个自定义字段requireAuth,用于判断该路由的访问是否需要登录.如果用户已经登录,则顺利进入路由, 否则就进入登录页面.在路由管 ...
- MySQL-By孙胜利-sifangku.com
一.数据库基本概念 数据库:信息存储的仓库,包括一系列的关系措施! 表:一个数据库中可以有若干张表(形式上你可以看出我们日常生活中建立的表) 字段:表里面的信息会分若干个栏目来存,这些栏目呢,我们在数 ...
- JAVA项目之增删改查
public class ProductDao { // 查询所有商品 // BeanListHandler查询所有商品 public List<Product> getAll() thr ...
- nginx配置访问xx.com跳转www.xx.com
二.在nginx里面配置 rewrite 规则.打开 Nginx.conf 文件找到server配置段:[以下是我的server配置段] 禁止IP地址访问 server{ listen 80 defa ...
- ETL 的一些概念
1. What is a logical data mapping and what does it mean to the ETL team? 什么是逻辑数据映射?它对ETL项目组的作用是什么? 答 ...
- InnoDB存储引擎与MyIsam存储引擎的区别
特性比较 mysql5.5之后默认的存储引擎为InnoDB,在此之前默认存储引擎是MyIsam 特点 MyIsam InnoDB 锁机制 表锁 行锁 事务 不支持 支持 外键 不支持 支持 B树索引 ...
- 详细点的Mysql主从同步
.说明 此操作文档,如果在master机器已开启bin-log及设定好server-id的情况下,可以不锁表,不停机的实现master-slave同步.这一同步可以将master上已有数据同步到sla ...
- SQLAlchemy多对多
创建多对多表 from sqlalchemy.ext.declarative import declarative_base Base=declarative_base() from sqlalche ...
- mysql类似to_char()to_date()函数mysql日期和字符相互转换方法date_f
mysql 类似to_char() to_date()函数mysql日期和字符相互转换方法 date_format(date,'%Y-%m-%d') -------------->oracle中 ...
- netstat -an unix socket 会阻塞吗
[lyd@localhost ~]$ netstat -an | grep "SOFO"unix 2 [ ACC ] SEQPACKET LISTENING 86308 @*MY- ...