xinxuaw231 发表于 2016-11-26 00:16:43

spring mvc + spring + mybatis环境搭建

spring mvc + spring + mybatis环境搭建
使用工具:
maven,  eclipse , mysql, druid, hibernate-validate jsr303
 
整个工程已经上传附件中。
 
在这记录搭建过程中,遇到的问题。
 
搭建顺序
先搭建spring 和 mybatis的集成,然后junit测试通过再进行 spring mvc的集成。
 
1、spring 和 mybatis的集成
会用到spring.xml和spring-mybatis.xml
使用的jar主要是
spring-core.jar
mybatis-spring.jar
mytais.jar
 
2、spring mvc集成
配置文件spring-mvc.xml,  web.xml
使用的jar:
spring-webmvc.jar
 
3、注意:web.xml中
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value>
  </context-param>
 
<!-- 配置spring mvc -->
  <servlet>
   <servlet-name>springMvc</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-mvc.xml</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>springMvc</servlet-name>
   <url-pattern>/</url-pattern>
  </servlet-mapping>
这两个名字要一致,否则会报莫名的错误。
 
4、静态文件不在spring管理的配置
<mvc:annotation-driven />
<!-- spring mvc对静态资源的访问 -->
 <mvc:resources location="/image/**" mapping="/image/**" />
 <mvc:resources location="/js/**" mapping="/js/**" />
 <mvc:resources location="/style/**" mapping="/style/**" />
 
这样,js,图片等文件才能正常访问。
 
5、jsp 引入js方式
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery-1.9.0.min.js"></script>
 
页: [1]
查看完整版本: spring mvc + spring + mybatis环境搭建