springboot的服务端启动之后,用postman调用,发现返回失败。在control层捕获exception,打印为:nested exception is org.apache.ibatis.binding.BindingException:
完整报错如下:
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d7ded93] was not registered for synchronization because synchronization is not active
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5d7ded93]
Exception:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'phone' not found. Available parameters are [arg0, pwd, param1, param2]
查了不少资料发现是参数没有加指定的原因:
在usermapper.java文件里,找到该接口,在入参定义的前面加上@Param("phone")指定其参数名为phone
@Repository public interface UserMapper { List<user> login(@Param("phone") String phone, @Param("pwd") String pwd); List<user> listUser(); }
在usermapper.xml文件里对于该接口,则采用#{phone,jdbcType=VARCHAR}的形式,就可以进行具名调度。
<select id="login" resultType="songbay.mes.project.domain.user"> select * from user_info where phone = #{phone,jdbcType=VARCHAR} and pwd = #{pwd,jdbcType=VARCHAR} </select>