微信開發準備(二)--springmvc+mybatis專案結構的搭建
轉自:http://www.cuiyongzhi.com/post/34.html
前面一篇有說道如何在MyEclipse中搭建maven專案,這裡將繼續介紹如何在搭建好的基礎maven專案中引入我們常用的javaweb框架——SpringMVC!
①在建立好的maven專案中的pom.xml檔案引入依賴,程式碼如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
<
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/maven-v4_0_0.xsd
>
<
modelVersion
>4.0.0</
modelVersion
>
<
groupId
>wechat.cuiyongzhi.com</
groupId
>
<
artifactId
>wechat</
artifactId
>
<
packaging
>war</
packaging
>
<
version
>0.0.1-SNAPSHOT</
version
>
<
name
>wechat</
name
>
<
url
>http://maven.apache.org</
url
>
<
dependencies
>
<!-- spring -->
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-test</
artifactId
>
<
version
>3.2.0.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-webmvc</
artifactId
>
<
version
>3.2.0.RELEASE</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework</
groupId
>
<
artifactId
>spring-core</
artifactId
>
<
version
>3.2.0.RELEASE</
version
>
</
dependency
>
<!-- mybatis -->
<
dependency
>
<
groupId
>org.mybatis</
groupId
>
<
artifactId
>mybatis</
artifactId
>
<
version
>3.1.1</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.mybatis</
groupId
>
<
artifactId
>mybatis-spring</
artifactId
>
<
version
>1.1.1</
version
>
</
dependency
>
<!-- mysql -->
<
dependency
>
<
groupId
>mysql</
groupId
>
<
artifactId
>mysql-connector-java</
artifactId
>
<
version
>5.1.21</
version
>
</
dependency
>
<!-- junit測試 -->
<
dependency
>
<
groupId
>junit</
groupId
>
<
artifactId
>junit</
artifactId
>
<
version
>4.11</
version
>
<
scope
>test</
scope
>
</
dependency
>
<!-- mysql阿里連線池druid -->
<
dependency
>
<
groupId
>com.alibaba</
groupId
>
<
artifactId
>druid</
artifactId
>
<
version
>0.2.9</
version
>
</
dependency
>
<!-- spring aop包 -->
<
dependency
>
<
groupId
>org.aspectj</
groupId
>
<
artifactId
>aspectjweaver</
artifactId
>
<
version
>1.7.1</
version
>
</
dependency
>
<!-- json包 -->
<
dependency
>
<
groupId
>com.alibaba</
groupId
>
<
artifactId
>fastjson</
artifactId
>
<
version
>1.2.7</
version
>
</
dependency
>
<!-- 檔案上傳包 -->
<
dependency
>
<
groupId
>commons-fileupload</
groupId
>
<
artifactId
>commons-fileupload</
artifactId
>
<
version
>1.2.2</
version
>
</
dependency
>
<!--servlet包 -->
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>servlet-api</
artifactId
>
<
version
>3.0-alpha-1</
version
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet.jsp</
groupId
>
<
artifactId
>jsp-api</
artifactId
>
<
version
>2.1</
version
>
<
scope
>provided</
scope
>
</
dependency
>
<
dependency
>
<
groupId
>javax.servlet</
groupId
>
<
artifactId
>jstl</
artifactId
>
<
version
>1.2</
version
>
</
dependency
>
<!-- 日誌包 -->
<
dependency
>
<
groupId
>log4j</
groupId
>
<
artifactId
>log4j</
artifactId
>
<
version
>1.2.17</
version
>
</
dependency
>
</
dependencies
>
<
build
>
<
finalName
>wechat</
finalName
>
</
build
>
</
project
>
|
②修改專案路徑下的web.xml檔案如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:web
=
"http://java.sun.com/xml/ns/javaee"
xmlns
=
"http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd"
id
=
"WebApp_ID"
version
=
"3.0"
>
<
display-name
>com.cuiyongzhi.wechat</
display-name
>
<
context-param
>
<
param-name
>contextConfigLocation</
param-name
>
<
param-value
>classpath:spring.xml,classpath:spring-mybatis.xml</
param-value
>
<!-- ,classpath:spring-quartz.xml 用於做任務排程 任務定時都可以 -->
</
context-param
>
<
context-param
>
<
param-name
>log4jConfigLocation</
param-name
>
<
param-value
>classpath:log4j.properties</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>org.springframework.web.util.Log4jConfigListener</
listener-class
>
</
listener
>
<
|