更新,删除,增加:
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