9、RequestMapping说明
作用
用于映射
@Controller
//@RequestMapping("/c3")
public class ControllerTest3{
@RequestMapping("/t1")
public String test1(Model model){
//封装数据
model.addAttribute("msg","controllerTest3");
return "test";
}
}
localhost:8080/c3/t1
如果同时注解了类和方法,类和方法需要同时访问,先访问类路径。
更推荐这样写,
//在方法上
@RequestMapping("/c3/t1")
因为如果在代码量很大很复杂,写在类上的注释可能会被忽略。
养成良好的代码习惯