用途一:实现页面的通用跳转
package com.jt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/page/{moduleName}")
public String module(@PathVariable String moduleName) {
return moduleName;
}
}
用途二:简化用户url写法
package com.jt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
@RequestMapping(value = "/item", method = RequestMethod.GET)
public void getItem(Integer id){
}
@RequestMapping(value = "/item", method = RequestMethod.POST)
public void saveItem(Item item){
}
}