mapper代理接口中的方法:
public User login(String loginid,String loginpwd) throws Exception;
mapper.xml中的代码:
<select id="login" parameterType="String" resultType="User">
SELECT * FROM `user` WHERE LoginID=‘#{loginid}‘ and LoginPwd=‘#{loginpwd}‘ AND Role=2
</select>
调用login()时出现Parameter ‘loginid‘ not found. Available parameters are [1, 0, param1, param2]的错误。
解决方案:
当只传一个参数到sql语句时,可以直接写参数名,当传多个参数时,应当这样写(多个参数已#{0}开始):
1
|
public User login(String loginid,String loginpwd) throws Exception; |
1
2
3
|
<select id= "loginByTeacher" parameterType= "String" resultType= "User" > SELECT * FROM `user` WHERE LoginID=#{ 0 } and LoginPwd=#{ 1 } AND Role= 2 </select> |
参考:http://www.2cto.com/database/201409/338155.html