The use springmvc RequestMapping binding @PathVariable

@PathVariable URL placeholder parameters can be bound to the controller of the processing method parameter.

@RequestMapping("/springmvc")
@Controller
public class SpringmvcTest {
    private static final String SUCCESS = "success";
    
    @RequestMapping(value="testPathVariable/{id}",method=RequestMethod.GET)
    public String testPathVariable(@PathVariable("id") Integer id) {
        System.out.println(id);
        return SUCCESS;
    }
}

In the jsp page:

<a href="springmvc/testPathVariable/1">testPathVariable</a>

The final value of the URL id value of id we testPathVariable method in.

Guess you like

Origin www.cnblogs.com/xiximayou/p/12176547.html