4
回答
Spring MVC框架 我这样写注册功能对么
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   

Cnotroller

@RequestMapping(value = "aaa")
public ModelAndView aaa(HttpServletRequest request, User user){
ModelAndView mav = new ModelAndView();
Map<String, Object> map = new HashMap<String, Object>(); 
map.put("login", user.getLogin());//map.put得到帐号
   map.put("pwd", ConvertUtils.stringToMD5(user.getPwd()));//得到密码(密码用MD5加密)
if(user.getLogin() == null){
request.setAttribute("login",user.getLogin());
request.setAttribute("pwd", user.getPwd());
mav.setViewName("redirect:/success.jsp");
} else {
mav.setViewName("redirect:/test.jsp");
}

return mav;
}

service

public User zhuce(Map<String, Object> map){
try {
return dao.zhuce(map);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

DAO

public User zhuce(Map<String, Object> map);

xml

<insert id="zhuce" parameterType="User" keyProperty="id">
insert into user(
u_login,
u_pwd,)
values(
#{login},
#{pwd},)
</insert>

不对的话怎么修改

一运行就这样了

对了这是我随便写的form注册登录界面

<form action="aaa" method = "post">
账户:<input type="text" name="login" id="zhuce"><br>
密码:<input type="password" name="pwd"><br>
<input type="submit" value="注册">
</form>



举报
小小哈哈
发帖于1年前 4回/304阅
顶部