The springMVC Requestmapping failure interface prompts 404-Parameter binding failed

The problem is that four @RequestMappings are configured under a @Controller, two of which can be accessed and the other two are accessed after 404 errors.

Looking at the spring_mvc-servlet file, all four methods are registered. And if there is no registration here, it should return to the homepage to log in, and no 404 error will occur.

The configuration used by @RequestMapping( "/account/invests") is a very common configuration

 

If the above problems occur, you can also locate the problem to the parameters. The URL bound by RequestMapping is also related to the parameters. The problem after investigation here is, parameter binding

Failed, and the parameter is of type int

1. Basic data types (take int as an example, others are similar):

Controller code:

@RequestMapping("saysth.do")



public void test(int count) {



}

 

Form code:

<form action="saysth.do" method="post">
<input name="count" value="10" type="text"/>
......
</form>

 

The name value of the input in the form is consistent with the parameter variable name of the Controller, and the data binding can be completed. If it is inconsistent, you can use the @RequestParam annotation. It should be noted that if the basic data type is defined in the controller method parameter, but the data submitted from the page is null or "", a data conversion exception will occur. That is to say, it must be ensured that the data passed by the form cannot be null or "". Therefore, in the development process, for the data that may be empty, it is best to define the parameter data type as a wrapper type . For details, see the following example.

Packaging type (take Integer as an example, others are similar):

Controller code:

@RequestMapping("saysth.do")
public void test(Integer count) {
}

 

Form code:

<form action="saysth.do" method="post">
<input name="count" value="10" type="text"/>
......
</form>

 

It is basically the same as the basic data type. The difference is that the data passed by the form can be null or "". Taking the above code as an example, if the num in the form is "" or there is no num input in the form, then the Controller method parameter The num value in is null.

 

The problem with the current project is that the paging page and rows in the parameters are defined as int types, and the calling url does not pass parameters. Just replace it with Integer

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325238433&siteId=291194637