1.springmvc会为没有view的modelandview指定默认view
知道这个的时候我都惊呆了。
我从来都是手动指定view名字,今天看到别人写的代码竟然直接返回了个mav,貌似是在dispatcherservlet.dodispatch这个方法里面把url的路径直接当做view名字解析了
//这个Controller返回的是t23_third_person_manage.jsp这个视图 @RequestMapping("/t23_third_person_manage") public ModelAndView method2() { return new ModelAndView(); }
2.如下
<form:form action="<%=contextPath%>/labt/lawsuit/t23_third_person_list.do" //这种写法是错的 <form:form action='<%=contextPath +"/labt/lawsuit/t23_third_person_list.do" %>' //这种写法是对的
你可以使用<%%>或某个字符串为form:form或其它的springmvc标签的属性赋值,但你不能同时使用这两者,html标签则不关心这一点
3.@ResponseBody需要配置
这个注解不是能直接拿过来用的,得配一个json解析bean,还得引入好几个包,不然会报404.
最近在做一个老项目,项目里没有用过这个注解,我以为早就配置好了,拿过来用就出错.
4.String[]接收到空值时
springmvc会将空值转换成一个空的string数组,也就是一个长度为零的string数组。
这点和struts1不同,它会将空值封装成一个长度为1的string数组,这个数组中只有一个长度为零的字符串:“”,而不是null
5.接口写错时不一定会报404
有时候也会报:
DefaultServletHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod