@Controller @RequestMapping("/zmu") public class LoginController { @Autowired AccountDao adao; @GetMapping("/login") public String login(){ return "login"; } @GetMapping("/registry") public String registry(){ return "registry"; } @PostMapping("/addaccount") //方法中的参数名一定要与网页端属性为name的值一致 public String addAccount(String username,String password, Model model){ Account account=new Account(username,password); account= adao.saveAndFlush(account); if(account.getId()>0) model.addAttribute("success","帐户和密码添加成功"); else model.addAttribute("success","添加帐户和密码失败"); //redirect跳转到对路径,所带的信息会被丢弃 //redirect:/ return "registry"; } @PostMapping("/verify") //方法中的参数名一定要与网页端属性为name的值一致 public String verify(String username,String password, Model model){ boolean s=adao.existsByUsernameAndPassword(username,password); if(s) model.addAttribute("success","合法用户验证成功"); else model.addAttribute("success","无此帐户和密码,登录失败"); //redirect跳转到对路径,所带的信息会被丢弃 //redirect:/ return "login"; } //浏览帐户信息 @GetMapping("/accountshow") public String accountshow(Model model){ List<Account> lists=adao.findAll(); if(lists.size()!=0){ model.addAttribute("success",true); model.addAttribute("account",lists); } else model.addAttribute("success",false); return "account_show"; }对应的删除用户的方法代码
时间: 2023-06-26 12:09:08 浏览: 94
@Controller、@RestController注解区别详解
5星 · 资源好评率100%
@PostMapping("/deleteaccount")
public String deleteAccount(int id, Model model){
try{
adao.deleteById(id);
model.addAttribute("success","删除帐户成功");
}catch(Exception e){
model.addAttribute("success","删除帐户失败");
}
return "account_show";
}
阅读全文