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);
相關文章
相關標籤/搜索