尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

SpringMVC注解1@RequestMapping

SpringMVC注解1@RequestMapping RequestMapping1.作用建立浏览器与后端代码服务器之间的映射关系。2.用法补最终访问地址 类路径 方法路径类路径可没有1仅注解在【方法】上类上不加 RequestMapping类路径为空直接使用方法注解内配置的路径访问。RestControllerpublicclassHelloController{RequestMapping(/hello)publicStringhello(){returnhello springboot;}}2注解在类上这时就要用类路径➕方法路径其中方法路径有不同写法a.使用GetMapping,支持get 请求RestControllerRequestMapping(/hello)publicclassHelloController{//支持getGetMapping(/hello1)publicStringhello(){returnhello spring mvc111;}发送get请求正常发送post会报405错误b.使用RequestMapping(value “”,method {})在method中指定get和post请求方式RequestMapping(value/hello2,method{RequestMethod.GET,RequestMethod.POST})publicStringhello2(){returnhello, spring mvc222;}get请求和post请求都正常c.PostMapping()只支持post请求PostMapping(/hello3)publicStringhello3(){returnhello, spring mvc333;}post请求是正常的get请求就会报405错误
返回列表