Springboot-001-解决nested exception is org.apache.ibatis.binding.BindingException: Parameter 'env' not

环境:Springboot + Mybatis + MySQL + VUE前端

 

场景:java

前端发出数据比对请求,在服务后台与数据库交互时,接口提示错误信息以下所示:数据库

{
	"code": 999,
	"success": false,
	"msg": "nested exception is org.apache.ibatis.binding.BindingException: Parameter 'env' not found. Available parameters are [arg1, arg0, param1, param2]",
	"menu": "DATABASE",
	"action": "DATABASE_COMPARE",
	"operator": "ANON",
	"datetime": "2018-10-23 11:26:17.877"
}

控制台日志响应以下所示:apache

 

解决:app

由错误信息可知,Mybatis在操做数据库前未接收到请求参数,实际为Respository/Mapper中的SQL语句中引用的参数未获取到所致使的报错信息。查看源码可知,以下代码中蓝色加粗部分缺失致使的,添加后,问题解决。spa

    @Select("select * from `data` " +
            "where eng = #{eng} and env like '%${env}%' ")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "env", column = "env"),
            @Result(property = "eng", column = "eng"),
    })
    List<Database> findAllComp(@Param("eng") String eng, @Param("env") String env);
相关文章
相关标签/搜索