使用myeclipse搭建SSM(springMVC+spring+mybatis)
程序员文章站
2022-11-02 16:07:37
一、SSM搭建 1、使用的工具: myeclipse+jdk8+maven+MySQL+Tomcat8.5 2、配制文件截: 二、配置文件 1、web.xml 1 2
view code
view code
view code
view code
view code
view code
view code
view code
一、ssm搭建
1、使用的工具: myeclipse+jdk8+maven+mysql+tomcat8.5
2、配制文件截:
二、配置文件
1、web.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="webapp_id" version="3.1"> 3 <display-name>tomm</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 <listener> 13 <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> 14 </listener> 15 <listener> 16 <listener-class>org.springframework.web.util.introspectorcleanuplistener</listener-class> 17 </listener> 18 <context-param> 19 <param-name>contextconfiglocation</param-name> 20 <param-value>classpath:applicationcontext.xml</param-value> 21 </context-param> 22 <filter> 23 <filter-name>charsetencoding</filter-name> 24 <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> 25 <init-param> 26 <param-name>encoding</param-name> 27 <param-value>utf-8</param-value> 28 </init-param> 29 <init-param> 30 <param-name>forceencoding</param-name> 31 <param-value>true</param-value> 32 </init-param> 33 </filter> 34 <filter-mapping> 35 <filter-name>charsetencoding</filter-name> 36 <url-pattern>/*</url-pattern> 37 </filter-mapping> 38 <servlet> 39 <servlet-name>druidstatview</servlet-name> 40 <servlet-class>com.alibaba.druid.support.http.statviewservlet</servlet-class> 41 </servlet> 42 <servlet-mapping> 43 <servlet-name>druidstatview</servlet-name> 44 <url-pattern>/druid/*</url-pattern> 45 </servlet-mapping> 46 <servlet> 47 <servlet-name>springmvc</servlet-name> 48 <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> 49 <init-param> 50 <param-name>contextconfiglocation</param-name> 51 <param-value> 52 classpath:spring-mvc.xml 53 </param-value> 54 </init-param> 55 <load-on-startup>1</load-on-startup> 56 </servlet> 57 <servlet-mapping> 58 <servlet-name>springmvc</servlet-name> 59 <url-pattern>/</url-pattern> 60 </servlet-mapping> 61 62 63 <servlet> 64 <servlet-name>displaychart</servlet-name> 65 <servlet-class>org.jfree.chart.servlet.displaychart</servlet-class> 66 </servlet> 67 <servlet-mapping> 68 <servlet-name>displaychart</servlet-name> 69 <url-pattern>/chart</url-pattern> 70 </servlet-mapping> 71 </web-app>
2、pom.xml
1 <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"> 2 <modelversion>4.0.0</modelversion> 3 <groupid>tomm</groupid> 4 <artifactid>tomm</artifactid> 5 <version>0.0.1-snapshot</version> 6 <packaging>war</packaging> 7 <name>tomm</name> 8 <description/> 9 <properties> 10 <webversion>3.1</webversion> 11 <project.build.sourceencoding>utf-8</project.build.sourceencoding> 12 </properties> 13 14 <build> 15 <resources> 16 <resource> 17 <directory>src/main/java</directory> 18 <includes> 19 <include>**/*.xml </include> 20 </includes> 21 </resource> 22 <resource> 23 <directory>src/main/resources</directory> 24 <includes> 25 <include>**/*.* </include> 26 </includes> 27 </resource> 28 <resource> 29 <directory>src/main/webapp/web-inf</directory> 30 <includes> 31 <include>*.xml </include> 32 <include>*.properties </include> 33 </includes> 34 </resource> 35 </resources> 36 37 <plugins> 38 <plugin> 39 <artifactid>maven-compiler-plugin</artifactid> 40 <version>2.3.2</version> 41 <configuration> 42 <source>1.8</source> 43 <target>1.8</target> 44 </configuration> 45 </plugin> 46 <plugin> 47 <artifactid>maven-war-plugin</artifactid> 48 <version>2.6</version> 49 <configuration> 50 <failonmissingwebxml>false</failonmissingwebxml> 51 </configuration> 52 </plugin> 53 </plugins> 54 </build> 55 56 <dependencies> 57 <dependency> 58 <groupid>javax.servlet</groupid> 59 <artifactid>jstl</artifactid> 60 <version>1.2</version> 61 </dependency> 62 <dependency> 63 <groupid>javax.servlet</groupid> 64 <artifactid>javax.servlet-api</artifactid> 65 <version>3.1.0</version> 66 </dependency> 67 <dependency> 68 <groupid>org.springframework</groupid> 69 <artifactid>spring-aop</artifactid> 70 <version>4.1.0.release</version> 71 </dependency> 72 <dependency> 73 <groupid>org.springframework</groupid> 74 <artifactid>spring-aspects</artifactid> 75 <version>4.1.0.release</version> 76 </dependency> 77 <dependency> 78 <groupid>org.springframework</groupid> 79 <artifactid>spring-beans</artifactid> 80 <version>4.1.0.release</version> 81 </dependency> 82 <dependency> 83 <groupid>org.springframework</groupid> 84 <artifactid>spring-context</artifactid> 85 <version>4.1.0.release</version> 86 </dependency> 87 <dependency> 88 <groupid>org.springframework</groupid> 89 <artifactid>spring-context-support</artifactid> 90 <version>4.1.0.release</version> 91 </dependency> 92 <dependency> 93 <groupid>org.springframework</groupid> 94 <artifactid>spring-expression</artifactid> 95 <version>4.1.0.release</version> 96 </dependency> 97 <dependency> 98 <groupid>org.springframework</groupid> 99 <artifactid>spring-instrument</artifactid> 100 <version>4.1.0.release</version> 101 </dependency> 102 <dependency> 103 <groupid>org.springframework</groupid> 104 <artifactid>spring-instrument-tomcat</artifactid> 105 <version>4.1.0.release</version> 106 </dependency> 107 <dependency> 108 <groupid>org.springframework</groupid> 109 <artifactid>spring-core</artifactid> 110 <version>4.1.0.release</version> 111 </dependency> 112 <dependency> 113 <groupid>aopalliance</groupid> 114 <artifactid>aopalliance</artifactid> 115 <version>1.0</version> 116 </dependency> 117 <dependency> 118 <groupid>commons-pool</groupid> 119 <artifactid>commons-pool</artifactid> 120 <version>1.6</version> 121 </dependency> 122 <dependency> 123 <groupid>log4j</groupid> 124 <artifactid>log4j</artifactid> 125 <version>1.2.17</version> 126 </dependency> 127 <dependency> 128 <groupid>org.aspectj</groupid> 129 <artifactid>aspectjweaver</artifactid> 130 <version>1.8.2</version> 131 </dependency> 132 <dependency> 133 <groupid>org.springframework</groupid> 134 <artifactid>spring-web</artifactid> 135 <version>4.1.0.release</version> 136 </dependency> 137 <dependency> 138 <groupid>org.springframework</groupid> 139 <artifactid>spring-webmvc</artifactid> 140 <version>4.1.0.release</version> 141 </dependency> 142 <dependency> 143 <groupid>org.springframework</groupid> 144 <artifactid>spring-webmvc-portlet</artifactid> 145 <version>4.1.0.release</version> 146 </dependency> 147 <dependency> 148 <groupid>org.springframework</groupid> 149 <artifactid>spring-jms</artifactid> 150 <version>4.1.0.release</version> 151 </dependency> 152 <dependency> 153 <groupid>org.springframework</groupid> 154 <artifactid>spring-oxm</artifactid> 155 <version>4.1.0.release</version> 156 </dependency> 157 <dependency> 158 <groupid>org.springframework.security</groupid> 159 <artifactid>spring-security-web</artifactid> 160 <version>3.2.5.release</version> 161 </dependency> 162 <dependency> 163 <groupid>org.springframework.security</groupid> 164 <artifactid>spring-security-core</artifactid> 165 <version>3.2.5.release</version> 166 </dependency> 167 <dependency> 168 <groupid>org.springframework.security</groupid> 169 <artifactid>spring-security-acl</artifactid> 170 <version>3.2.5.release</version> 171 </dependency> 172 <dependency> 173 <groupid>org.springframework.security</groupid> 174 <artifactid>spring-security-aspects</artifactid> 175 <version>3.2.5.release</version> 176 </dependency> 177 <dependency> 178 <groupid>org.springframework.security</groupid> 179 <artifactid>spring-security-cas</artifactid> 180 <version>3.2.5.release</version> 181 </dependency> 182 <dependency> 183 <groupid>org.springframework.security</groupid> 184 <artifactid>spring-security-config</artifactid> 185 <version>3.2.5.release</version> 186 </dependency> 187 <dependency> 188 <groupid>org.springframework.security</groupid> 189 <artifactid>spring-security-crypto</artifactid> 190 <version>3.2.5.release</version> 191 </dependency> 192 <dependency> 193 <groupid>org.springframework.security</groupid> 194 <artifactid>spring-security-ldap</artifactid> 195 <version>3.2.5.release</version> 196 </dependency> 197 <dependency> 198 <groupid>org.springframework.security</groupid> 199 <artifactid>spring-security-openid</artifactid> 200 <version>3.2.5.release</version> 201 </dependency> 202 <dependency> 203 <groupid>org.springframework.security</groupid> 204 <artifactid>spring-security-remoting</artifactid> 205 <version>3.2.5.release</version> 206 </dependency> 207 <dependency> 208 <groupid>org.springframework.security</groupid> 209 <artifactid>spring-security-taglibs</artifactid> 210 <version>3.2.5.release</version> 211 </dependency> 212 <dependency> 213 <groupid>org.springframework.webflow</groupid> 214 <artifactid>spring-webflow</artifactid> 215 <version>2.4.0.release</version> 216 </dependency> 217 <dependency> 218 <groupid>org.springframework.webflow</groupid> 219 <artifactid>spring-binding</artifactid> 220 <version>2.4.0.release</version> 221 </dependency> 222 <dependency> 223 <groupid>org.springframework.webflow</groupid> 224 <artifactid>spring-js</artifactid> 225 <version>2.4.0.release</version> 226 </dependency> 227 <dependency> 228 <groupid>org.springframework.webflow</groupid> 229 <artifactid>spring-js-resources</artifactid> 230 <version>2.4.0.release</version> 231 </dependency> 232 <dependency> 233 <groupid>opensymphony</groupid> 234 <artifactid>ognl</artifactid> 235 <version>2.6.11</version> 236 </dependency> 237 <dependency> 238 <groupid>org.mybatis</groupid> 239 <artifactid>mybatis</artifactid> 240 <version>3.4.6</version> 241 </dependency> 242 <dependency> 243 <groupid>org.mybatis</groupid> 244 <artifactid>mybatis-spring</artifactid> 245 <version>1.3.2</version> 246 </dependency> 247 <dependency> 248 <groupid>mysql</groupid> 249 <artifactid>mysql-connector-java</artifactid> 250 <version>5.1.26</version> 251 </dependency> 252 <dependency> 253 <groupid>com.alibaba</groupid> 254 <artifactid>druid</artifactid> 255 <version>0.2.26</version> 256 </dependency> 257 258 <dependency> 259 <groupid>org.aspectj</groupid> 260 <artifactid>aspectjweaver</artifactid> 261 <version>1.7.3</version> 262 </dependency> 263 264 <dependency> 265 <groupid>commons-fileupload</groupid> 266 <artifactid>commons-fileupload</artifactid> 267 <version>1.3</version> 268 </dependency> 269 <dependency> 270 <groupid>log4j</groupid> 271 <artifactid>log4j</artifactid> 272 <version>1.2.17</version> 273 </dependency> 274 <dependency> 275 <groupid>com.alibaba</groupid> 276 <artifactid>fastjson</artifactid> 277 <version>1.2.4</version> 278 </dependency> 279 280 <dependency> 281 <groupid>junit</groupid> 282 <artifactid>junit</artifactid> 283 <version>4.11</version> 284 </dependency> 285 <dependency> 286 <groupid>commons-io</groupid> 287 <artifactid>commons-io</artifactid> 288 <version>2.5</version> 289 </dependency> 290 <dependency> 291 <groupid>commons-logging</groupid> 292 <artifactid>commons-logging</artifactid> 293 <version>1.2</version> 294 </dependency> 295 <dependency> 296 <groupid>jfree</groupid> 297 <artifactid>jcommon</artifactid> 298 <version>1.0.16</version> 299 </dependency> 300 <dependency> 301 <groupid>jfree</groupid> 302 <artifactid>jfreechart</artifactid> 303 <version>1.0.13</version> 304 </dependency> 305 </dependencies> 306 </project>
3、applicationcontext.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" 4 xmlns:p="http://www.springframework.org/schema/p" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:aop="http://www.springframework.org/schema/aop" 7 xmlns:tx="http://www.springframework.org/schema/tx" 8 xsi:schemalocation="http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/aop 13 http://www.springframework.org/schema/aop/spring-aop-4.1.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx-4.1.xsd "> 16 17 <!-- 扫描service、dao组件 --> 18 <context:component-scan base-package="com.service" /> 19 <context:component-scan base-package="com.dao" /> 20 21 <!-- 引入properties的文件 --> 22 <bean 23 class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> 24 <property name="locations"> 25 <list> 26 <value>classpath:*.properties</value> 27 </list> 28 </property> 29 </bean> 30 <!-- 阿里 druid数据库连接池 --> 31 <bean id="datasource" class="com.alibaba.druid.pool.druiddatasource" destroy-method="close"> 32 <!-- 数据库基本信息配置 --> 33 <property name="url" value="${url}" /> 34 <property name="username" value="${username}" /> 35 <property name="password" value="${password}" /> 36 <property name="driverclassname" value="${driverclassname}" /> 37 <property name="filters" value="${filters}" /> 38 <!-- 最大并发连接数 --> 39 <property name="maxactive" value="${maxactive}" /> 40 41 </bean> 42 43 44 <!-- 配置sqlsessionfactorybean --> 45 <bean id="sqlsessionfactory" class="org.mybatis.spring.sqlsessionfactorybean"> 46 <!-- 引用数据源组件 --> 47 <property name="datasource" ref="datasource" /> 48 <!-- 引用mybatis配置文件中的配置 --> 49 <property name="configlocation" value="classpath:mybatis-config.xml" /> 50 <!-- 配置sql映射文件信息 --> 51 <property name="mapperlocations"> 52 <list> 53 <value>classpath:com/dao/impl/*mapper.xml</value> 54 </list> 55 </property> 56 </bean> 57 <!-- dao接口所在包名,spring会自动查找其下的类 --> 58 <bean class="org.mybatis.spring.mapper.mapperscannerconfigurer"> 59 <property name="basepackage" value="com.dao" /> 60 <property name="sqlsessionfactorybeanname" value="sqlsessionfactory"></property> 61 </bean> 62 <!-- 配置注解事务 --> 63 <bean id="transactionmanager" 64 class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> 65 <property name="datasource" ref="datasource" /> 66 </bean> 67 <tx:annotation-driven transaction-manager="transactionmanager" /> 68 69 70 71 </beans>
4、db.properties
1 url:jdbc:mysql://主机名:3306/连接的数据名?useunicode=true&characterencoding=utf8 2 driverclassname:com.mysql.jdbc.driver 3 username:用户名 4 password:密码 5 6 7 filters:stat 8 9 maxactive:20 10 initialsize:1 11 maxwait:60000 12 minidle:10 13 maxidle:15 14
5、log4j.properties
1 log4j.rootlogger=debug,console,fil 2 #log4j.rootlogger=error,rolling_file 3 log4j.logger.cn.smbms.dao=debug 4 log4j.logger.com.ibatis=debug 5 log4j.logger.com.ibatis.common.jdbc.simpledatasource=debug 6 log4j.logger.com.ibatis.common.jdbc.scriptrunner=debug 7 log4j.logger.com.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debug 8 log4j.logger.java.sql.connection=debug 9 log4j.logger.java.sql.statement=debug 10 log4j.logger.java.sql.preparedstatement=debug 11 log4j.logger.java.sql.resultset=debug 12 log4j.logger.org.tuckey.web.filters.urlrewrite.urlrewritefilter=debug 13 14 ###################################################################################### 15 # console appender \u65e5\u5fd7\u5728\u63a7\u5236\u8f93\u51fa\u914d\u7f6e 16 ###################################################################################### 17 log4j.appender.console=org.apache.log4j.consoleappender 18 log4j.appender.threshold=error 19 log4j.appender.console.target=system.out 20 log4j.appender.console.layout=org.apache.log4j.patternlayout 21 log4j.appender.console.layout.conversionpattern= [%p] %d %c - %m%n 22 23 24 ###################################################################################### 25 # dailyrolling file \u6bcf\u5929\u4ea7\u751f\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u683c\u5f0f:log2009-09-11 26 ###################################################################################### 27 log4j.appender.file=org.apache.log4j.dailyrollingfileappender 28 log4j.appender.file.datepattern=yyyy-mm-dd 29 log4j.appender.file.file=log.log 30 log4j.appender.file.append=true 31 log4j.appender.file.threshold=error 32 log4j.appender.file.layout=org.apache.log4j.patternlayout 33 log4j.appender.file.layout.conversionpattern=%d{yyyy-m-d hh:mm:ss}%x[%5p](%f:%l) %m%n 34 35 36 37 log4j.logger.com.opensymphony.xwork2=error
6.log4j.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <loggers> 3 *<logger name="com.dao" level="debug"/>* 4 <root level="error"> 5 <appenderref ref="console"/> 6 </root> 7 <logger name="com.dao.impl" level="trace" additivity="false"> //为dao mapper所在的包,level为trace 8 <appenderref ref="console"/> 9 </logger> 10 </loggers>
7.mybatis-config.xml
1 <?xml version="1.0" encoding="utf-8" ?> 2 <!doctype configuration public "-//mybatis.org//dtd config 3.0//en" 3 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 4 <configuration> 5 <settings> 6 <setting name="lazyloadingenabled" value="false" /> 7 <setting name="cacheenabled" value="false" /> 8 <setting name="logimpl" value="stdout_logging" /> 9 </settings> 10 <!--类型别名 --> 11 <typealiases> 12 <typealias type="com.pojo.user" alias="user" /> 13 <!-- <typealias type="com.pojo.books" alias="book" />--> 14 </typealiases> 15 <!-- <typealiases> 16 <typealias type="com.pojo.bookuser" alias="buser" /> 17 <typealias type="com.pojo.book" alias="book"/> 18 </typealiases> --> 19 </configuration>
8.spring-mvc.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" 5 xmlns:p="http://www.springframework.org/schema/p" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemalocation=" 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/mvc 13 http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 14 <!-- 配置文件 <bean name="/index.html" class="com.web.helloaction"></bean> --> 15 16 <context:component-scan base-package="com.controller" /> 17 18 <mvc:annotation-driven> 19 <mvc:message-converters> 20 <bean class="org.springframework.http.converter.stringhttpmessageconverter"> 21 <property name="supportedmediatypes"> 22 <list> 23 <value>application/json;charset=utf-8</value> 24 </list> 25 </property> 26 </bean> 27 28 <bean 29 class="com.alibaba.fastjson.support.spring.fastjsonhttpmessageconverter"> 30 <property name="supportedmediatypes"> 31 <list> 32 <value>text/html;charset=utf-8</value> 33 <value>application/json</value> 34 </list> 35 </property> 36 </bean> 37 </mvc:message-converters> 38 </mvc:annotation-driven> 39 <!-- 映射到根目录下,文件引用静态资源时就加上static.. --> 40 <mvc:resources mapping="/static/**" location="web-inf/static/" /> 41 42 43 44 <!-- 完成视图的对应 --> 45 <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --> 46 <bean 47 class="org.springframework.web.servlet.view.internalresourceviewresolver"> 48 <property name="prefix" value="/web-inf/jsp/" /> 49 <property name="suffix" value=".jsp" /> 50 </bean> 51 52 <!-- 上传文件拦截,设置最大上传文件大小 10m=10*1024*1024(b)=10485760 bytes --> 53 <bean id="multipartresolver" 54 class="org.springframework.web.multipart.commons.commonsmultipartresolver"> 55 <property name="maxuploadsize" value="10485760 " /> <!-- 最大文件大小限制 --> 56 <property name="defaultencoding" value="utf-8" /> 57 58 </bean> 59 </beans>
推荐阅读
-
使用IDEA配置Maven搭建开发框架ssm教程
-
ssm整合总结(一)--第一步之使用maven搭建一个web项目
-
在eclipse中使用Maven分模块搭建SSM框架,创建jar、war、pom工程模块教学,项目的热部署,需要的可以留下邮箱,给大家发整理过的Maven笔记
-
使用myeclipse搭建SSM(springMVC+spring+mybatis)
-
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
-
SSM框架搭建项目,使用ajax的RESTfull风格
-
IDEA使用Maven搭建SSM框架
-
使用maven快速搭建SpringBoot的SSM项目
-
【java项目实战】一步步教你使用MyEclipse搭建java Web项目开发环境(一)
-
教你使用idea搭建ssm详细教程(Spring+Spring Mvc+Mybatis)