【发布时间】:2016-09-22 08:28:48
【问题描述】:
我正在尝试使用 Spring Boot 创建一个帐户控制器。我有一个位于 static/login.html 下的登录页面的 html 文件。当我没有将 POST 请求映射到同一路径时,页面加载得非常好。
我有一个 AccountController 类:
@RestController
public class AccountController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
public Account login(@RequestBody Map<String, Object> body) {
// code
}
}
此控制器禁用对 html 页面的 GET 请求。尝试访问该页面时,我收到了;
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
所以我的问题本质上是,如何让 POST 和 GET 请求同时工作。如果有更好的文件结构可以用于静态内容,请提出建议。
【问题讨论】:
标签: java html spring spring-mvc spring-boot