You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.6 KiB
64 lines
2.6 KiB
package com.spring.modules.base.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.github.pagehelper.PageRowBounds;
|
|
import com.spring.common.utils.PageUtils;
|
|
import com.spring.common.utils.R;
|
|
import com.spring.modules.sys.entity.SysUserEntity;
|
|
import org.apache.ibatis.session.SqlSession;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 通用查询控制器,Controller直接调用mybatis的selectList方法,省去service层等
|
|
*/
|
|
@Controller
|
|
public class CommonController {
|
|
@Autowired
|
|
SqlSession sqlSession;
|
|
|
|
/**
|
|
* 通用查询分页,暂时有bug,如果当前页不在第一页时,加参数查询会有问题
|
|
*/
|
|
@RequestMapping(value = "/select/{namespace}/{statement}/paging")
|
|
@ResponseBody
|
|
public R paging(@PathVariable("namespace") String namespace,
|
|
@PathVariable("statement") String statement,
|
|
@RequestBody Map<String, Object> paramMap) {
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
|
|
paramMap.put("site", currentUser.getSite());
|
|
int page = 1;
|
|
if (paramMap.containsKey("page")) {
|
|
page = Integer.parseInt(paramMap.get("page").toString());
|
|
}
|
|
int size = 20;
|
|
if (paramMap.containsKey("limit")) {
|
|
size = Integer.parseInt(paramMap.get("limit").toString());
|
|
}
|
|
PageRowBounds rowBounds = new PageRowBounds((page - 1) * size, size);
|
|
List rows = sqlSession.selectList(namespace + "." + statement, paramMap, rowBounds);
|
|
IPage<T> pageList = new Page<>(page, size,rowBounds.getTotal());
|
|
pageList.setRecords(rows);
|
|
return R.ok().put("page", new PageUtils(pageList));
|
|
}
|
|
|
|
@RequestMapping(value = "/select/{namespace}/{statement}/list")
|
|
@ResponseBody
|
|
public R getList(@PathVariable("namespace") String namespace,
|
|
@PathVariable("statement") String statement,
|
|
@RequestBody Map<String, Object> paramMap) {
|
|
List rows = sqlSession.selectList(namespace + "." + statement, paramMap);
|
|
return R.ok().put("rows", rows);
|
|
}
|
|
|
|
}
|