QueryParser 使用

为了使MyBatis查询更加方便,UJCMS使用了查询解析器。相关代码的包名:com.ujcms.commons.query

单表查询

只检索本表字段。

# t.username_ like ?
Like_username

# t.price_ = ?
EQ_price_Int

Many-to-One 查询

# 符合规则的
# join ujcms_user user_ on t.user_id_ = user_.id_
# user_.usernmae like ?
Like_user-username

# 不符合规则的
# join ujcms_user editUser_ on t.edit_user_id_ = user_.id_
# editUser_.usernmae like ?
Like_editUser@user-username
```

## One-to-One 查询

```
# join ujcms_user_ext userExt_ on t.id_ = userExt_.id_
# userExt_.real_name_ like ?
Like_@userExt-realName
```

## One-to-Many 查询

```
# 符合规则的
# join ujcms_user_role UserRole_ on t.id_ = UserRole_.user_id_
# UserRole_.real_name_ like ?
Like_user@UserRole-realName

# 不符合规则的
# join ujcms_channel_tree ChannelTree_ on t.channel_id_ = ChannelTree_.descendant_id_
# ChannelTree_.ancestor_id_ = ?
In_channel@ChannelTree@descendant-ancestorId_Int
```

## OR 查询

```
# 一级分组
# join ujcms_question_ext questionExt_ on  t.question_ext_id_ = questionExt_.id_
# (questionExt_.title_ like ? or questionExt_.markdown_ like ?)
Like_1_questionExt-title
Like_1_questionExt-markdown

# 二级分组
# join ujcms_dict_type dictType_ on t.type_id_ = dictType_.id_
# (dictType_.alias_ = ? and dictType_.scope_ = ?) or (dictType_.alias_ = ? and dictType_.site_id_ = ?)
EQ_1-1_type@dictType-alias
EQ_1-2_type@dictType-scope
EQ_2-1_type@dictType-alias
EQ_2-2_type@dictType-siteId
```

## 多级关联查询

```
# join ujcms_user editUser_  on t.edit_user_id_ = editUser_.id_
# join ujcms_user_ext userExt_ on editUser_.user_ext_id_ = userExt_.id_
# editUser_.username_ = ?
Like_editUser@user-userExt-username
```

## 操作符

* Like:等同SQL的`like`,支持通配符,如`%`
* Contains:包含字符串。前后加通配符,如`%name%`
* StartsWith:字符串开头。后加通配符,如`name%`
* EndsWith:字符串结尾。前加通配符,如`%name`
* EQ:等于 `=` equals
* NE:不等于 `!=` not equals
* GT:大于 `>` greater than
* GE:大于等于 `>=` greater than or equal to
* LT:小于 `<` less then
* LE:小于等于 `<=` less than or equal to
* In:等同SQL的`in`
* NotIn:等同SQL的`not in`
* IsNull:等同SQL的`is null`
* IsNotNull:等同SQL的`is not null`

## 数据类型

* String
* Int:Integer的缩写
* Integer
* Short
* Long
* Double
* BigInteger
* BigDecimal
* Boolean
* DateTime
* Date

默认为String


2022-07-14 13:54
Last Updated: 2025-04-08
CONTENTS
0791-85271700
QQ咨询:1779755751
QQ交流群:626599871
微信咨询
微信扫码咨询
微信交流群
微信交流群
Powered by UJCMS © 2010-2025 All Rights Reserved
QQ咨询
电话
微信
微信扫码咨询