有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring:实际请求参数不满足参数条件“loanTitle”

Java Spring MVC。没有参数我无法打开url。我在网上找到了一些建议,但它们对我没有帮助

@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)
    {
....
    }

URL有效

http://localhost:8080/college/loans/objectloan?loanTitle=test

URL错误

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).

共 (1) 个答案

  1. # 1 楼答案

    由于loanTitle可能不在查询url中,请尝试删除控制器方法中的params = {"loanTitle"}

        @GetMapping(value= "objectloan")
        public String index(Model theModel, HttpSession session, @RequestParam(value = "loanTitle", required = false, defaultValue = "") Optional<String> loanTitle)
        {
    ....
        }