標籤: springmvc mybatisjava
[TOC]mysql
本文主要展現如何在intellij IDEA中經過maven構建springmvc+mybatis框架的開發環境。git
需求:使用springmvc和mybatis完成商品列表查詢github
第一步:整合dao層web
第二步:整合service層spring
第三步:整合springmvcsql
不一樣於《mybatis學習筆記(17)-spring和mybatis整合》中的示例demo,本文的整合採用maven構建。apache
如何建立使用maven構建的web應用能夠參考前面的一篇《springmvc學習筆記(1)-框架原理和入門配置》api
new->project->maven
,建一個裸的maven工程,手動建webapp的目錄spring-mvc
在src/main
下新建文件夾webapp
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <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.iot.learnssm</groupId> <artifactId>learnssm-firstssm</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- jar 版本設置 --> <spring.version>4.2.4.RELEASE</spring.version> </properties> <dependencies> <!-- spring框架--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.4</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.18</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <!-- JSP tag --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> </dependencies> </project>
這裏添加的依賴可能有多的,但總比少包好,我開始就是引少了依賴(springframework的依賴只引用了spring-mvc,連spring-core都沒引),致使報錯,之後會出一篇博客專門講這個系列筆記中debug相關問題。
在java目錄下建各個package,按照maven的命名習慣:
com.公司名.項目名.模塊名
這裏個人包爲:
com.iot.learnssm.firstssm
包含幾個子包:
項目結構如圖:
後面幾篇筆記會依次記錄mapper,service,controller各個部分的整合