Java Spring MVC。没有参数我无法打开url。我在Internet(Spring MVC Thymeleaf Error: Parameter conditions not met for actual request parameters,http://www.baeldung.com/spring-requestmapping)中找到了建议,但是它们没有帮助我。
@Controller
@RequestMapping("/loans/")
public class LoanController {
@Autowired
LoanDAO loanDAO;
@GetMapping(value= "objectloan", params = {"loanTitle"})
public String index(Model theModel, HttpSession session, @RequestParam(value = "loanTitle", required = false, defaultValue = "") Optional<String> loanTitle)
{
....
}
网址有效
http://localhost:8080/college/loans/objectloan?loanTitle=test
网址错误
http://localhost:8080/college/loans/objectloan
错误:
Type Status Report
Message Parameter conditions "loanTitle" not met for actual request parameters:
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
最佳答案
由于查询网址中可能没有loanTitle
,请尝试在控制器方法中删除params = {"loanTitle"}
@GetMapping(value= "objectloan")
public String index(Model theModel, HttpSession session, @RequestParam(value = "loanTitle", required = false, defaultValue = "") Optional<String> loanTitle)
{
....
}