在使用SSM写后台管理系统登录功能出现了错误,mybatis查询数据库出现查询用户条数超过一条,
Expected one result (or null) to be returned by selectOne(), but found: 4
期望返回一个结果,但是返回了四个
所以判断应该是mapper.xml的问题,查看文件后发现
<select id="checkLogin" resultType="User" parameterType="User">
select * from bookbms.user
<where>
<if test="userName != null and userName != ''">
and userName = #{userName}
</if>
<if test="userPassword != null and userPassword != ''">
and userPassword = #{userPassword}
</if>
</where>
</select>
发现在第一个判断语句前多了一个and
将and删除后再次运行,问题解决