自定义sql执行问题

提问 未结 1 62
shengke
shengke VIP3 2020-11-21
悬赏:20积分
版本:renren-security 2 开发环境:
自己定义一service方法,然后在xml中写sql语句,但是调用时会执行 ”SELECT COUNT(1) FROM “ 语句, [pre] public interface GoodsRebateService extends CrudService<GoodsRebateEntity, GoodsRebateDTO> { List<GoodsRebateEntity> getListByParam(Map<String, Object> params); } [/pre] [pre] @Service public class GoodsRebateServiceImpl extends CrudServiceImpl<GoodsRebateDao, GoodsRebateEntity, GoodsRebateDTO> implements GoodsRebateService { @Override public QueryWrapper<GoodsRebateEntity> getWrapper(Map<String, Object> params){ String id = (String)params.get("id"); String goodsId = String.valueOf(params.get("goodsId")).equals("null")?null:String.valueOf(params.get("goodsId")); QueryWrapper<GoodsRebateEntity> wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(id), "id", id); wrapper.eq(StringUtils.isNotBlank(goodsId), "goods_id", goodsId); return wrapper; } @Override public List<GoodsRebateEntity> getListByParam(Map<String, Object> params) { return baseDao.getListByParam(params); } } [/pre] [pre] @Mapper public interface GoodsRebateDao extends BaseDao<GoodsRebateEntity> { List<GoodsRebateEntity> getListByParam(Map<String, Object> params); } [/pre] [pre] <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.root.wxapp.modules.goods.dao.GoodsRebateDao"> <resultMap type="com.root.wxapp.modules.goods.entity.GoodsRebateEntity" id="goodsRebateMap"> <result property="id" column="id"/> <result property="goodsId" column="goods_id"/> <result property="buyAgentId" column="buy_agent_id"/> <result property="rebateAgentId" column="rebate_agent_id"/> <result property="money" column="money"/> <result property="point" column="point"/> <result property="sort" column="sort"/> <result property="creator" column="creator"/> <result property="createDate" column="create_date"/> <result property="updater" column="updater"/> <result property="updateDate" column="update_date"/> <result property="status" column="status"/> </resultMap> <select id="getListByParam" resultType="com.root.wxapp.modules.goods.entity.GoodsRebateEntity"> select t1.*,(select t2.name from tb_agent t2 where t2.id=t1.buy_agent_id)buyAgentName, (select t2.name from tb_agent t2 where t2.id=t1.rebate_agent_id)rebateAgentName, from tb_goods_rebate t1 <where> <if test="goodsId != null"> and t1.goods_id = #{goodsId} </if> </where> order by t1.sort asc </select> </mapper> [/pre] 调用: [pre] @GetMapping("page") @ApiOperation("分页") @ApiImplicitParams({ @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") }) @RequiresPermissions("goods:goodsrebate:page") public Result<PageData<GoodsRebateDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){ PageData<GoodsRebateDTO> page = goodsRebateService.page(params); List<GoodsRebateEntity> getList = goodsRebateService.getListByParam(params); System.out.println("----------------------"+getList.size()); System.out.println("----------------------"+getList.size()); return new Result<PageData<GoodsRebateDTO>>().ok(page); } [/pre] 我想直接执行getListByParam对应的SQL语句就行,后台调用后,报错如下图: [pre] 2020-11-21 16:51:24.935 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.dao.GoodsRebateDao.selectPage : ==> Preparing: SELECT COUNT(1) FROM tb_goods_rebate WHERE goods_id = ? 2020-11-21 16:51:24.936 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.dao.GoodsRebateDao.selectPage : ==> Parameters: 1268812966731513858(String) 2020-11-21 16:51:24.947 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.dao.GoodsRebateDao.selectPage : ==> Preparing: SELECT id,goods_id,buy_agent_id,rebate_agent_id,money,point,sort,updater,update_date,status,creator,create_date FROM tb_goods_rebate WHERE goods_id = ? LIMIT ?,? 2020-11-21 16:51:24.948 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.dao.GoodsRebateDao.selectPage : ==> Parameters: 1268812966731513858(String), 0(Long), 10(Long) 2020-11-21 16:51:24.953 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.dao.GoodsRebateDao.selectPage : <== Total: 2 2020-11-21 16:51:24.971 DEBUG 6996 --- [nio-8080-exec-2] c.r.w.m.g.d.G.getListByParam : ==> Preparing: SELECT COUNT(1) FROM ( select t1.*,(select t2.name from tb_agent t2 where t2.id=t1.buy_agent_id)buyAgentName, (select t2.name from tb_agent t2 where t2.id=t1.rebate_agent_id)rebateAgentName, from tb_goods_rebate t1 WHERE t1.goods_id = ? order by t1.sort asc ) TOTAL 2020-11-21 16:51:24.981 ERROR 6996 --- [nio-8080-exec-2] c.r.w.c.exception.RenExceptionHandler : nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql : SELECT COUNT(1) FROM ( select t1.*,(select t2.name from tb_agent t2 where t2.id=t1.buy_agent_id)buyAgentName, (select t2.name from tb_agent t2 where t2.id=t1.rebate_agent_id)rebateAgentName, from tb_goods_rebate t1 WHERE t1.goods_id = ? order by t1.sort asc ) TOTAL ### The error may exist in URL [jar:file:/home/hzp/api-bin/root-wxapp-admin.jar!/BOOT-INF/lib/root-wxapp-service-1.0.0.jar!/mapper/goods/GoodsRebateDao.xml] ### The error may involve com.root.wxapp.modules.goods.dao.GoodsRebateDao.getListByParam ### The error occurred while executing a query ### Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql : SELECT COUNT(1) FROM ( select t1.*,(select t2.name from tb_agent t2 where t2.id=t1.buy_agent_id)buyAgentName, (select t2.name from tb_agent t2 where t2.id=t1.rebate_agent_id)rebateAgentName, from tb_goods_rebate t1 WHERE t1.goods_id = ? order by t1.sort asc ) TOTAL org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql : SELECT COUNT(1) FROM ( select t1.*,(select t2.name from tb_agent t2 where t2.id=t1.buy_agent_id)buyAgentName, (select t2.name from tb_agent t2 where t2.id=t1.rebate_agent_id)rebateAgentName, [/pre]
回帖
  • 如果不需要分页,就去掉这行代码 PageData<GoodsRebateDTO> page = goodsRebateService.page(params);
    0 回复