春季启动控制器不会重定向

huangapple go评论82阅读模式
英文:

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(&quot;/login&quot;)
    public String showLoginPage() {
        return &quot;login&quot;;
    }

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(&quot;/login&quot;)
public String showLoginPage() {
    return &quot;login.html&quot;;
}

This will work

huangapple
  • 本文由 发表于 2020年4月8日 17:34:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/61097574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定