收获

今天独立的把注册登陆做出来的,感觉很有成就感。小小的show一下下:

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

    public String initLogin(UserBean userBean, Model model){

    UserBean result = helloWorldService.searchUser(userBean);

        if(result!=null){

            List<UserBean> resultList = helloWorldService.searchUserall(userBean);

            model.addAttribute("List",resultList);

                return "denglu";

        }

        else{

            model.addAttribute("message","登陆失败!");

                return "first";

        }

    }

@RequestMapping(value = "/index", method = RequestMethod.POST, params = "register")

public String initloginzhuce(UserBean userBean, Model model) {

return "zhuce";

}

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

    public String initregister(UserBean userBean, Model model){

    String pass1=userBean.getPassword();

    String pass2=userBean.getPassconfirm();

    if(pass1.equals(pass2)){

    int insert=helloWorldService.insert(userBean);

    //UserBean user=new UserBean();

    if(insert==1){

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

    return "zhuce";

    }else{

    model.addAttribute("userBean", userBean);

    model.addAttribute("message", "ID或用户名已存在");

    return "zhuce";

    }

    }else{

    model.addAttribute("userBean", userBean);

    model.addAttribute("message", "两次密码不一致!");

    return "zhuce";

    }(if的逻辑关系,开始有点小糊涂,换了种简洁写法就易懂了)

}


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

public String intinsert1(UserBean userBean, Model model) {

return "first";

}

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

public String initdelete(UserBean userdelete, Model model) {

return "queren";

}

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

public String deleteok(UserBean userBean, Model model) {

List<UserBean> resul = helloWorldService.searchUserall(userBean);

model.addAttribute("List", resul);

return "denglu";

}

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

public String delete(UserBean userdelete, Model model) {

int result = helloWorldService.deleteUser(userdelete);

if(result==1){

List<UserBean> resultList = helloWorldService.searchUserall(userdelete);

model.addAttribute("List", resultList);

return "denglu";

}else{

model.addAttribute("message", "删除错误!");

return "denglu";

}

}

你可能感兴趣的:(收获)