增加范围查询接口
This commit is contained in:
@@ -12,6 +12,7 @@ import com.synebula.gaea.query.Page
|
||||
import com.synebula.gaea.query.Params
|
||||
import com.synebula.gaea.query.annotation.Table
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.query.Criteria
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,10 @@ open class MongoQuery(var template: MongoTemplate, var logger: ILogger? = null)
|
||||
*/
|
||||
var validViewCollection = false
|
||||
|
||||
override fun <TView, TKey> get(id: TKey, clazz: Class<TView>): TView? {
|
||||
return this.template.findOne(whereId(id), clazz, this.collection(clazz))
|
||||
}
|
||||
|
||||
override fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView> {
|
||||
val fields = this.fields(clazz)
|
||||
val query = Query()
|
||||
@@ -57,8 +62,8 @@ open class MongoQuery(var template: MongoTemplate, var logger: ILogger? = null)
|
||||
return result
|
||||
}
|
||||
|
||||
override fun <TView, TKey> get(id: TKey, clazz: Class<TView>): TView? {
|
||||
return this.template.findOne(whereId(id), clazz, this.collection(clazz))
|
||||
override fun <TView> range(field: String, params: List<Any>, clazz: Class<TView>): List<TView> {
|
||||
return this.template.find(Query.query(Criteria.where(field).`in`(params)), clazz, this.collection(clazz))
|
||||
}
|
||||
|
||||
fun <TView> fields(clazz: Class<TView>): Array<String> {
|
||||
|
||||
@@ -9,8 +9,8 @@ interface IQuery {
|
||||
/**
|
||||
* 根据Key获取对象。
|
||||
*
|
||||
* @param key 对象Key。
|
||||
* @return
|
||||
* @param id 对象Key。
|
||||
* @return 视图结果
|
||||
*/
|
||||
fun <TView, TKey> get(id: TKey, clazz: Class<TView>): TView?
|
||||
|
||||
@@ -18,7 +18,7 @@ interface IQuery {
|
||||
* 根据实体类条件查询所有符合条件记录
|
||||
*
|
||||
* @param params 查询条件。
|
||||
* @return list
|
||||
* @return 视图列表
|
||||
*/
|
||||
fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView>
|
||||
|
||||
@@ -26,7 +26,7 @@ interface IQuery {
|
||||
* 根据条件查询符合条件记录的数量
|
||||
*
|
||||
* @param params 查询条件。
|
||||
* @return int
|
||||
* @return 数量
|
||||
*/
|
||||
fun <TView> count(params: Map<String, Any>?, clazz: Class<TView>): Int
|
||||
|
||||
@@ -37,4 +37,13 @@ interface IQuery {
|
||||
* @return 分页数据
|
||||
*/
|
||||
fun <TView> paging(params: Params, clazz: Class<TView>): Page<TView>
|
||||
|
||||
/**
|
||||
* 查询条件范围内数据。
|
||||
* @param field 查询字段
|
||||
* @param params 查询条件
|
||||
*
|
||||
* @return 视图列表
|
||||
*/
|
||||
fun <TView> range(field: String, params: List<Any>, clazz: Class<TView>): List<TView>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user