逆向工程的Example类用法

简介: 逆向工程的Example类用法

20170914215212025.png


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


11.png


Or


22.png


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();
    //获得StudentMapper
    StudentMapper dao=(StudentMapper)sqlSession.getMapper(StudentMapper.class);
    StudentExample example=new StudentExample();
    Criteria c1=example.createCriteria();
    //select * from student where age between 11 and 22
    c1.andAgeBetween(11, 22);
    Criteria c2=example.createCriteria();
    //select * from student where age < 11
    c2.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 22
    example.or(c2);//  等价于 C1  or  C2
    //example.or(c3);//  等价于 C1  or  C2 or  C3
    List<Student>  students=dao.selectByExample(example);
    for (Student student : students) {
      System.out.println(student);
    }
  }
}
目录
相关文章
|
3月前
|
安全 Java API
ServletRequest类及其使用方法介绍
ServletRequest类及其使用方法介绍
|
4月前
|
Java
|
10月前
|
Java
[正式学习java①]——java项目结构,定义类和创建对象,一个标准javabean的书写
[正式学习java①]——java项目结构,定义类和创建对象,一个标准javabean的书写
|
测试技术 数据库 Python
python接口自动化(二十二)--unittest执行顺序隐藏的坑(详解)
大多数的初学者在使用 unittest 框架时候,不清楚用例的执行顺序到底是怎样的。对测试类里面的类和方法分不清楚,不知道什么时候执行,什么时候不执行。虽然或许通过代码实现了,也是稀里糊涂的一知半解,这样还好,好歹自己鼓 捣出了,但是时间和效率并不是很高,下次遇到还是老样子。那么本篇通过最简单案例来给给为小伙伴详细讲解、演示一下 unittest 执行顺序。
248 0
python接口自动化(二十二)--unittest执行顺序隐藏的坑(详解)
|
NoSQL Java 程序员
想自己写框架?不会写Java注解可不行
想自己写框架?不会写Java注解可不行
想自己写框架?不会写Java注解可不行
|
Java 编译器 数据库
Java注解—高级用法与深入解读(1)
Java注解—高级用法与深入解读(1)
374 0
Java注解—高级用法与深入解读(1)
|
Java 编译器 API
Java注解—高级用法与深入解读(2)
Java注解—高级用法与深入解读(2)
195 0
Java注解—高级用法与深入解读(2)
|
SQL Java 数据库连接
Java注解—高级用法与深入解读(3)
Java注解—高级用法与深入解读(3)
212 0
|
Java API 容器
Java注解—高级用法与深入解读(4)
Java注解—高级用法与深入解读(4)
373 0