码迷,mamicode.com
首页 > 编程语言 > 详细

springMVC + mybatis总结

时间:2017-01-17 19:00:08      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:tar   jar   map   2.4   dbcp   snapshot   开发   ons   fas   

这周一直在研究SpringMVC+Mybatis,有些心得,记录一下。

Ⅰ:建maven遇到的问题。

  1.1 新建maven时选中【Create a simple project】这样,后面【Packaging】选项有【war/pom/jar】可供选择。

  1.2 新建maven时没有web.xml文件,会报错方法一是从别的项目copy过来一份

    方法二:【Project Facets】取消【Dynamic web Module】并且将【Java】选项调到1.6以上,选【OK】

        重新选中【Project Facts】中【Dynamic web Module】,在下面有一个【Futher Configuration aviable】

        点击后,选中【Generate web.xml deployment】就会自动生成web.xml

        同时将WebContent换成-》src/main/webapp

        最后确认【Deployment Assembly】中 src/main/webapp 后为“/”项目的根目录

  1.3 在maven里使用【${spring.version}】,因为在上边【Properties】属性里,定义了全局变量。

        <properties>
           <spring.version>4.0.2.RELEASE</spring.version>
         </properties>

  1.4 使用了build插件的一个理解:没有加入这个声明时,是按照jdk1.3来编译的

      参考:http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin

      <build> 
          <plugins> 
              <plugin> 
                  <groupId>org.apache.maven.plugins</groupId> 
                  <artifactId>maven-compiler-plugin</artifactId> 
                  <version>3.3</version> 
                  <configuration> 
                      <!-- 指定source和target的版本 -->                
                      <source>1.8</source>  =<source>${jdk.version}</source>
                      <target>1.8</target>   =<targer>${jdk.version}</targer>
                  </configuration> 
              </plugin> 
          </plugins> 
      </build>

Ⅱ:建spring工程需要的jar包

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.msm2</groupId>
  <artifactId>msm2</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
   <properties>  
        <!-- spring版本号 -->  
        <spring.version>4.0.2.RELEASE</spring.version>  
        <!-- mybatis版本号 -->  
        <mybatis.version>3.2.6</mybatis.version>  
        <!-- log4j日志文件管理包版本 -->  
        <slf4j.version>1.7.7</slf4j.version>  
        <log4j.version>1.2.17</log4j.version>  
    </properties> 
  
  <dependencies>
  
  <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.11</version>  
            <!-- 表示开发的时候引入,发布的时候不会加载此包 -->  
            <scope>test</scope>  
        </dependency> 
  	<!-- spring -->
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-core</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>
  	<dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-web</artifactId>  
            <version>3.1.1.RELEASE</version>  
        </dependency> 
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-oxm</artifactId>  
            <version>4.2.3.RELEASE</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-tx</artifactId>  
            <version>4.3.3.RELEASE</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-jdbc</artifactId>  
            <version>4.3.3.RELEASE</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context-support</artifactId>  
            <version>${spring.version}</version>  
        </dependency> 
  	<dependency>
  	
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-aop</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-beans</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-asm</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-orm</artifactId>
  		<version>3.1.1.RELEASE</version>
  	</dependency>  	
  	<dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-test</artifactId>  
            <version>${spring.version}</version>  
        </dependency>         
    <dependency>
    	<groupId>org.springframework.security</groupId>
    	<artifactId>spring-security-core</artifactId>
    	<version>3.1.3.RELEASE</version>
	</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.servlet</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web.portlet</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.transaction</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>

        
    <!-- mybatis核心包 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>${mybatis.version}</version>  
        </dependency>  
        <!-- mybatis/spring包 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.2.2</version>  
        </dependency> 
  	
  	<!-- oracle连接 -->
    <dependency>  
    	<groupId>com.oracle</groupId>  
        <artifactId>ojdbc14</artifactId>  
        <version>10.2.0.3.0</version>  
    </dependency> 
    
    <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->  
        <dependency>  
            <groupId>commons-dbcp</groupId>  
            <artifactId>commons-dbcp</artifactId>  
            <version>1.2.2</version>  
        </dependency>  
        <!-- JSTL标签类 -->  
        <dependency>  
            <groupId>jstl</groupId>  
            <artifactId>jstl</artifactId>  
            <version>1.2</version>  
        </dependency>  
    <!-- log4j -->  
    <dependency>  
    	<groupId>log4j</groupId>  
		<artifactId>log4j</artifactId>  
		<version>1.2.17</version>
	</dependency>
  
	<dependency>  
		<groupId>javax.servlet</groupId>  
		<artifactId>jstl</artifactId>  
		<version>1.2</version>  
	</dependency>  
	
	<!-- 格式化对象,方便输出日志 -->  
        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>fastjson</artifactId>  
            <version>1.1.41</version>  
        </dependency> 
        
    <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-api</artifactId>  
            <version>${slf4j.version}</version>  
        </dependency>  
  
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-log4j12</artifactId>  
            <version>${slf4j.version}</version>  
        </dependency> 
        
    <!-- log end -->  
        <!-- 映入JSON -->  
        <dependency>  
            <groupId>org.codehaus.jackson</groupId>  
            <artifactId>jackson-mapper-asl</artifactId>  
            <version>1.9.13</version>  
        </dependency>  
        <!-- 上传组件包 -->  
        <dependency>  
            <groupId>commons-fileupload</groupId>  
            <artifactId>commons-fileupload</artifactId>  
            <version>1.3.1</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-io</groupId>  
            <artifactId>commons-io</artifactId>  
            <version>2.4</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-codec</groupId>  
            <artifactId>commons-codec</artifactId>  
            <version>1.9</version>  
        </dependency>  
  
  </dependencies>
  <repositories>
  	<repository>
  		<id>aliyun-nexus</id>
  		<name>Nexus</name>
  		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  	</repository>
  </repositories>
  <pluginRepositories>
  	<pluginRepository>
  		<id>aliyun-nexus</id>
  		<name>Nexus</name>
  		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  	</pluginRepository>
  </pluginRepositories>
  
  
  <build>  
    <plugins>  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <version>3.3</version>  
            <configuration>  
                <!-- 指定source和target的版本 -->                 
                <source>1.8</source>  
                <target>1.8</target>  
            </configuration>  
        </plugin>  
    </plugins>  
</build>
</project>

Ⅲ:切换workspace时,要检查setting.xml文件是否是自己需要的。

springMVC + mybatis总结

标签:tar   jar   map   2.4   dbcp   snapshot   开发   ons   fas   

原文地址:http://www.cnblogs.com/ysloong/p/6094575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!