2
我正在學習Spring Boot,現在我寫了一個小應用程序。該應用程序有此控制器:Spring Boot - POST請求方法不起作用,但GET做了
@Controller
@RequestMapping("/")
public class ApplicationController {
@RequestMapping(value="/account", method = RequestMethod.POST)
public String getAccountVo(ModelMap model) {
AccountVO vo = new AccountVO();
vo.setAccountNo("0102356");
vo.setAccountHolderName("Dinesh");
model.addAttribute("acc", vo);
return "account";
}
}
...並在頁面(視圖)是:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Account Details</title>
</head>
<body>
<form>
Account number <input type="text" name="acctNo" value="${acc.getAccountNo()}"><br>
Account Holder Name <input type="text" name="name" value="${acc.getAccountHolderName()}"><br>
</form>
</body>
</html>
當我運行應用程序,我得到了HTTP Status 405
與消息Request method 'GET' not supported
。但是當我將@RequestMapping
註釋中的方法更改爲method=RequestMethod.GET
時,我得到了預期的頁面。
爲什麼會發生這種情況?