mybatis plus crud Wrapper

更新,删除,增加:

UPDATE student SET stuage=?, stuname=? WHERE stuid = ?
public void TestupdatewithWrapper() { 
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml"); 
    StudentMapper studentMapper = (StudentMapper)context.getBean("studentMapper"); 
   Student student = new Student();
   student.setStuname("wang");
   student.setStuage(22);
   UpdateWrapper<Student> wrapper = new UpdateWrapper<Student>();
   wrapper.eq("stuid",1);
    int rows = studentMapper.update(student, wrapper);
    System.out.println("成功更新"+rows+"条数据"); 

    .eq()  =>  where ? = ?

查询

SELECT stuid,stuage,stuname FROM student WHERE stuage BETWEEN ? AND ? OR stuid >= ?
public void TestselectwithWrapper() { 
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml"); 
    StudentMapper studentMapper = (StudentMapper)context.getBean("studentMapper"); 
    QueryWrapper<Student> wrapper = new QueryWrapper<Student>();
    wrapper.between("stuage", 17,20).or().ge("stuid",1);
   List<Student> list = studentMapper.selectList(wrapper);
    System.out.println(list); 
    
	```
```java
.between("stuage", 17,20)  where stuage  between 17 and 20 
 .or()   or
 .ge("stuid",1) stuid >= 1
 .le("stuid",1) stuid <= 1
 .like("stuage","s")   stuage like '%s% '自动加%%
 .last("limit 3,2" )  直接在sql语句后面加 limit 3,2  
 .lambda().like(Student::getstuname,"a")  stuname like '%a%' 面向对象属性查询
.or(i->i.ge("stuage",18).le("stuid",1))
 or(stuage>=18 and stuid<=1); 
 不加or 默认为and
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值