• 在微服务开发的工程中使用mybaits进行查询时,出现了参数无法识别的报错信息:org.apache.ibatis.binding.BindingException: Parameter 'payDate' not found.


    【问题描述】

    2018-06-09 17:33:09.910 ERROR 7424 --- [io-2008-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'payDate' not found. Available parameters are [arg1, arg0, param1, param2]] with root cause

    org.apache.ibatis.binding.BindingException: Parameter 'payDate' not found. Available parameters are [arg1, arg0, param1, param2]
    at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:115) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2671) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:114) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:50) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258) ~[mybatis-3.4.5.jar:3.4.5]
    at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61) ~[mybatis-3.4.5.jar:3.4.5]

    【原因分析】

    在XxxxMapper.xml文件中,定义的parameterType为"java.util.Map":

    <select id="xxxxxxxx" parameterType="java.util.Map" resultType="com.xxxx.framework.model.xxxx.xxxxxxxxxxxx">

    而在XxxxServiceImpl.java文件中使用XxxxMapper.java文件中的方法进行查询时,传过去的参数不是map集合,而是两个参数;

    【解决方法】

    XxxxServiceImpl.java文件中,调用XxxxMapper类中的查询方法时,需要把相应的参数封装到一个map集合中,然后再传递过去进行查询:

     Map<String, Object> map = new HashMap<String, Object>();

       map.put("userId", userId);
       map.put("payDate", payDate);

     list = xxxxMapper.selectAllByUserIdOrMonth(map);

  • 相关阅读:
    《高校实验室低值易耗品和耗材的"一站式"管理探索 》论文笔记
    《浅谈MVC框架模式》论文笔记
    《低值易耗品的超市化和信息化管理模式探索》论文笔记
    《浅谈企业低值易耗品的管理》论文笔记
    《解说Spring MVC的处理流程及优点》论文笔记
    《基于SSM构建RESTfuI API服务》论文笔记
    《基于SSM的登录验证功能实现》论文笔记
    《基于SpringBoot+Shiro的权限管理实现》论文笔记
    《实验室设备管理系统》10
    《实验室设备管理系统》9
  • 原文地址:https://www.cnblogs.com/heyi-77/p/9165868.html
Copyright © 2020-2023  润新知