综合

增删查改,点id可以删除数据,点name修改用户信息

导读: 

用户登录然后显示列表

@RequestMapping(value = "/init", method = RequestMethod.POST, params = "login")

public String initLogin(UserBean userBean, Model model) {

UserBean result = helloWorldService.searchUser(userBean);// 将查询的结果返回给result

// model.addAttribute("userBean", result);


if (result != null) {

List<UserBean> result1 = helloWorldService.searchUser1();// 登录验证成功了以后再加入列表

model.addAttribute("list", result1);

return "login";


} else {

model.addAttribute("message", "您输入的用户名和密码有误,请重新输入!");

}

return "helloWorld";

}

注册

@RequestMapping(value = "/insert", method = RequestMethod.POST, params = "register2")

public String initregister(UserBean userBean, Model model) {

String pass1=userBean.getPassword();

String pass2=userBean.getPasswordConfirm();

if (pass1.equals(pass2)) {

int result = helloWorldService.insert(userBean);

if(result==1)

{

model.addAttribute("message", "注册成功!");

return "success";

}else{

model.addAttribute("message", "注册失败!");

model.addAttribute("userBean", userBean);

return "register";

}

}else{

model.addAttribute("message", "两次密码不一致,请重新输入!");

model.addAttribute("userBean", userBean);

}

return "register";

}


用户删除:(<a th:href="@{delete(userId=${user.userId})}"><span th:text="${user.userId}"></span></a>)

@RequestMapping(value = "/deleteuser", method = RequestMethod.POST,params="no")

public String deleteuser(UserBean userBean, Model model) {

List<UserBean> refresh =helloWorldService.searchUser1();

model.addAttribute("list",refresh);

return "login";

}

@RequestMapping(value = "/deleteuser", method = RequestMethod.POST,params="delete")

public String delete(UserBean userBean, Model model) {

int result = helloWorldService.delete(userBean);

List<UserBean> refresh =helloWorldService.searchUser1();

model.addAttribute("list",refresh);

return "login";

}

用户修改:(<a th:href="@{change(userId=${user.userId})}"><span th:text="${user.userName}"></span></a>)


@RequestMapping(value = "/change", method = RequestMethod.GET)

public String change(UserBean userBean, Model model) {

UserBean result=helloWorldService.searchUser2(userBean);

model.addAttribute("userBean",result);

return "change";

}

@RequestMapping(value = "/update", method = RequestMethod.POST)

public String initUpdate(UserBean userBean, Model model) {


int update=helloWorldService.update(userBean);

if (update==1) {

List<UserBean> refresh =helloWorldService.searchUser1();

model.addAttribute("list",refresh);

return "login";

}else{

model.addAttribute("message", "修改失败!");

model.addAttribute("userBean", userBean);

return "change";

}


相关资讯

发表评论
网友评论0 条评论)
暂无评论