逆向工程的Example类用法

来源:互联网 发布:骆驼 薛之谦 知乎 编辑:程序博客网 时间:2024/06/13 22:30

package com.imooc.entity;public class Student {    /**  */    private Integer id;    /**  */    private String name;    /**  */    private Integer age;    /**  */    private Integer score;    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name == null ? null : name.trim();    }    public Integer getAge() {        return age;    }    public void setAge(Integer age) {        this.age = age;    }    public Integer getScore() {        return score;    }    public void setScore(Integer score) {        this.score = score;    }}




And




Or


package com.imooc.test;import java.util.List;import org.apache.ibatis.session.SqlSession;import com.imooc.dao.StudentMapper;import com.imooc.entity.Student;import com.imooc.entity.StudentExample;import com.imooc.entity.StudentExample.Criteria;import com.imooc.untils.MyBatisUntil;public class Main {public static void main(String[] args) {//获得SqlSession对象SqlSession sqlSession=MyBatisUntil.getSqlSession();//获得StudentMapperStudentMapper dao=(StudentMapper)sqlSession.getMapper(StudentMapper.class);StudentExample example=new StudentExample();Criteria c1=example.createCriteria();//select * from student where age between 11 and 22c1.andAgeBetween(11, 22);Criteria c2=example.createCriteria();//select * from student where age < 11c2.andAgeLessThan(11);//(select * from student where age between 11 and 22) or  ( select * from student where age < 11 )//如果不写这一句select * from student where age between 11 and 22example.or(c2);//  等价于 C1  or  C2//example.or(c3);//  等价于 C1  or  C2 or  C3List<Student>  students=dao.selectByExample(example);for (Student student : students) {System.out.println(student);}}}