環境:Springboot + Mybatis + MySQL + VUE
場景:
前端發出數據比對請求,在服務后台與數據庫交互時,接口提示錯誤信息如下所示:
{
"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"
}
控制台日志響應如下所示:

解決:
由錯誤信息可知,Mybatis在操作數據庫前未接收到請求參數,實際為Respository/Mapper中的SQL語句中引用的參數未獲取到所導致的報錯信息。查看源碼可知,如下代碼中藍色加粗部分缺失導致的,添加后,問題解決。
@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);
