前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >逆向工程的Example类用法

逆向工程的Example类用法

作者头像
CBeann
发布2023-12-25 16:12:53
1170
发布2023-12-25 16:12:53
举报
文章被收录于专栏:CBeann的博客CBeann的博客
代码语言:javascript
复制
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

代码语言:javascript
复制
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);
		}
		

	}

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • And
  • Or
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档