英文:
Spring Boot controller does not redirect
问题
我创建了以下控制器:
@Controller
public class RootController {
@RequestMapping(path = "/login", method = RequestMethod.GET)
public String showLoginPage() {
return "redirect:resources/templates/login.html";
}
}
但是,尝试映射这个端点时,我收到了404错误。
这是目标页面的位置:
我做错了什么?
英文:
I create the following controller:
@Controller
public class RootController {
@RequestMapping(path = "/login", method = RequestMethod.GET)
public String showLoginPage() {
return "redirect:resources/templates/login.html";
}
}
But, trying to map this endpoint, I receive 404-ERROR.
This is a target-page location:
What am I doing wrong?
答案1
得分: 1
@Controller
public class RootController {
@GetMapping("/login")
public String showLoginPage() {
return "login";
}
It works for me. I hope it helps you!
<details>
<summary>英文:</summary>
@Controller
public class RootController {
@GetMapping("/login")
public String showLoginPage() {
return "login";
}
It works to me.I hope hepls you!
</details>
# 答案2
**得分**: 0
```java
@Controller
public class RootController {
@GetMapping("/login")
public String showLoginPage() {
return "login.html";
}
This will work
英文:
@Controller
public class RootController {
@GetMapping("/login")
public String showLoginPage() {
return "login.html";
}
This will work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论