1. 程式人生 > >常用框架(一):spring+springMvc+mybatis+maven

常用框架(一):spring+springMvc+mybatis+maven

專案說明:

(1) 本例採用 maven web 工程做例子講解

(2) 利用mybaits 提供的程式碼生成工具自動生成程式碼(dao介面,sql mapper對映檔案,pojo資料庫對映類)

(3) 資料庫用 MySQL

專案構建:

一,新建maven web 工程

網上有很多詳細的教程,初學者可以點這裡跳轉學習:eclipse建立maven工程

本例專案結構如下,待會再一步一步講解:


二,引入需要的jar包到pom.xml中,配置如下:

[html]  view plain
 copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.maven.web</groupId>  
  5.     <artifactId>com.maven.web</artifactId>  
  6.     <packaging
    >war</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>com.maven.web Maven Webapp</name>  
  9.   
  10.     <properties>  
  11.         <spring.version>4.3.0.RELEASE</spring.version>  
  12.         <jackson.version>2.6.5</jackson.version>  
  13.         <fastjson.version>1.2.23</fastjson.version>  
  14.         <mybatis.version>3.3.0</mybatis.version>  
  15.         <mybatis-spring.version>1.2.3</mybatis-spring.version>  
  16.         <mysql.connector.version>5.1.29</mysql.connector.version>  
  17.     </properties>  
  18.   
  19.     <repositories>  
  20.         <repository>  
  21.             <id>spring-milestones</id>  
  22.             <name>Spring Milestones</name>  
  23.             <url>https://repo.spring.io/libs-milestone</url>  
  24.             <snapshots>  
  25.                 <enabled>false</enabled>  
  26.             </snapshots>  
  27.         </repository>  
  28.     </repositories>  
  29.   
  30.     <dependencies>  
  31.         <dependency>  
  32.             <groupId>junit</groupId>  
  33.             <artifactId>junit</artifactId>  
  34.             <version>3.8.1</version>  
  35.             <scope>test</scope>  
  36.         </dependency>  
  37.   
  38.         <dependency>  
  39.             <groupId>javax.annotation</groupId>  
  40.             <artifactId>javax.annotation-api</artifactId>  
  41.             <version>1.2</version>  
  42.         </dependency>  
  43.   
  44.         <!-- Spring -->  
  45.         <dependency>  
  46.             <groupId>org.springframework</groupId>  
  47.             <artifactId>spring-core</artifactId>  
  48.             <version>${spring.version}</version>  
  49.         </dependency>  
  50.         <dependency>  
  51.             <groupId>org.springframework</groupId>  
  52.             <artifactId>spring-expression</artifactId>  
  53.             <version>${spring.version}</version>  
  54.         </dependency>  
  55.         <dependency>  
  56.             <groupId>org.springframework</groupId>  
  57.             <artifactId>spring-beans</artifactId>  
  58.             <version>${spring.version}</version>  
  59.         </dependency>  
  60.         <dependency>  
  61.             <groupId>org.springframework</groupId>  
  62.          &nbs