java学习知识积累-Mybatis中model内置方法细解
该文件由Mybatis自动生成。
User Model:
1 2 3 4 5 6 7 |
package com.hongyin.model; import java.util.Date; public class User { .... } |
getId返回ID
1 2 3 |
public Integer getId() { return id; } |
setId设置ID
1 2 3 |
public void setId(Integer id) { this.id = id; } |
UserExample Model:
UserExample 创建一个内部类 Criteria
1 2 3 |
public UserExample() { oredCriteria = new ArrayList<Criteria>(); } |
setOrderByClause(“username asc,email desc”); 按字段排序
1 2 3 |
public void setOrderByClause(String orderByClause) { this.orderByClause = orderByClause; } |
getOrderByClause 得到成员的排序值
1 2 3 |
public String getOrderByClause() { return orderByClause; } |
setDistinct 设置是否返回唯一不同的值
1 2 3 |
public void setDistinct(boolean distinct) { this.distinct = distinct; } |
isDistinct 返回成员的是否去重复
1 2 3 |
public boolean isDistinct() { return distinct; } |
getOredCriteria 返回Criteria对象
1 2 3 |
public List<Criteria> getOredCriteria() { return oredCriteria; } |
or 添加Criteria对象
1 2 3 |
public void or(Criteria criteria) { oredCriteria.add(criteria); } |
or 添加Criteria对象,并返回
1 2 3 4 5 |
public Criteria or() { Criteria criteria = createCriteriaInternal(); oredCriteria.add(criteria); return criteria; } |
createCriteria 创建并判断
1 2 3 4 5 6 7 |
public Criteria createCriteria() { Criteria criteria = createCriteriaInternal(); if (oredCriteria.size() == 0) { oredCriteria.add(criteria); } return criteria; } |
createCriteriaInternal 创建Criteria
1 2 3 4 |
protected Criteria createCriteriaInternal() { Criteria criteria = new Criteria(); return criteria; } |
clear 清除
1 2 3 4 5 |
public void clear() { oredCriteria.clear(); orderByClause = null; distinct = false; } |
GeneratedCriteria 内嵌的内部类,其已经实现了所有字段的常用过滤条件
1 2 3 |
protected abstract static class GeneratedCriteria { ... } |
andIdIsNull 条件为 id is null
1 2 3 4 |
public Criteria andIdIsNull() { addCriterion("id is null"); return (Criteria) this; } |
andIdIsNotNull 条件为 id is not null
1 2 3 4 |
public Criteria andIdIsNotNull() { addCriterion("id is not null"); return (Criteria) this; } |
andIdEqualTo 条件为id=变量值
1 2 3 4 |
public Criteria andIdEqualTo(Integer value) { addCriterion("id =", value, "id"); return (Criteria) this; } |
andIdNotEqualTo 条件为id!=变量值
1 2 3 4 |
public Criteria andIdNotEqualTo(Integer value) { addCriterion("id <>", value, "id"); return (Criteria) this; } |
………..
还有一些常用的。这里就不作多介绍了。
- java学习知识积累-Mybatis中Mapper内置方法细解
- PHP中的OOP面向对象笔记