Spring+SpringMVC+MyBaties问题总结(一)

来源:互联网 发布:windows 10家庭版关闭 编辑:程序博客网 时间:2024/05/17 18:44

问题1:导入maven工程时提示错误 Cannot change version of project facet Dynamic Web Module to 2.5.

解决方法:修改工程目录下的文件 .settings/org.eclipse.wst.common.project.facet.core.xml,做如下修改

                  <installed facet="jst.web" version="2.5" />

                   按如上方法修改后,如果还有这个错误,则需要将web.xml中<web-app>对应的版本值与上面的值统一即可。

                  如果还是提示这个错误,有可能是eclipse缓存问题,在Problems中删除错误提示即可。


问题2:update maven之后jre被改成1.5的问题

解决方法:在pom.xml中加入如下配置

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>



问题3:java.lang.ClassNotFoundException:       org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

解决方法:参照 http://blog.csdn.net/yixiaoping/article/details/45281721

1)springMVC配置文件开启注解

[html] view plain copy
  1. <!-- 开启注解-->  
  2.  <mvc:annotation-driven />  


(2)添加springMVC需要添加如下配置。 (这个要注意spring版本,3.x和4.x配置不同

spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

具体可以查看spring-web的jar确认,哪个存在用哪个!

spring3.x配置:

[html] view plain copy
  1. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  2.     <property name="messageConverters">  
  3.         <list>  
  4.             <ref bean="jsonHttpMessageConverter" />  
  5.         </list>  
  6.     </property>  
  7. </bean>  
  8.   
  9. <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
  10.     <property name="supportedMediaTypes">  
  11.         <list>  
  12.             <value>application/json;charset=UTF-8</value>  
  13.         </list>  
  14.     </property>  
  15. </bean>  


spring4.x配置:

[html] view plain copy
  1. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  2.     <property name="messageConverters">  
  3.         <list>  
  4.             <ref bean="jsonHttpMessageConverter" />  
  5.         </list>  
  6.     </property>  
  7. </bean>  
  8.   
  9. <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  10.     <property name="supportedMediaTypes">  
  11.         <list>  
  12.             <value>application/json;charset=UTF-8</value>  
  13.         </list>  
  14.     </property>  
  15. </bean>  

(3)pom.xml添加jackson依赖(这个要注意spring版本,3.x和4.x配置不同

如果是spring 3.x,pom.xml添加如下配置

[html] view plain copy
  1.        <dependency>  
  2.             <groupId>org.codehaus.jackson</groupId>  
  3.             <artifactId>jackson-core-lgpl</artifactId>  
  4.             <version>1.8.1</version>  
  5.          </dependency>  
  6.   
  7.   
  8.         <dependency>  
  9.             <groupId>org.codehaus.jackson</groupId>  
  10.             <artifactId>jackson-mapper-lgpl</artifactId>  
  11.             <version>1.8.1</version>  
  12.         </dependency></span>  
spring4.x,  pom.xml添加如下配置

[html] view plain copy
  1.    <dependency>  
  2.     <groupId>com.fasterxml.jackson.core</groupId>  
  3.     <artifactId>jackson-core</artifactId>  
  4.     <version>2.5.2</version>  
  5. </dependency>  
  6.   
  7. <dependency>  
  8.     <groupId>com.fasterxml.jackson.core</groupId>  
  9.     <artifactId>jackson-databind</artifactId>  
  10.     <version>2.5.2</version>  
  11. </dependency>  

这里要说明一下,spring3.x用的是org.codehaus.jackson的1.x版本,在maven资源库,已经不在维护,统一迁移到com.fasterxml.jackson,版本对应为2.x







问题4:ajax接收不到controller返回的对象数据

解决方法:

           jsp/html文件的头应该是

    <%@ pagelanguage="java"contentType="text/html;charset=UTF-8"

pageEncoding="UTF-8"%>

   否则接收不到。


0 0
原创粉丝点击