jeecg中高级查询的写法总结:
前端:
数据结构:
queryParam:{
current: 1,//页数
size: 50,//每页条数
//queryType有:and,or
//and(所有条件都要求匹配)or(条件中的任意一个匹配)
queryType:'多items之间的规则',
queryItems:[
{
field: "要筛选的字段",
//rowType有:input,input-number,select,select-multiple,date等,可以不向后端传递
rowType:"字段的类型",
//rule有:
//eq(等于),like(包含),
//right_like(以..开始),left_like(以..结尾),
//in(在...中),ne(不等于),
//gt(大于),ge(大于等于),lt(小于),le(小于等于)
rule:'匹配规则',
val:'数据'
},
]
}
可以自己在js中组装该数据,也可以自己定义高级查询的组件,去组装该数据。
后端:
controller:
/**
* 分页高级查询
*
* @param page
* @param testEntity
* @param commonQuery
* @return
*/
@GetMapping("/queryPage")
@ApiOperation(value = "分页高级查询")
public Result<IPage<TestEntity>> listPageAll(Page<TestEntity> page, TestEntity testEntity, CommonQuery commonQuery) {
QueryWrapper<TestEntity> autoQueryWrapper = AutoQueryGenerator.initQueryWrapper(testEntity, commonQuery);
QueryGenerator.applyPermissionWrapper(autoQueryWrapper, testEntity.getClass(), "");
autoQueryWrapper.orderByDesc("create_time");
return Res.ok(baseMapper.pageBills(page, autoQueryWrapper););
}
前端传的参数中,current和size会被page接收,queryType和queryItems会被commonQuery接收。
mapper:
/**
* 分页高级查询
* @param page
* @param ew
* @return
*/
Page<TestEntity> pageBills(Page<TestEntity> page, @Param("ew") QueryWrapper<TestEntity> ew);
@Param(“参数名”),表示给参数命名
xml:
<select id="pageBills" resultType="org.jeecg.modules.leasing.lease.dao.entity.TestEntity">
select dto.* from(
SELECT
a.*,
b.customers_name AS customersName,
c.suppliers_name AS ownerName
FROM
lease_bills a
LEFT JOIN base_customers b ON a.customers_code = b.customers_code
LEFT JOIN base_suppliers c ON a.owner_code = c.suppliers_code
) dto
${ew.customSqlSegment}
</select>
从xml中可以看到,”${ew.customSqlSegment}“ 我们是将数据先查出来整理成一个新的表,然后又进行的高级查询。这样有利于查询的字段扩展。