1.springmvc项目成功启动,但是访问controller却报404?
首先查看访问路径中的项目名称是否正确:即项目在tomcat中部署的路径;然后查看,访问路径与实际代码中controller中RequestMapping的配置路径是否一致!
在上述都正常的情况下,我在这里遇到的坑如下(简直坑死个人):
在这里我的springMVC的配置文件:spring-mvc.xml和spring的配置文件:applicationContext.xml是分开的,
而我只在applicationContext.xml中配置了包扫描,没有在spring-mvc.xml配置,然后加上就可以了!
2.springmvc返回给前端字符串乱码问题?
spring-mvc.xml文件添加如下内容:
<mvc:annotation-driven>
<!--处理返回json乱码,StringHttpMessageConverter中默认的是ISO-->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>