MyBatis-plusSQL语句包装器QueryWrapper,包装器查询倒序返回第一个

 MyBatis-plusSQL语句包装器QueryWrapper,包装器查询倒序返回第一个

CategoryEntity categoryEntity = IotBeanUtil.copy(categoryCreateDTO, CategoryEntity.class);
QueryWrapper wrapper = new QueryWrapper<>();
QueryWrapper sort = wrapper.orderByDesc("sort").last("limit 1");
CategoryEntity sortEntity = categoryDao.selectOne(sort);       

 

 简单SQL不想写SQL语句或者复杂SQL不想在Mapper里写时可以Mybatis-plus的包装类,实现自己的业务。可读性差,建议使用xml统一管理,方便别处使用。

方法名

说明

使用

allEq(Map params)

全部=(或个别isNull)

allEq(params,true)

eq

=

eq(“table_column”,”王昭君”)

ne

<>

ne(“column”,”空想4”)

gt

>

gt(“table_column”,21)

ge

>=

ge(“table_column”,22)

lt

<

lt(“table_column”,22)

le

<=

le(“table_column”,21”)

between

cloum between ? and ?

between(“table_column”,0,21)

notBetween

cloum between ? and ?

notBetween(“table_column”,0,21)

like

cloum like ‘%王%’

like(“table_column”,”王”)

notLike

not like ‘%王%’

notLike(“table_column”,”王”)

likeLeft

like ‘%王’

likeLeft(“table_column”,”昭”)

likeRight

like ‘王%’

likeRight(“table_column”,”昭”)

isNull

is null

isNull(“table_column”)

isNotNull

is not null

isNotNull(“table_column”)

in

in (1,2,3)

in(“column”,lists)

notIn

age not in (1,2,3)

notIn(“column”,lists)

inSql

age in (1,2,3)

inSql(“column”,”‘空想4’,‘空想5’,‘空想6’”)

notInSql

age not in (1,2,3,4,5,6)

notInSql(“column”,”‘空想4’,‘空想5’,‘空想6’”)

groupBy

group by id,name

groupBy(“column”,”table_column”)

orderByAsc

order by id ASC,name ASC

orderByAsc(“column”,”table_column”)

orderByDesc

order by id DESC,name DESC

orderByDesc(“table_column”)

orderBy

order by id ASC,name ASC

orderBy(true,true,”table_column”)

having

having sum(age) > 10

having(“sum(age) > 10”)

or

id = 1 or name = ‘老王’

eq(“column”,”空想4”).or(i->i.eq(“table_column”,21) eq(“column”,”空想4”).or().eq(“column”,”空想5”)

and

and (name = ‘李白’ and status <> ‘活着’)

and(i->i.eq(“table_column”,21))

nested

(name = ‘李白’ and status <> ‘活着’)

nested(i->i.eq(“table_column”,21).eq(“column”,”空想4”))

apply

id = 1

apply(“table_column” = ‘空想4’”)

last

最后添加多个以最后的为准,有sql注入风险

last(“limit 1”)

exists

拼接 EXISTS ( sql语句 )

exists(“select id from table where age = 1”)

notExists

拼接 NOT EXISTS ( sql语句 )

notExists(“select id from table where age = 1”)

你可能感兴趣的:(杂记和踩坑,MyBatis,包装器,MyBatis_plus)