使用@PathVariable注解实现动态传值

@RequestMapping(value="/Test/{id}")
public void Test(@PathVariable Integer id){
            .............
}
在页面表单的action中,写controller中对应的方法名

TestController.java
@RequestMapping(value="/{methodName}")
public String TZ(@PathVariable String methodName){
              return methodName;
}
@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/item/{itemId}")
	@ResponseBody
	public TbItem geItemById(@PathVariable Long itemId){
		TbItem tbItem = itemService.getItemById(itemId);
		return tbItem;
	}


猜你喜欢

转载自blog.csdn.net/qq_38097815/article/details/80376747