测试login.do,用户名不存在,传参没有成功??
来源:6-2 登录功能开发
筱爻
2017-08-14
怎么解决下呀,从dao层都没有拿到数据??
测试login.do结果:
debug调试结果:
控制台打印:
【相关代码】
UserMapper.xml:
<mapper namespace="com.mall.dao.UserMapper" > <resultMap id="BaseResultMap" type="com.mall.pojo.User" > <constructor > <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" /> <arg column="username" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="password" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="email" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="phone" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="question" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="answer" jdbcType="VARCHAR" javaType="java.lang.String" /> <arg column="role" jdbcType="INTEGER" javaType="java.lang.Integer" /> <arg column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date" /> <arg column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date" /> </constructor> </resultMap> <sql id="Base_Column_List" > id, username, password, email, phone, question, answer, role, create_time, update_time </sql> //查看用户名是否存在 <select id="checkUsername" resultType="int" parameterType="string"> SELECT COUNT(1) FROM mall_user WHERE username = #{username} </select> <select id="selectLogin" resultMap="BaseResultMap" parameterType="map"> SELECT <include refid="Base_Column_List" /> from mall_user WHERE username = #{username},password = #{password}} </select> </mapper>
UserServiceImpl.java
@Autowired private UserMapper userMapper; @Override public ServerResponse<User> login(String username, String password) { //检查用户名是否存在 int resultCode = userMapper.checkUsername(username); System.out.println("------ServiceImpl返回username=---------"+username); if(resultCode == 0 ){ ServerResponse.createByErrorMessage("用户名不存在"); } // todo 密码登录 MD5 //检查用户名和密码是否匹配: User user = userMapper.selectLogin(username,password); if(user == null){ return ServerResponse.createByErrorMessage("密码错误"); } //登录成功,密码处理为null; user.setPassword(StringUtils.EMPTY); return ServerResponse.createBySuccess("登录成功",user); }
UserController.java
private IUserService iUserService; /** * 用户登录 * @param username * @param password * @param session * @return * 登录成功后把用户信息存进session */ @RequestMapping(value="login.do", method = RequestMethod.POST) @ResponseBody public ServerResponse<User> login(String username, String password, HttpSession session){ ServerResponse<User> response = iUserService.login(username, password); System.out.println("------Controller返回username=---------"+username); if(response.isSuccess()){ session.setAttribute(Const.CURRENT_USER,response.getData()); } return response; }
写回答
3回答
-
筱爻
提问者
2017-08-21
已经解决:
SELECT <include refid="Base_Column_List" /> from mall_user
WHERE username = #{username},password = #{password}}
应该为:
SELECT <include refid="Base_Column_List" /> from mall_user
WHERE username = #{username} and password = #{password}
00 -
qq_浮空_03536131
2017-08-15
如果还不行, 看看你的调试工具, 输出那里 是不是弄错了
022017-08-19 -
舞有涵意
2017-08-14
<select id="selectLogin" resultMap="BaseResultMap" parameterType="map">
SELECT <include refid="Base_Column_List" /> from mall_user
WHERE username = #{username},password = #{password}}
</select>
你好,我看到你的sql多了一个“}”,password = #{password}} ,去掉后调试一下,谢谢。
022017-08-19
相似问题