SpringMVC学习注意事项

版权声明:本BLOG上原创文章未经本人许可,不得用于商业用途及传统媒体。网络媒体转载请注明出处,否则属于侵权行为。 https://blog.csdn.net/haobindayi/article/details/81944961

1.注解@RequestMapping

通过RequestMapping注解可以定义不同的处理器映射规则。

  1. @RequestMapping(value="/item")或@RequestMapping("/item)value的值是数组,可以将多个url映射到同一个方法

  2. 限定GET方法 @RequestMapping(method = RequestMethod.GET) @GetMapping
  3. 限定GET方法 @RequestMapping(method = RequestMethod.POST) @PostMapping

2.Controller方法返回值

3.文件上传时

id不能为空,值不能改变 springMVC.xml中

<!-- 文件上传 -->

       <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

              <!-- 设置上传文件的最大尺寸为5MB -->

              <property name="maxUploadSize">

                     <value>5242880</value>

              </property>

       </bean>

4.使用springmvc中的restful格式注意

controller中返回rediret:/product/findall类似的全路径,省略容易发生错误,product窄化范围

猜你喜欢

转载自blog.csdn.net/haobindayi/article/details/81944961