package com.czxy;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czxy.domain.Student;
import com.czxy.mapper.StudentMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.beans.Customizer;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TestStudentApplication.class)
public class TestMapper_01_student {
@Resource
private StudentMapper studentMapper;
//1.查询所有
@Test
public void selectAll(){
List<Student> list = studentMapper.selectList(null);
list.forEach(System.out::println);
}
//1.1分页查询
@Test
public void testPage(){
int current=1;
int size=3;
Page<Student> page = new Page<>(current, size);
studentMapper.selectPage(page, null);
System.out.println("总共记录数:"+page.getRecords());
page.getRecords().forEach(System.out::println);
}
//1.2分页条件查询
@Test
public void testPageByCondition(){
//条件
String sname="三";
int age=18;
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
//姓名中包含三的 且年龄大于等于19的
queryWrapper.like(sname!=null&&!"".equals(sname),"sname",sname);
queryWrapper.ge("age",age);
//分页
int current=1;
int size=3;
Page<Student> page = new Page<>(current, size);
//查询
studentMapper.selectPage(page, queryWrapper);
page.getRecords().forEach(System.out::println);
}
//2.添加
@Test
public void insertStudent(){
Student student = new Student();
student.setSid("s007");
student.setSname("lihua");
int insert = studentMapper.insert(student);
System.out.println(insert);
}
//3.修改
@Test
public void updateStudent(){
//要修改成这个信息
Student student = new Student("s003", "赵san三", 19, new Date(), '0', "c001");
//不能修改成重名的
UpdateWrapper<Student> queryWrapper = new UpdateWrapper<>();
queryWrapper.ne("s_id",student.getSid());
queryWrapper.eq("sname",student.getSname());
Student selectOne = studentMapper.selectOne(queryWrapper);
System.out.println(selectOne);
if(selectOne!=null){
//改成和别人重名了
System.err.println("修改失败了");
}else {
//更新
// studentMapper.update(student, queryWrapper);
studentMapper.updateById(student);
System.out.println("修改成功了");
}
}
//4.删除
@Test
public void deleteStudent(){
int i = studentMapper.deleteById("s007");
System.out.println(i);
}
//批量删除
@Test
public void deleteBatchs(){
studentMapper.deleteBatchIds(Arrays.asList("s007","s008","s009"));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java中MybatisPlus中常见的案例,通用Mapper通用Service,以及XML书写SQL语句进行增删改查常见操作
共26个文件
class:10个
java:10个
xml:3个
需积分: 0 2 下载量 132 浏览量
2022-06-14
18:01:21
上传
评论 1
收藏 25KB RAR 举报
温馨提示
基于java的高级知识, 对Mybatis+SpringBoot+Restful风格的增强其中MybatisPlus中常见的案例,通用Mapper通用Service,以及XML书写SQL语句进行增删改查常见操作
资源详情
资源评论
资源推荐
收起资源包目录
02_homework_mybatisplus.rar (26个子文件)
02_homework_mybatisplus
pom.xml 2KB
target
generated-test-sources
test-annotations
test-classes
com
czxy
TestMapper_01_student.class 6KB
TestService_02_student.class 4KB
TestXML_03_student.class 3KB
generated-sources
annotations
classes
application.yml 435B
com
czxy
domain
Classes.class 3KB
Student.class 4KB
config
MyBatisPlusConfig.class 1KB
mapper
StudentMapper.class 1KB
TestStudentApplication.class 738B
service
StudentService.class 306B
impl
StudentServiceImpl.class 728B
mapper
student
StudentMapper.xml 1KB
02_homework_mybatisplus.iml 9KB
src
test
java
com
czxy
TestService_02_student.java 3KB
TestXML_03_student.java 2KB
TestMapper_01_student.java 3KB
main
resources
application.yml 435B
mapper
student
StudentMapper.xml 1KB
java
com
czxy
domain
Classes.java 515B
Student.java 729B
config
MyBatisPlusConfig.java 791B
mapper
StudentMapper.java 956B
service
StudentService.java 189B
impl
StudentServiceImpl.java 466B
TestStudentApplication.java 331B
共 26 条
- 1
扇贝壳
- 粉丝: 6
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 4399GameSem_116_13955_207551_6.apk
- python 3.9.19源码编译包
- php-8.2.18-Win32-vs16-x64.rar
- 字节跳动青训营-抖音项目
- SQL资料手册,语句教程,高级查询语句语法
- 上位机和串口建立 Modbus 协议进行数据传输,并使用 Mysql 数据库存储,能够实现实时温湿度显示和动态变化曲线,历史数据
- Attachment 1_chazhi.xlsx
- 安卓项目,实现虚拟摇杆通过wifi串口发送nema-0183协议实现小吊舱方向控制
- 基于modbus协议的大屏数据监控,使用modbus slave模拟数据,串口服务器获取温湿度
- 下载资源.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0