Mybatis-Plus 实战完整学习笔记(五)------insert测试
一、更新操作探究(3.0.3版本)
demo
/**
* 修改用户
* @throws SQLException
*/
@Test
public void update() throws SQLException { Employee employee = new Employee(); employee.setLastName("Marry");
employee.setAge(12);
employee.setEmail("marry@163.com");
employee.setGender(1); Integer result = employeeMapper.updateById(employee); if (result!=null||result>0) {
logger.info("++++++++++++++++修改成功+++++");
}
}
1、根据Id修改字段内容
/**
* 修改用户
* @throws SQLException
*/
@Test
public void update() throws SQLException { Employee employee = new Employee(); employee.setId(1);
employee.setLastName("Marry");
employee.setAge(55);
employee.setEmail("marry@163.com");
employee.setGender(0); Integer result = employeeMapper.updateById(employee); if (result!=null||result>0) {
logger.info("++++++++++++++++修改成功+++++");
}
}
2、全表修改一个字段值
/**
* 修改用户
* @throws SQLException
*/
@Test
public void update() throws SQLException { Employee employee = new Employee(); employee.setId(1);
employee.setLastName("Marry");
employee.setAge(55);
employee.setGender(0); //全表修改一个字段的值
Integer result = employeeMapper.update(employee,new UpdateWrapper().set("email","marry@163.com")); if (result!=null||result>0) {
logger.info("++++++++++++++++修改成功+++++");
}
}
3、判断重复的就修改
/**
* 修改用户
* @throws SQLException
*/
@Test
public void update() throws SQLException { Employee employee = new Employee(); employee.setId(1);
employee.setLastName("Marry");
employee.setAge(55);
employee.setEmail("marry@163.com");
employee.setGender(0); // 判断重复的就修改
// UPDATE tbl_employee SET last_name=?, gender=?, age=? WHERE id=? AND last_name=? AND gender=? AND age=?
Integer result = employeeMapper.update(employee,new UpdateWrapper().setEntity(employee)); if (result!=null||result>0) {
logger.info("++++++++++++++++修改成功+++++");
}
}
4、自定义sql语句修改
/**
* 修改用户
* @throws SQLException
*/
@Test
public void update() throws SQLException { Employee employee = new Employee(); employee.setId(1);
employee.setLastName("Marry");
employee.setAge(55);
employee.setEmail("marry@163.com");
employee.setGender(0); //拼接一个sql的值
//UPDATE tbl_employee SET last_name=?, gender=?, age=?, email=1 where email=1 and age=12(注意where前的空格))
Integer result = employeeMapper.update(employee,new UpdateWrapper().setSql("email="+employee.getId()+" where email=1 and age=12")); if (result!=null||result>0) {
logger.info("++++++++++++++++修改成功+++++");
}
}
注意:
2.3版本有
1) Integer updateById(@Param("et") T entity); 根据ID修改
2) Integer updateAllColumnById(@Param("et") T entity) 不管是否为空,都会出现在slq语句中。默认未设置的字段设置为空
Mybatis-Plus 实战完整学习笔记(五)------insert测试的更多相关文章
- Mybatis-Plus 实战完整学习笔记(八)------delete测试
1.根据ID删除一个员工deleteById /** * 删除客户 * * @throws SQLException */ @Test public void deletedMethod() thro ...
- Mybatis-Plus 实战完整学习笔记(七)------select测试二
1.查询selectOne (3.0.3版) @Test public void selectMethod() throws SQLException { // 根据ID获取一个对象的数据 Empl ...
- Mybatis-Plus 实战完整学习笔记(六)------select测试一
查询方法(3.0.3) 1.查询一个员工的数据 @Test public void selectMethod() throws SQLException { // 根据ID获取一个对象的数据 Empl ...
- Mybatis-Plus 实战完整学习笔记(一)------简介
第一章 简介 1. 什么是MybatisPlus MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只 ...
- Mybatis-Plus 实战完整学习笔记(四)------全局参数配置
一.全局配置设置 (1)全局配置Id自动生成 <!--定义mybatisplus全局配置--> <bean id="globalConfig" class=&qu ...
- Mybatis-Plus 实战完整学习笔记(二)------环境搭建
第二章 使用实例 1.搭建测试数据库 -- 创建库 CREATE DATABASE mp; -- 使用库 USE mp; -- 创建表 CREATE TABLE tbl_employee( ...
- Mybatis-Plus 实战完整学习笔记(三)------导入MybatisPlus环境
1.dao层接口引入 package com.baidu.www.mplus.mapper; import com.baidu.www.mplus.bean.Employee; import com. ...
- 《从Lucene到Elasticsearch:全文检索实战》学习笔记五
今天我给大家讲讲tf-idf权重计算 tf-idf权重计算: tf-idf(中文词频-逆文档概率)是表示计算词项对于一个文档集或语料库中的一份文件的重要程度.词项的重要性随着它在文档中出现的次数成正比 ...
- Mybatis-Plus 实战完整学习笔记(十一)------条件构造器删除,修改,conditon
1.修改功能--其他过滤方式跟select一样 /** * 修改条件构造器 * @throws SQLException */ @Test public void selectUpdate() thr ...
随机推荐
- struct在C和C++中的使用总结
主要理解一下两点: 1.在C和C++中struct的常规使用. 2.在C++中struct和class基本一致,除了在访问控制权限方面,即: 通过struct关键字实现的类,属性,函数默认的访问权限为 ...
- jQuery 与js判断是否单选复选选中
js判断复选:这段代码昨天网上查看的资料没保存出处,抱歉 var obj=document.getElementsByName("diseaseSet"); //选择所有name= ...
- SA9 collections
[定义] 表示object的集合 generic class:可以用于多种object, 抽象类的具体实现: [ArrayList] 动态添加,只能加Non-primitive type,要初始化长 ...
- TableView中Label自适应高度
//Xcode6.3以后label自适应需要添加两个属性 _tableView.rowHeight = UITableViewAutomaticDimension; //给予预计行高 _tableVi ...
- iOS工程中创建pch文件
1.新建pch类文件 2.在工程配置中,Build Setting 下搜索"pre"寻找Apple LLVM6.1 - Language下的 Preflx Header 3.点开P ...
- idea中快捷键设置为eclipse中快捷键
打开file-settings,然后搜索key,在keymap中选择eclipse (1) (2)
- c语言练习题:求1-1/2+1/3-1/4+... -1/100的值
/******************************************* 求1-1/2+1/3-1/4+... -1/100的值 *************************** ...
- Charles基本使用
Charles使用 查找电脑IP,菜单选项helpàLocal IP Addresses 手机连接代理 手机打开WiFi,把代理模式设置为手动,设置主机名为Charles所在机器的ip,端口号为Cha ...
- MCS-51与8086指令系统比较
- start()方法和run()方法有什么区别?
通过调用线程类的start()方法来启动一个线程,使线程处于就绪状态,即可以被JVM来调度执行,在调度过程中,JVM通过调用线程类的run()方法来完成实际的业务逻辑,当run()方法结束后,此线程就 ...