做自适应网站公司,网站版权模板,做图形的网站,交互设计的方法和技巧第一章 RequestMapping详解 RequestMapping注解作用#xff1a;为指定的类或方法设置相应URL 1.1 RequestMapping注解位置
书写在类上面 作用#xff1a;为当前类设置映射URL注意#xff1a;不能单独使用#xff0c;需要与方法上的RequestMapping配合使用 书写在方法上面 …第一章 RequestMapping详解 RequestMapping注解作用为指定的类或方法设置相应URL 1.1 RequestMapping注解位置
书写在类上面 作用为当前类设置映射URL注意不能单独使用需要与方法上的RequestMapping配合使用 书写在方法上面 作用为当前方法设置映射URL注意可以单独使用
1.2 RequestMapping注解属性 value属性 类型String[]作用设置URL信息 path属性 类型String[]作用与value属性作用一致 method属性 类型RequestMethod[] public enum RequestMethod {GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
}作用为当前URL【类或方法】设置请求方式【POST、DELETE、PUT、GET】 注意 默认情况所有请求方式均支持如请求方式不支持会报如下错误 405【Request method ‘GET’ not supported】 params 类型String[]作用为当前URL设置请求参数注意如设置指定请求参数但URL中未携带指定参数会报如下错误 400【Parameter conditions “lastName” not met for actual request parameters:】 headers 类型String[]作用为当前URL设置请求头信息注意如设置指定请求头但URL中未携带请求头会报如下错误 404请求资源未找到 示例代码 RequestMapping(value {/saveEmp,/insertEmp},method RequestMethod.GET,params lastNamelisi,headers User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36)
public String saveEmp(){System.out.println(添加员工信息);return SUCCESS;
}RequestMapping(method RequestMethod.POST)
public interface PostMapping {}
RequestMapping(method RequestMethod.GET)
public interface GetMapping {}
RequestMapping(method RequestMethod.PUT)
public interface PutMapping {}
RequestMapping(method RequestMethod.DELETE)
public interface DeleteMapping {}1.3 RequestMapping支持Ant 风格的路径了解 常用通配符 a) ?匹配一个字符 b) *匹配任意字符 c) **匹配多层路径 示例代码 RequestMapping(/testAnt/**)
public String testAnt(){System.out.println(testAnt!!!);return SUCCESS;
}