gpt4 book ai didi

java - 意外错误(类型=未找到,状态=404)

转载 作者:行者123 更新时间:2023-12-02 10:08:56 25 4
gpt4 key购买 nike

我正在使用 Spring Boot 并遇到错误:出现意外错误(类型=未找到,状态=404)

我的 .jsp 页面位于文件夹 src>main>webapp>WEB-INF>views

application.properties:

spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix:.jsp
spring.messages.basename=validation

Controller :

@Controller
public class UserController {
@Autowired
private UserService userService;

@Autowired
private SecurityService securityService;

@Autowired
private UserValidator userValidator;

@GetMapping("/registration")
public String registration(Model model) {
model.addAttribute("userForm", new User());

return "registration";
}

@PostMapping("/registration")
public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult) {
userValidator.validate(userForm, bindingResult);

if (bindingResult.hasErrors()) {
return "registration";
}

userService.save(userForm);

securityService.autoLogin(userForm.getUsername(), userForm.getPasswordConfirm());

return "redirect:/welcome";
}

@GetMapping("/login")
public String login(Model model, String error, String logout) {
if (error != null)
model.addAttribute("error", "Your username and password is invalid.");

if (logout != null)
model.addAttribute("message", "You have been logged out successfully.");

return "login";
}

@GetMapping({"/", "/welcome"})
public String welcome(Model model) {
return "welcome";
}
}

但它仍然找不到页面。我该怎么办?

最佳答案

请尝试进行以下更改:

  1. 在末尾添加正斜杠:spring.mvc.view.prefix:/WEB-INF/views/
  2. 将@RestController更改为@Controller

关于java - 意外错误(类型=未找到,状态=404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55134264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com