public class GeneralEntityWrapper<T>
extends com.baomidou.mybatisplus.mapper.EntityWrapper<T>
This object is used to solve EntityWrapper.where/and/or... Parameter Type of Date. Mybatis-plus_v_1.5
Eg:
EntityWrapper ew = new EntityWrapper(entity);
ew.andNew("col1_date > {0} and col1_date<{1}", LocalDate.of(2017,2,10), LocalDate.of(2017,2,15));
SQL:
select xx from tbl_entity where col1_date>2017-2-10 and col1_date<2017-2-15
Question:
1) Mysql: no record will be found due to condition is false forever.(actual sql: col1_date>2005 and col1_date<2000) : do subtraction
2) Other db(oracle), sql will encounter error
Solution:
1) just use: ew.andNew("col1_date > {0} and col1_date<{1}", LocalDate.of(2017,2,10), LocalDate.of(2017,2,15));
sqlSegment will be replaced to : col1_date > #{GENVAL1} and col1_date<#{GENVAL2},
And GENVAL1,GENVAL2 will be passed to mybatis via Map.
2) OR try like this: ew.andNew("col1_date > #{dateFrom} and col1_date<#{dateTo}", LocalDate.of(2017,2,10), LocalDate.of(2017,2,15));
3) BUT {0} and #{value}, mixed use currently NOT supported.
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
CLOSE_TOKEN |
static String |
OPEN_TOKEN |
| 构造器和说明 |
|---|
GeneralEntityWrapper() |
GeneralEntityWrapper(T entity) |
GeneralEntityWrapper(T entity,
String sqlSelect) |
| 限定符和类型 | 方法和说明 |
|---|---|
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
addFilter(String sqlWhere,
Object... params)
已过时。
instead use
where(String sqlWhere, Object... params),and(String sqlAnd, Object... params)... |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
addFilterIfNeed(boolean need,
String sqlWhere,
Object... params)
已过时。
instead use
where(String sqlWhere, Object... params),and(String sqlAnd, Object... params)... |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
and(String sqlAnd,
Object... params)
Code:
ew.and("col1=18").and("col2={0}", 20) SQL: AND col1=18 AND col2=20 |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
andNew(String sqlAnd,
Object... params)
Use () to separate sql segment.
|
boolean |
checkFieldValueNotNull()
Get corresponding class and check property values NOT null.
|
protected String |
formatSqlIfNeed(boolean need,
String sqlStr,
Object... params)
Format SQL for methods: EntityWrapper.where/and/or...
|
Map<String,Object> |
getParamNameValuePairs() |
String |
getSqlSegment()
Plus Injected Sql will use EntityWrapper.sqlSegment in sql script
Refer to AutoSqlInjector.sqlWhereEntityWrapper()If ew.entity is an empty object, sql structure: select col1, col2 from tbl_entity #{sqlSegment}, sqlSegment should start with "WHERE"; If ew.entity has property values, sql structure: select col1, col2 from tbl_entity where col1=#{propertyVal1} #{sqlSegment}, sqlSegment should start with "AND" |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
having(String sqlHaving,
Object... params)
Code:
eg: ew.groupBy("id,name").having("id={0}",22).and("password is not null") SQL: group by id, name having id=22 and password is not null |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
or(String sqlOr,
Object... params)
Code:
ew.or("col1=18").or("col2={0}", 20) SQL: OR col1=18 OR col2=20 |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
orNew(String sqlOr,
Object... params)
Code:
ew.or("col1=18").orNew("col2={0} and col3={0}", 20) SQL: OR col1=18 OR ( col2=20 and col3=20 ) |
com.baomidou.mybatisplus.mapper.EntityWrapper<T> |
where(String sqlWhere,
Object... params)
ew.where("col_1>{0} and col_1<{1}", Object val1, Object val2);
eg: ew.where("name='Bob'").where("id=#{value1}",123).where("age>#{value2}", 18); OR ew.where("name='Bob'").where("id={0}",123).where("age>{1}", 18); sql: where (name='Bob' and id=#{value1} and age>#{value2}) The values of "value1" and "value2" will be passed to mybatis via Map param. |
public GeneralEntityWrapper()
public GeneralEntityWrapper(T entity)
public String getSqlSegment()
AutoSqlInjector.sqlWhereEntityWrapper()getSqlSegment 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>public boolean checkFieldValueNotNull()
protected String formatSqlIfNeed(boolean need, String sqlStr, Object... params)
formatSqlIfNeed 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>need - truesqlStr - normally like: "column_name={0}"params - public com.baomidou.mybatisplus.mapper.EntityWrapper<T> where(String sqlWhere, Object... params)
where 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>sqlWhere - sql segment: "col_1>{0} AND col_1<{1}" or "col_1>#{val1} AND col_1<#{val2}"params - public com.baomidou.mybatisplus.mapper.EntityWrapper<T> and(String sqlAnd, Object... params)
and 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>public com.baomidou.mybatisplus.mapper.EntityWrapper<T> andNew(String sqlAnd, Object... params)
andNew 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>public com.baomidou.mybatisplus.mapper.EntityWrapper<T> or(String sqlOr, Object... params)
or 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>public com.baomidou.mybatisplus.mapper.EntityWrapper<T> orNew(String sqlOr, Object... params)
orNew 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>public com.baomidou.mybatisplus.mapper.EntityWrapper<T> having(String sqlHaving, Object... params)
having 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>@Deprecated public com.baomidou.mybatisplus.mapper.EntityWrapper<T> addFilter(String sqlWhere, Object... params)
where(String sqlWhere, Object... params),and(String sqlAnd, Object... params)...addFilter 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>@Deprecated public com.baomidou.mybatisplus.mapper.EntityWrapper<T> addFilterIfNeed(boolean need, String sqlWhere, Object... params)
where(String sqlWhere, Object... params),and(String sqlAnd, Object... params)...addFilterIfNeed 在类中 com.baomidou.mybatisplus.mapper.EntityWrapper<T>Copyright © 2017. All rights reserved.