1. 增加BindQuery注解,用于Entity/DTO对象直接转换为QueryWrapper查询对象; 2. 优化Pagination对象,以便在Controller中可以自动注入属性值;
This commit is contained in:
parent
0d55f5c271
commit
e225324ec8
|
@ -31,11 +31,9 @@ public class MessageController extends BaseCrudRestController {
|
|||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public JsonResult list(HttpServletRequest request) throws Exception {
|
||||
public JsonResult list(Message message, Pagination pagination, HttpServletRequest request) throws Exception {
|
||||
//构建查询条件
|
||||
QueryWrapper<Message> queryWrapper = buildQuery(request);
|
||||
//构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
QueryWrapper<Message> queryWrapper = super.buildQueryWrapper(message);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<Message> entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
// 自动转换VO中注解绑定的关联
|
||||
|
|
|
@ -29,11 +29,9 @@ public class MessageTemplateController extends BaseCrudRestController {
|
|||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public JsonResult list(HttpServletRequest request) throws Exception {
|
||||
public JsonResult list(MessageTemplate messageTemplate, Pagination pagination, HttpServletRequest request) throws Exception {
|
||||
//构建查询条件
|
||||
QueryWrapper<MessageTemplate> queryWrapper = buildQuery(request);
|
||||
//构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
QueryWrapper<MessageTemplate> queryWrapper = super.buildQueryWrapper(messageTemplate);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<MessageTemplate> entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
//返回结果
|
||||
|
|
|
@ -57,6 +57,7 @@ compile("com.diboot:diboot-core:2.0.1")
|
|||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
~~~
|
||||
> 注: @BindDict注解需要依赖dictionary表,初始化SQL需执行/META-INF/sql/init-mysql.sql
|
||||
### 2. 定义你的Service(继承diboot的BaseService或Mybatis-plus的ISerivice)及Mapper
|
||||
|
||||
### 3. 使用注解绑定:
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package com.diboot.core.binding;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.diboot.core.binding.query.BindQuery;
|
||||
import com.diboot.core.binding.query.Comparison;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* QueryWrapper构建器 - Entity,DTO -> 注解绑定查询条件 并转换为QueryWrapper对象
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/07/27
|
||||
*/
|
||||
public class QueryBuilder {
|
||||
private static Logger log = LoggerFactory.getLogger(QueryBuilder.class);
|
||||
|
||||
/**
|
||||
* Entity或者DTO对象转换为QueryWrapper
|
||||
* @param dto
|
||||
* @param <T>
|
||||
* @param <DTO>
|
||||
* @return
|
||||
*/
|
||||
public static <T,DTO> QueryWrapper<T> toQueryWrapper(DTO dto){
|
||||
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
||||
return (QueryWrapper<T>) dtoToWrapper(wrapper, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity或者DTO对象转换为LambdaQueryWrapper
|
||||
* @param dto
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T,DTO> LambdaQueryWrapper<T> toLambdaQueryWrapper(DTO dto){
|
||||
LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
|
||||
return (LambdaQueryWrapper<T>) dtoToWrapper(wrapper, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换具体实现
|
||||
* @param wrapper
|
||||
* @param dto
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
private static <T,DTO> Wrapper<T> dtoToWrapper(AbstractWrapper wrapper, DTO dto){
|
||||
Field[] declaredFields = dto.getClass().getDeclaredFields();
|
||||
for (Field field : declaredFields) {
|
||||
BindQuery query = field.getAnnotation(BindQuery.class);
|
||||
if(query != null && query.ignore()){ //忽略字段
|
||||
continue;
|
||||
}
|
||||
//打开私有访问 获取值
|
||||
field.setAccessible(true);
|
||||
Object value = null;
|
||||
try {
|
||||
value = field.get(dto);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
log.error("通过反射获取属性值出错:" + e);
|
||||
}
|
||||
if(value == null){
|
||||
continue;
|
||||
}
|
||||
// 对比类型
|
||||
Comparison comparison = (query != null)? query.comparison() : Comparison.EQ;
|
||||
// 转换条件
|
||||
String columnName = getColumnName(field);
|
||||
switch (comparison) {
|
||||
case EQ:
|
||||
wrapper.eq(columnName, value);
|
||||
break;
|
||||
case IN:
|
||||
if(value.getClass().isArray()){
|
||||
Object[] valueArray = (Object[])value;
|
||||
if(valueArray.length == 1){
|
||||
wrapper.in(columnName, valueArray[0]);
|
||||
}
|
||||
else if(valueArray.length >= 2){
|
||||
wrapper.in(columnName, valueArray);
|
||||
}
|
||||
}
|
||||
else{
|
||||
wrapper.in(columnName, value);
|
||||
}
|
||||
break;
|
||||
case CONTAINS:
|
||||
wrapper.like(columnName, value);
|
||||
break;
|
||||
case LIKE:
|
||||
wrapper.like(columnName, value);
|
||||
break;
|
||||
case STARTSWITH:
|
||||
wrapper.likeRight(columnName, value);
|
||||
break;
|
||||
case GT:
|
||||
wrapper.gt(columnName, value);
|
||||
break;
|
||||
case BETWEEN_BEGIN:
|
||||
wrapper.ge(columnName, value);
|
||||
break;
|
||||
case GE:
|
||||
wrapper.ge(columnName, value);
|
||||
break;
|
||||
case LT:
|
||||
wrapper.lt(columnName, value);
|
||||
break;
|
||||
case BETWEEN_END:
|
||||
wrapper.le(columnName, value);
|
||||
break;
|
||||
case LE:
|
||||
wrapper.le(columnName, value);
|
||||
break;
|
||||
case BETWEEN:
|
||||
if(value.getClass().isArray()){
|
||||
Object[] valueArray = (Object[])value;
|
||||
if(valueArray.length == 1){
|
||||
wrapper.ge(columnName, valueArray[0]);
|
||||
}
|
||||
else if(valueArray.length >= 2){
|
||||
wrapper.between(columnName, valueArray[0], valueArray[1]);
|
||||
}
|
||||
}
|
||||
// 支持逗号分隔的字符串
|
||||
else if(value instanceof String && ((String) value).contains(",")){
|
||||
Object[] valueArray = ((String) value).split(",");
|
||||
wrapper.between(columnName, valueArray[0], valueArray[1]);
|
||||
}
|
||||
else{
|
||||
wrapper.ge(columnName, value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表的列名(驼峰转下划线蛇形命名)
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
private static String getColumnName(Field field){
|
||||
BindQuery annotation = field.getAnnotation(BindQuery.class);
|
||||
if (annotation != null && V.notEmpty(annotation.field())){
|
||||
return annotation.field();
|
||||
}
|
||||
return S.toSnakeCase(field.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.diboot.core.binding.query;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 绑定管理器
|
||||
* @author Xieshuang
|
||||
* @version v2.0
|
||||
* @date 2019/7/18
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface BindQuery {
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
* @return
|
||||
*/
|
||||
Comparison comparison() default Comparison.EQ;
|
||||
|
||||
/**
|
||||
* 数据库字段,默认为空,自动根据驼峰转下划线
|
||||
* @return
|
||||
*/
|
||||
String field() default "";
|
||||
|
||||
/**
|
||||
* 忽略该字段
|
||||
* @return
|
||||
*/
|
||||
boolean ignore() default false;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.diboot.core.binding.query;
|
||||
|
||||
/**
|
||||
* 比较条件枚举类
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/08/06
|
||||
*/
|
||||
public enum Comparison {
|
||||
EQ, // 相等,默认
|
||||
IN, // IN
|
||||
|
||||
STARTSWITH, //以xx起始
|
||||
|
||||
LIKE, // LIKE
|
||||
CONTAINS, //包含,等同LIKE
|
||||
|
||||
GT, // 大于
|
||||
GE, // 大于等于
|
||||
LT, // 小于
|
||||
LE, // 小于等于
|
||||
|
||||
BETWEEN, //介于-之间
|
||||
BETWEEN_BEGIN, //介于之后
|
||||
BETWEEN_END //介于之前
|
||||
}
|
|
@ -1,27 +1,19 @@
|
|||
package com.diboot.core.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.diboot.core.binding.QueryBuilder;
|
||||
import com.diboot.core.config.Cons;
|
||||
import com.diboot.core.entity.BaseEntity;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.JSON;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.JsonResult;
|
||||
import com.diboot.core.vo.Pagination;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
/***
|
||||
|
@ -30,14 +22,9 @@ import java.util.*;
|
|||
* @version 2.0
|
||||
* @date 2019/01/01
|
||||
*/
|
||||
@Controller
|
||||
public class BaseController {
|
||||
private static final Logger log = LoggerFactory.getLogger(BaseController.class);
|
||||
|
||||
/***
|
||||
* 分页参数列表
|
||||
*/
|
||||
protected static final List<String> PARAM_PAGES = Arrays.asList("_pageIndex", "_pageSize", "_totalCount", "_orderBy");
|
||||
/***
|
||||
* 字段
|
||||
*/
|
||||
|
@ -48,11 +35,6 @@ public class BaseController {
|
|||
*/
|
||||
protected static final String PARAM_ID = Cons.FieldName.id.name();
|
||||
|
||||
/**
|
||||
* 错误关键字
|
||||
*/
|
||||
protected static final String ERROR = "error";
|
||||
|
||||
/**
|
||||
* 解析所有的验证错误信息,转换为JSON
|
||||
* @param result
|
||||
|
@ -71,68 +53,23 @@ public class BaseController {
|
|||
}
|
||||
|
||||
/***
|
||||
* 构建查询wrapper
|
||||
* @param request
|
||||
* 构建查询QueryWrapper (根据BindQuery注解构建相应的查询条件)
|
||||
* @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T extends BaseEntity> QueryWrapper<T> buildQuery(HttpServletRequest request) throws Exception{
|
||||
if(!RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())){
|
||||
log.warn("调用错误: 非GET请求,无需构建查询条件!");
|
||||
return null;
|
||||
}
|
||||
//TODO 是否需要先拿到Entity定义的属性列表,只映射该列表中的属性?
|
||||
QueryWrapper query = new QueryWrapper<T>();
|
||||
Map<String, Object> requestMap = getParamsMap(request);
|
||||
if(V.notEmpty(requestMap)){
|
||||
if(requestMap.containsKey(PARAM_FIELDS) && V.notEmpty(requestMap.get(PARAM_FIELDS))){
|
||||
if(requestMap.get(PARAM_FIELDS) instanceof String){
|
||||
String fields = (String) requestMap.get(PARAM_FIELDS);
|
||||
query.select(fields);
|
||||
}
|
||||
}
|
||||
for(Map.Entry<String, Object> entry : requestMap.entrySet()){
|
||||
Object value = entry.getValue();
|
||||
if(!entry.getKey().startsWith("_") && value != null){
|
||||
if(value instanceof Set || value instanceof List || value.getClass().isArray()){
|
||||
query.in(S.toSnakeCase(entry.getKey()), value);
|
||||
}
|
||||
else if(value instanceof String){
|
||||
query.eq(S.toSnakeCase(entry.getKey()), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return query;
|
||||
public <T,DTO> QueryWrapper<T> buildQueryWrapper(DTO entityOrDto) throws Exception{
|
||||
return QueryBuilder.toQueryWrapper(entityOrDto);
|
||||
}
|
||||
|
||||
/***
|
||||
* 构建分页对象
|
||||
* @param request
|
||||
* 构建查询LambdaQueryWrapper (根据BindQuery注解构建相应的查询条件)
|
||||
* @param entityOrDto Entity对象或者DTO对象 (属性若无BindQuery注解,默认构建为为EQ相等条件)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
protected Pagination buildPagination(HttpServletRequest request) throws Exception{
|
||||
return buildPagination(request, true);
|
||||
}
|
||||
|
||||
/***
|
||||
* 构建分页对象
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
protected Pagination buildPagination(HttpServletRequest request, boolean newInstanceIfNull) throws Exception{
|
||||
Pagination page = newInstanceIfNull? new Pagination() : null;
|
||||
Map<String, Object> pageParamMap = getParamsMap(request, PARAM_PAGES);
|
||||
if(V.notEmpty(pageParamMap)){
|
||||
if(page == null){
|
||||
page = new Pagination();
|
||||
}
|
||||
BeanUtils.bindProperties(page, pageParamMap);
|
||||
}
|
||||
if(log.isTraceEnabled()){
|
||||
log.trace(JSON.stringify(page));
|
||||
}
|
||||
return page;
|
||||
public <T,DTO> LambdaQueryWrapper<T> buildLambdaQueryWrapper(DTO entityOrDto) throws Exception{
|
||||
return QueryBuilder.toLambdaQueryWrapper(entityOrDto);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -193,31 +130,6 @@ public class BaseController {
|
|||
return request.getRequestURI();
|
||||
}
|
||||
|
||||
/***
|
||||
* 返回json格式错误信息
|
||||
* @param response
|
||||
* @param jsonResult
|
||||
*/
|
||||
protected static void responseJson(HttpServletResponse response, JsonResult jsonResult){
|
||||
// 处理异步请求
|
||||
PrintWriter pw = null;
|
||||
try {
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||
pw = response.getWriter();
|
||||
pw.write(JSON.stringify(jsonResult));
|
||||
pw.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.error("处理异步请求异常", e);
|
||||
}
|
||||
finally {
|
||||
if (pw != null) {
|
||||
pw.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 将请求参数值转换为Map
|
||||
* @param request
|
||||
|
@ -245,15 +157,6 @@ public class BaseController {
|
|||
return result;
|
||||
}
|
||||
|
||||
/***
|
||||
* 将请求参数值绑定成Model
|
||||
* @param request
|
||||
*/
|
||||
public static void buildEntity(BaseEntity entity, HttpServletRequest request){
|
||||
Map<String, Object> propMap = convertParams2Map(request);
|
||||
BeanUtils.bindProperties(entity, propMap);
|
||||
}
|
||||
|
||||
/***
|
||||
* 打印所有参数信息
|
||||
* @param request
|
||||
|
|
|
@ -9,9 +9,7 @@ import com.diboot.core.vo.Status;
|
|||
import com.diboot.core.vo.Pagination;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.Serializable;
|
||||
|
@ -25,7 +23,6 @@ import java.util.Map;
|
|||
* @version 2.0
|
||||
* @date 2019/01/01
|
||||
*/
|
||||
@RestController
|
||||
public abstract class BaseCrudRestController extends BaseController {
|
||||
private static final Logger log = LoggerFactory.getLogger(BaseCrudRestController.class);
|
||||
|
||||
|
@ -39,13 +36,12 @@ public abstract class BaseCrudRestController extends BaseController {
|
|||
/***
|
||||
* 获取某资源的集合
|
||||
* <p>
|
||||
* url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR
|
||||
* url参数示例: /dictionary/list?pageSize=20&pageIndex=1&orderBy=itemValue&type=GENDAR
|
||||
* </p>
|
||||
* @param request
|
||||
* @return JsonResult
|
||||
* @throws Exception
|
||||
*/
|
||||
protected JsonResult getEntityList(HttpServletRequest request, Wrapper queryWrapper) throws Exception {
|
||||
protected JsonResult getEntityList(Wrapper queryWrapper) throws Exception {
|
||||
// 查询当前页的数据
|
||||
List entityList = getService().getEntityList(queryWrapper);
|
||||
// 返回结果
|
||||
|
@ -55,15 +51,12 @@ public abstract class BaseCrudRestController extends BaseController {
|
|||
/***
|
||||
* 获取某资源的集合
|
||||
* <p>
|
||||
* url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR
|
||||
* url参数示例: /dictionary/list?pageSize=20&pageIndex=1&orderBy=itemValue&type=GENDAR
|
||||
* </p>
|
||||
* @param request
|
||||
* @return JsonResult
|
||||
* @throws Exception
|
||||
*/
|
||||
protected JsonResult getEntityListWithPaging(HttpServletRequest request, Wrapper queryWrapper) throws Exception {
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
protected JsonResult getEntityListWithPaging(Wrapper queryWrapper, Pagination pagination) throws Exception {
|
||||
// 查询当前页的数据
|
||||
List entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
// 返回结果
|
||||
|
@ -73,15 +66,12 @@ public abstract class BaseCrudRestController extends BaseController {
|
|||
/***
|
||||
* 获取某VO资源的集合
|
||||
* <p>
|
||||
* url参数示例: /dictionary/list?_pageSize=20&_pageIndex=1&_orderBy=itemValue&type=GENDAR
|
||||
* url参数示例: /dictionary/list?pageSize=20&pageIndex=1&orderBy=itemValue&type=GENDAR
|
||||
* </p>
|
||||
* @param request
|
||||
* @return JsonResult
|
||||
* @throws Exception
|
||||
*/
|
||||
protected <T> JsonResult getVOListWithPaging(HttpServletRequest request, Wrapper queryWrapper, Class<T> clazz) throws Exception {
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
protected <T> JsonResult getVOListWithPaging(Wrapper queryWrapper, Pagination pagination, Class<T> clazz) throws Exception {
|
||||
// 查询当前页的数据
|
||||
List<T> voList = getService().getViewObjectList(queryWrapper, pagination, clazz);
|
||||
// 返回结果
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.diboot.core.mapper;
|
||||
|
||||
import com.diboot.core.entity.Dictionary;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据字典Mapper
|
||||
|
@ -8,6 +9,7 @@ import com.diboot.core.entity.Dictionary;
|
|||
* @version v2.0
|
||||
* @date 2018/12/22
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictionaryMapper extends BaseCrudMapper<Dictionary> {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "./mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.diboot.core.mapper.DictionaryMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,291 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
|
||||
Copyright 2009-2013 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed joinOn an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
|
||||
<!ELEMENT mapper (cache-ref | cache | resultMap* | parameterMap* | sql* | insert* | update* | delete* | select* )+>
|
||||
<!ATTLIST mapper
|
||||
xmlns:fo CDATA #IMPLIED
|
||||
namespace CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT cache-ref EMPTY>
|
||||
<!ATTLIST cache-ref
|
||||
namespace CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT cache (property*)>
|
||||
<!ATTLIST cache
|
||||
type CDATA #IMPLIED
|
||||
eviction CDATA #IMPLIED
|
||||
flushInterval CDATA #IMPLIED
|
||||
size CDATA #IMPLIED
|
||||
readOnly CDATA #IMPLIED
|
||||
blocking CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT parameterMap (parameter+)?>
|
||||
<!ATTLIST parameterMap
|
||||
id CDATA #REQUIRED
|
||||
type CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT parameter EMPTY>
|
||||
<!ATTLIST parameter
|
||||
property CDATA #REQUIRED
|
||||
javaType CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
mode (IN | OUT | INOUT) #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
scale CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT resultMap (constructor?,id*,result*,association*,collection*, discriminator?)>
|
||||
<!ATTLIST resultMap
|
||||
id CDATA #REQUIRED
|
||||
type CDATA #REQUIRED
|
||||
extends CDATA #IMPLIED
|
||||
autoMapping (true|false) #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT constructor (idArg*,arg*)>
|
||||
|
||||
<!ELEMENT id EMPTY>
|
||||
<!ATTLIST id
|
||||
property CDATA #IMPLIED
|
||||
javaType CDATA #IMPLIED
|
||||
column CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT result EMPTY>
|
||||
<!ATTLIST result
|
||||
property CDATA #IMPLIED
|
||||
javaType CDATA #IMPLIED
|
||||
column CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT idArg EMPTY>
|
||||
<!ATTLIST idArg
|
||||
javaType CDATA #IMPLIED
|
||||
column CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
select CDATA #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT arg EMPTY>
|
||||
<!ATTLIST arg
|
||||
javaType CDATA #IMPLIED
|
||||
column CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
select CDATA #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT collection (constructor?,id*,result*,association*,collection*, discriminator?)>
|
||||
<!ATTLIST collection
|
||||
property CDATA #REQUIRED
|
||||
column CDATA #IMPLIED
|
||||
javaType CDATA #IMPLIED
|
||||
ofType CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
select CDATA #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
notNullColumn CDATA #IMPLIED
|
||||
columnPrefix CDATA #IMPLIED
|
||||
resultSet CDATA #IMPLIED
|
||||
foreignColumn CDATA #IMPLIED
|
||||
autoMapping (true|false) #IMPLIED
|
||||
fetchType (lazy|eager) #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT association (constructor?,id*,result*,association*,collection*, discriminator?)>
|
||||
<!ATTLIST association
|
||||
property CDATA #REQUIRED
|
||||
column CDATA #IMPLIED
|
||||
javaType CDATA #IMPLIED
|
||||
jdbcType CDATA #IMPLIED
|
||||
select CDATA #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
notNullColumn CDATA #IMPLIED
|
||||
columnPrefix CDATA #IMPLIED
|
||||
resultSet CDATA #IMPLIED
|
||||
foreignColumn CDATA #IMPLIED
|
||||
autoMapping (true|false) #IMPLIED
|
||||
fetchType (lazy|eager) #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT discriminator (case+)>
|
||||
<!ATTLIST discriminator
|
||||
column CDATA #IMPLIED
|
||||
javaType CDATA #REQUIRED
|
||||
jdbcType CDATA #IMPLIED
|
||||
typeHandler CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT case (constructor?,id*,result*,association*,collection*, discriminator?)>
|
||||
<!ATTLIST case
|
||||
value CDATA #REQUIRED
|
||||
resultMap CDATA #IMPLIED
|
||||
resultType CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT property EMPTY>
|
||||
<!ATTLIST property
|
||||
name CDATA #REQUIRED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT typeAlias EMPTY>
|
||||
<!ATTLIST typeAlias
|
||||
alias CDATA #REQUIRED
|
||||
type CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT select (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST select
|
||||
id CDATA #REQUIRED
|
||||
parameterMap CDATA #IMPLIED
|
||||
parameterType CDATA #IMPLIED
|
||||
resultMap CDATA #IMPLIED
|
||||
resultType CDATA #IMPLIED
|
||||
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE) #IMPLIED
|
||||
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
|
||||
fetchSize CDATA #IMPLIED
|
||||
timeout CDATA #IMPLIED
|
||||
flushCache (true|false) #IMPLIED
|
||||
useCache (true|false) #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
lang CDATA #IMPLIED
|
||||
resultOrdered (true|false) #IMPLIED
|
||||
resultSets CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT insert (#PCDATA | selectKey | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST insert
|
||||
id CDATA #REQUIRED
|
||||
parameterMap CDATA #IMPLIED
|
||||
parameterType CDATA #IMPLIED
|
||||
timeout CDATA #IMPLIED
|
||||
flushCache (true|false) #IMPLIED
|
||||
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
|
||||
keyProperty CDATA #IMPLIED
|
||||
useGeneratedKeys (true|false) #IMPLIED
|
||||
keyColumn CDATA #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
lang CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT selectKey (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST selectKey
|
||||
resultType CDATA #IMPLIED
|
||||
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
|
||||
keyProperty CDATA #IMPLIED
|
||||
keyColumn CDATA #IMPLIED
|
||||
order (BEFORE|AFTER) #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT update (#PCDATA | selectKey | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST update
|
||||
id CDATA #REQUIRED
|
||||
parameterMap CDATA #IMPLIED
|
||||
parameterType CDATA #IMPLIED
|
||||
timeout CDATA #IMPLIED
|
||||
flushCache (true|false) #IMPLIED
|
||||
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
|
||||
keyProperty CDATA #IMPLIED
|
||||
useGeneratedKeys (true|false) #IMPLIED
|
||||
keyColumn CDATA #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
lang CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT delete (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST delete
|
||||
id CDATA #REQUIRED
|
||||
parameterMap CDATA #IMPLIED
|
||||
parameterType CDATA #IMPLIED
|
||||
timeout CDATA #IMPLIED
|
||||
flushCache (true|false) #IMPLIED
|
||||
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
lang CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!-- Dynamic -->
|
||||
|
||||
<!ELEMENT include (property+)?>
|
||||
<!ATTLIST include
|
||||
refid CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT bind EMPTY>
|
||||
<!ATTLIST bind
|
||||
name CDATA #REQUIRED
|
||||
value CDATA #REQUIRED
|
||||
>
|
||||
|
||||
<!ELEMENT sql (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST sql
|
||||
id CDATA #REQUIRED
|
||||
lang CDATA #IMPLIED
|
||||
databaseId CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT trim (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST trim
|
||||
prefix CDATA #IMPLIED
|
||||
prefixOverrides CDATA #IMPLIED
|
||||
suffix CDATA #IMPLIED
|
||||
suffixOverrides CDATA #IMPLIED
|
||||
>
|
||||
<!ELEMENT where (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ELEMENT set (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
|
||||
<!ELEMENT foreach (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST foreach
|
||||
collection CDATA #REQUIRED
|
||||
item CDATA #IMPLIED
|
||||
index CDATA #IMPLIED
|
||||
open CDATA #IMPLIED
|
||||
close CDATA #IMPLIED
|
||||
separator CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT choose (when* , otherwise?)>
|
||||
<!ELEMENT when (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST when
|
||||
test CDATA #REQUIRED
|
||||
>
|
||||
<!ELEMENT otherwise (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
|
||||
<!ELEMENT if (#PCDATA | include | trim | where | set | foreach | choose | if | bind)*>
|
||||
<!ATTLIST if
|
||||
test CDATA #REQUIRED
|
||||
>
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
page = super.page(page, queryWrapper);
|
||||
// 如果重新执行了count进行查询,则更新pagination中的总数
|
||||
if(page.isSearchCount()){
|
||||
pagination.set_totalCount(page.getTotal());
|
||||
pagination.setTotalCount(page.getTotal());
|
||||
}
|
||||
return page.getRecords();
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
IPage<Map<String, Object>> resultPage = super.pageMaps(page, queryWrapper);
|
||||
// 如果重新执行了count进行查询,则更新pagination中的总数
|
||||
if(page.isSearchCount()){
|
||||
pagination.set_totalCount(page.getTotal());
|
||||
pagination.setTotalCount(page.getTotal());
|
||||
}
|
||||
return resultPage.getRecords();
|
||||
}
|
||||
|
|
|
@ -26,15 +26,15 @@ public class Pagination implements Serializable {
|
|||
/***
|
||||
* 当前页
|
||||
*/
|
||||
private int _pageIndex = 1;
|
||||
private int pageIndex = 1;
|
||||
/***
|
||||
* 默认每页数量10
|
||||
*/
|
||||
private int _pageSize = BaseConfig.getPageSize();
|
||||
private int pageSize = BaseConfig.getPageSize();
|
||||
/***
|
||||
* count总数
|
||||
*/
|
||||
private long _totalCount = 0;
|
||||
private long totalCount = 0;
|
||||
/***
|
||||
* 排序-升序排列的字段
|
||||
*/
|
||||
|
@ -51,67 +51,68 @@ public class Pagination implements Serializable {
|
|||
* 指定当前页数
|
||||
*/
|
||||
public Pagination(int pageIndex){
|
||||
set_pageIndex(pageIndex);
|
||||
setPageIndex(pageIndex);
|
||||
}
|
||||
|
||||
public int getPageIndex() {
|
||||
return _pageIndex;
|
||||
return pageIndex;
|
||||
}
|
||||
|
||||
public void set_pageIndex(int _pageIndex) {
|
||||
this._pageIndex = _pageIndex;
|
||||
public void setPageIndex(int pageIndex) {
|
||||
this.pageIndex = pageIndex;
|
||||
}
|
||||
|
||||
public int getPageSize() {
|
||||
return _pageSize;
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void set_pageSize(int _pageSize) {
|
||||
if(_pageSize > 1000){
|
||||
log.warn("分页pageSize过大,将被调整为默认限值,请检查调用是否合理!pageSize="+_pageSize);
|
||||
_pageSize = 1000;
|
||||
public void setPageSize(int pageSize) {
|
||||
if(pageSize > 1000){
|
||||
log.warn("分页pageSize过大,将被调整为默认限值,请检查调用是否合理!pageSize="+ pageSize);
|
||||
pageSize = 1000;
|
||||
}
|
||||
this._pageSize = _pageSize;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public long getTotalCount() {
|
||||
return _totalCount;
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void set_totalCount(long _totalCount) {
|
||||
this._totalCount = _totalCount;
|
||||
public void setTotalCount(long totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
public void set_orderBy(String orderBy){
|
||||
if(V.notEmpty(orderBy)){
|
||||
// 先清空默认排序规则
|
||||
clearDefaultOrder();
|
||||
// 指定新的排序规则
|
||||
String[] orderByFields = S.split(orderBy);
|
||||
for(String field : orderByFields){
|
||||
// orderBy=name:DESC,age:ASC,birthdate
|
||||
if(field.contains(":")){
|
||||
String[] fieldAndOrder = S.split(field, ":");
|
||||
if("DESC".equalsIgnoreCase(fieldAndOrder[1])){
|
||||
if(descList == null){
|
||||
descList = new ArrayList<>();
|
||||
}
|
||||
descList.add(fieldAndOrder[0]);
|
||||
}
|
||||
else{
|
||||
if(ascList == null){
|
||||
ascList = new ArrayList<>();
|
||||
}
|
||||
ascList.add(fieldAndOrder[0]);
|
||||
public void setOrderBy(String orderBy){
|
||||
if(V.isEmpty(orderBy)){
|
||||
return;
|
||||
}
|
||||
// 先清空默认排序规则
|
||||
clearDefaultOrder();
|
||||
// 指定新的排序规则
|
||||
String[] orderByFields = S.split(orderBy);
|
||||
for(String field : orderByFields){
|
||||
// orderBy=name:DESC,age:ASC,birthdate
|
||||
if(field.contains(":")){
|
||||
String[] fieldAndOrder = S.split(field, ":");
|
||||
if("DESC".equalsIgnoreCase(fieldAndOrder[1])){
|
||||
if(descList == null){
|
||||
descList = new ArrayList<>();
|
||||
}
|
||||
descList.add(fieldAndOrder[0]);
|
||||
}
|
||||
else{
|
||||
if(ascList == null){
|
||||
ascList = new ArrayList<>();
|
||||
}
|
||||
ascList.add(field);
|
||||
ascList.add(fieldAndOrder[0]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(ascList == null){
|
||||
ascList = new ArrayList<>();
|
||||
}
|
||||
ascList.add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,10 +129,10 @@ public class Pagination implements Serializable {
|
|||
* @return
|
||||
*/
|
||||
public int getTotalPage() {
|
||||
if(_totalCount <= 0){
|
||||
if(totalCount <= 0){
|
||||
return 0;
|
||||
}
|
||||
return (int)Math.ceil((float)_totalCount/_pageSize);
|
||||
return (int)Math.ceil((float) totalCount / pageSize);
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
SET FOREIGN_KEY_CHECKS=0;
|
||||
-- 数据字典表
|
||||
-- DROP TABLE IF EXISTS `dictionary`;
|
||||
CREATE TABLE `dictionary` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`parent_id` int unsigned NOT NULL COMMENT '父ID',
|
|
@ -42,17 +42,15 @@ public class DepartmentController extends BaseCrudRestController {
|
|||
/***
|
||||
* 查询ViewObject的分页数据 (此为非继承的自定义使用案例,更简化的调用父类案例请参考UserController)
|
||||
* <p>
|
||||
* url参数示例: /list?_pageSize=20&_pageIndex=1&_orderBy=id&code=TST
|
||||
* url参数示例: /list?pageSize=20&pageIndex=1&orderBy=id&code=TST
|
||||
* </p>
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@RequiresPermissions("department:list")
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Department> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(Department department, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Department> queryWrapper = super.buildQueryWrapper(department);
|
||||
// 查询当前页的Entity主表数据
|
||||
List entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
// 自动转换VO中注解绑定的关联
|
||||
|
@ -64,14 +62,14 @@ public class DepartmentController extends BaseCrudRestController {
|
|||
/***
|
||||
* 查询ViewObject全部数据 (此为非继承的自定义使用案例,更简化的调用父类案例请参考UserController)
|
||||
* <p>
|
||||
* url参数示例: /listAll?_orderBy=id&code=TST
|
||||
* url参数示例: /listAll?orderBy=id&code=TST
|
||||
* </p>
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public JsonResult getAllVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Department> queryWrapper = buildQuery(request);
|
||||
public JsonResult getAllVOList(Department department, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Department> queryWrapper = super.buildQueryWrapper(department);
|
||||
// 查询当前页的Entity主表数据
|
||||
List entityList = getService().getEntityList(queryWrapper);
|
||||
// 自动转换VO中注解绑定的关联
|
||||
|
|
|
@ -38,13 +38,11 @@ public class DictionaryController extends BaseCrudRestController {
|
|||
* 获取列表页数据
|
||||
* */
|
||||
@GetMapping("/list")
|
||||
public JsonResult list(HttpServletRequest request) throws Exception {
|
||||
public JsonResult list(Dictionary dictionary, Pagination pagination, HttpServletRequest request) throws Exception {
|
||||
//构建查询条件
|
||||
QueryWrapper<Dictionary> queryWrapper = buildQuery(request);
|
||||
QueryWrapper<Dictionary> queryWrapper = super.buildQueryWrapper(dictionary);
|
||||
queryWrapper.lambda().eq(Dictionary::getParentId, 0)
|
||||
.orderByAsc(Dictionary::getSortId);
|
||||
//构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
//获取实体list
|
||||
List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper, pagination);
|
||||
//筛选出在列表页展示的字段
|
||||
|
|
|
@ -35,9 +35,8 @@ public class EmployeeController extends BaseCrudRestController {
|
|||
|
||||
|
||||
@RequestMapping("/list")
|
||||
public JsonResult list(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Employee> queryWrapper = super.buildQuery(request);
|
||||
Pagination pagination = super.buildPagination(request);
|
||||
public JsonResult list(Employee employee, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Employee> queryWrapper = super.buildQueryWrapper(employee);
|
||||
List<Employee> entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
List<EmployeeVO> voList = RelationsBinder.convertAndBind(entityList, EmployeeVO.class);
|
||||
return new JsonResult(Status.OK, voList).bindPagination(pagination);
|
||||
|
|
|
@ -36,10 +36,8 @@ public class OrganizationController extends BaseCrudRestController {
|
|||
private DictionaryService dictionaryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Organization> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(Organization organization, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Organization> queryWrapper = super.buildQueryWrapper(organization);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<Organization> entityList = organizationService.getEntityList(queryWrapper, pagination);
|
||||
//筛选出在列表页展示的字段
|
||||
|
|
|
@ -50,10 +50,8 @@ public class PositionController extends BaseCrudRestController {
|
|||
private DictionaryService dictionaryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Position> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(Position position, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Position> queryWrapper = super.buildQueryWrapper(position);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<Position> entityList = positionService.getEntityList(queryWrapper, pagination);
|
||||
//筛选出在列表页展示的字段
|
||||
|
|
|
@ -51,10 +51,8 @@ public class SysUserController extends BaseCrudRestController {
|
|||
private DepartmentService departmentService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<SysUser> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(SysUser sysUser, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<SysUser> queryWrapper = super.buildQueryWrapper(sysUser);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<SysUserVO> voList = sysUserService.getSysUserList(queryWrapper, pagination);
|
||||
//筛选出在列表页展示的字段
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package com.diboot.example.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.diboot.core.binding.QueryBuilder;
|
||||
import com.diboot.core.controller.BaseCrudRestController;
|
||||
import com.diboot.core.service.BaseService;
|
||||
import com.diboot.core.vo.JsonResult;
|
||||
import com.diboot.core.vo.Pagination;
|
||||
import com.diboot.core.vo.Status;
|
||||
import com.diboot.example.dto.UserDto;
|
||||
import com.diboot.example.entity.User;
|
||||
import com.diboot.example.service.UserService;
|
||||
import com.diboot.example.vo.DepartmentVO;
|
||||
import com.diboot.example.vo.UserVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -31,29 +34,42 @@ public class UserController extends BaseCrudRestController {
|
|||
/***
|
||||
* 查询ViewObject的分页数据 (此为继承父类方法的使用样例,更多自定义案例请参考DepartmentController)
|
||||
* <p>
|
||||
* url参数示例: /list?_pageSize=20&_pageIndex=1&_orderBy=username&gender=M
|
||||
* url参数示例: /list?pageSize=20&pageIndex=1&orderBy=username&gender=M
|
||||
* </p>
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<User> queryWrapper = buildQuery(request);
|
||||
return super.getVOListWithPaging(request, queryWrapper, UserVO.class);
|
||||
public JsonResult getVOList(User user, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<User> queryWrapper = super.buildQueryWrapper(user);
|
||||
return super.getVOListWithPaging(queryWrapper, pagination, UserVO.class);
|
||||
}
|
||||
|
||||
@GetMapping("/listDto")
|
||||
public JsonResult getVOListWithDTO(UserDto userDto, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<User> queryWrapper = super.buildQueryWrapper(userDto);
|
||||
// 构建分页
|
||||
//Pagination pagination = buildPagination(request);
|
||||
// 查询当前页的Entity主表数据
|
||||
List entityList = getService().getEntityList(queryWrapper, pagination);
|
||||
// 自动转换VO中注解绑定的关联
|
||||
List<UserVO> voList = super.convertToVoAndBindRelations(entityList, UserVO.class);
|
||||
// 返回结果
|
||||
return new JsonResult(Status.OK, voList).bindPagination(pagination);
|
||||
}
|
||||
|
||||
/***
|
||||
* 查询ViewObject的分页数据 (此为继承父类方法的使用样例,更多自定义案例请参考DepartmentController)
|
||||
* <p>
|
||||
* url参数示例: /listAll?_orderBy=username&gender=M
|
||||
* url参数示例: /listAll?orderBy=username&gender=M
|
||||
* </p>
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public JsonResult getAllVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<User> queryWrapper = buildQuery(request);
|
||||
return super.getVOListWithPaging(request, queryWrapper, UserVO.class);
|
||||
public JsonResult getAllVOList(User user, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<User> queryWrapper = super.buildQueryWrapper(user);
|
||||
return super.getVOListWithPaging(queryWrapper, pagination, UserVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.diboot.example.dto;
|
||||
|
||||
import com.diboot.core.binding.query.BindQuery;
|
||||
import com.diboot.core.binding.query.Comparison;
|
||||
|
||||
/**
|
||||
* <Description>
|
||||
*
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/08/06
|
||||
*/
|
||||
public class UserDto {
|
||||
|
||||
@BindQuery(comparison = Comparison.EQ)
|
||||
private Long id;
|
||||
|
||||
@BindQuery(comparison = Comparison.EQ)
|
||||
private Long departmentId;
|
||||
|
||||
@BindQuery(comparison = Comparison.LIKE)
|
||||
private String username;
|
||||
|
||||
@BindQuery(comparison = Comparison.EQ)
|
||||
private String gender;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getDepartmentId() {
|
||||
return departmentId;
|
||||
}
|
||||
|
||||
public void setDepartmentId(Long departmentId) {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
}
|
|
@ -56,17 +56,15 @@ public class PermissionController extends BaseCrudRestController {
|
|||
/***
|
||||
* 查询ViewObject的分页数据 (此为非继承的自定义使用案例,更简化的调用父类案例请参考UserController)
|
||||
* <p>
|
||||
* url参数示例: /list?_pageSize=20&_pageIndex=1&_orderBy=id&code=TST
|
||||
* url参数示例: /list?pageSize=20&pageIndex=1&orderBy=id&code=TST
|
||||
* </p>
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Permission> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(Permission permission, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Permission> queryWrapper = super.buildQueryWrapper(permission);
|
||||
// 查询当前页的Entity主表数据
|
||||
List<Permission> entityList = permissionService.getPermissionList(queryWrapper, pagination);
|
||||
|
||||
|
|
|
@ -43,10 +43,8 @@ public class RoleController extends BaseCrudRestController {
|
|||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public JsonResult getVOList(HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Role> queryWrapper = buildQuery(request);
|
||||
// 构建分页
|
||||
Pagination pagination = buildPagination(request);
|
||||
public JsonResult getVOList(Role role, Pagination pagination, HttpServletRequest request) throws Exception{
|
||||
QueryWrapper<Role> queryWrapper = super.buildQueryWrapper(role);
|
||||
// 获取结果
|
||||
List<RoleVO> voList = roleService.getRoleList(queryWrapper, pagination);
|
||||
// 返回结果
|
||||
|
|
Loading…
Reference in New Issue