一、Maven本地仓库的pom.xml配置
(全部是mysql数据库)
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>com.super</groupId> 4 <artifactId>mavenlayui</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 <packaging>war</packaging> 7 <properties> 8 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 9 <log4j.version>1.2.17</log4j.version> 10 <spring.version>4.3.9.RELEASE</spring.version> 11 <mybatis.version>3.2.2</mybatis.version> 12 </properties> 13 <dependencies> 14 <dependency> 15 <groupId>log4j</groupId> 16 <artifactId>log4j</artifactId> 17 <version>${log4j.version}</version> 18 </dependency> 19 <!-- spring --> 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-aop</artifactId> 23 <version>${spring.version}</version> 24 </dependency> 25 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-aspects</artifactId> 29 <version>${spring.version}</version> 30 </dependency> 31 32 33 <dependency> 34 <groupId>org.springframework</groupId> 35 <artifactId>spring-beans</artifactId> 36 <version>${spring.version}</version> 37 </dependency> 38 39 <dependency> 40 <groupId>org.springframework</groupId> 41 <artifactId>spring-context</artifactId> 42 <version>${spring.version}</version> 43 </dependency> 44 45 <dependency> 46 <groupId>org.springframework</groupId> 47 <artifactId>spring-context-support</artifactId> 48 <version>${spring.version}</version> 49 </dependency> 50 51 <dependency> 52 <groupId>org.springframework</groupId> 53 <artifactId>spring-expression</artifactId> 54 <version>${spring.version}</version> 55 </dependency> 56 57 <dependency> 58 <groupId>org.springframework</groupId> 59 <artifactId>spring-instrument</artifactId> 60 <version>${spring.version}</version> 61 </dependency> 62 63 <dependency> 64 <groupId>org.springframework</groupId> 65 <artifactId>spring-instrument-tomcat</artifactId> 66 <version>${spring.version}</version> 67 </dependency> 68 69 <dependency> 70 <groupId>org.springframework</groupId> 71 <artifactId>spring-jdbc</artifactId> 72 <version>${spring.version}</version> 73 </dependency> 74 75 <dependency> 76 <groupId>org.springframework</groupId> 77 <artifactId>spring-jms</artifactId> 78 <version>${spring.version}</version> 79 </dependency> 80 81 <dependency> 82 <groupId>org.springframework</groupId> 83 <artifactId>spring-messaging</artifactId> 84 <version>${spring.version}</version> 85 </dependency> 86 87 <dependency> 88 <groupId>org.springframework</groupId> 89 <artifactId>spring-orm</artifactId> 90 <version>${spring.version}</version> 91 </dependency> 92 93 <dependency> 94 <groupId>org.springframework</groupId> 95 <artifactId>spring-oxm</artifactId> 96 <version>${spring.version}</version> 97 </dependency> 98 99 <dependency> 100 <groupId>org.springframework</groupId> 101 <artifactId>spring-test</artifactId> 102 <version>${spring.version}</version> 103 </dependency> 104 105 <dependency> 106 <groupId>org.springframework</groupId> 107 <artifactId>spring-tx</artifactId> 108 <version>${spring.version}</version> 109 </dependency> 110 111 <dependency> 112 <groupId>org.springframework</groupId> 113 <artifactId>spring-web</artifactId> 114 <version>${spring.version}</version> 115 </dependency> 116 117 <dependency> 118 <groupId>org.springframework</groupId> 119 <artifactId>spring-webmvc</artifactId> 120 <version>${spring.version}</version> 121 </dependency> 122 123 <dependency> 124 <groupId>org.springframework</groupId> 125 <artifactId>spring-webmvc-portlet</artifactId> 126 <version>${spring.version}</version> 127 </dependency> 128 129 130 <dependency> 131 <groupId>org.springframework</groupId> 132 <artifactId>spring-websocket</artifactId> 133 <version>${spring.version}</version> 134 </dependency> 135 <!-- mybatis --> 136 137 <dependency> 138 <groupId>org.mybatis</groupId> 139 <artifactId>mybatis</artifactId> 140 <version>${mybatis.version}</version> 141 </dependency> 142 143 144 <dependency> 145 <groupId>org.mybatis</groupId> 146 <artifactId>mybatis-spring</artifactId> 147 <version>1.2.2</version> 148 </dependency> 149 <!-- 上传下载 --> 150 <dependency> 151 <groupId>commons-fileupload</groupId> 152 <artifactId>commons-fileupload</artifactId> 153 <version>1.3.1</version> 154 </dependency> 155 <dependency> 156 <groupId>commons-io</groupId> 157 <artifactId>commons-io</artifactId> 158 <version>2.2</version> 159 </dependency> 160 <dependency> 161 <groupId>taglibs</groupId> 162 <artifactId>standard</artifactId> 163 <version>1.1.2</version> 164 </dependency> 165 166 <dependency> 167 <groupId>javax</groupId> 168 <artifactId>javaee-api</artifactId> 169 <version>8.0</version> 170 <scope>provided</scope> 171 </dependency> 172 173 174 <dependency> 175 <groupId>javax</groupId> 176 <artifactId>javaee-web-api</artifactId> 177 <version>8.0</version> 178 <scope>provided</scope> 179 </dependency> 180 <dependency> 181 <groupId>net.sf.json-lib</groupId> 182 <artifactId>json-lib</artifactId> 183 <version>2.1</version> 184 <classifier>jdk15</classifier> 185 </dependency> 186 <dependency> 187 <groupId>javax.servlet</groupId> 188 <artifactId>jstl</artifactId> 189 <version>1.2</version> 190 </dependency> 191 <dependency> 192 <groupId>mysql</groupId> 193 <artifactId>mysql-connector-java</artifactId> 194 <version>5.1.41</version> 195 </dependency> 196 </dependencies> 197 198 <build> 199 <!-- 项目名称 --> 200 <finalName>SupermarketManager</finalName> 201 <defaultGoal>package</defaultGoal> 202 <plugins> 203 <plugin> 204 <groupId>org.apache.tomcat.maven</groupId> 205 <artifactId>tomcat7-maven-plugin</artifactId> 206 <version>2.2</version> 207 <configuration> 208 <url>http://localhost:8080/manager/text</url> 209 <server>tomcat8</server> 210 <path>/SupermarketManager</path> 211 </configuration> 212 </plugin> 213 </plugins> 214 </build> 215 </project>
二、springmvc.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" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 7 http://www.springframework.org/schema/context 8 http://www.springframework.org/schema/context/spring-context-4.3.xsd 9 http://www.springframework.org/schema/mvc 10 http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 11 http://www.springframework.org/schema/tx 12 http://www.springframework.org/schema/tx/spring-tx-4.3.xsd 13 "> 14 <context:component-scan base-package="com.supermanager.*"/> 15 <mvc:annotation-driven/> 16 <mvc:default-servlet-handler/> 17 18 <!-- json中文乱码 --> 19 <!-- <mvc:annotation-driven> 20 <mvc:message-converters> 21 <bean class="org.springframework.http.converter.StringHttpMessageConverter"> 22 <property name="supporteMediaTypes"> 23 <list> 24 <value>application/json;charset=UTF-8</value> 25 </list> 26 </property> 27 </bean> 28 </mvc:message-converters> 29 </mvc:annotation-driven> 30 --> 31 <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 32 <property name="prefix" value="/"></property> 33 <property name="suffix" value=".jsp"></property> 34 </bean> 35 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 36 <property name="defaultEncoding" value="UTF-8" /> 37 <property name="maxUploadSize" value="-1" /> 38 </bean> 39 40 </beans>
三、spring-mybatis.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" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:tx="http://www.springframework.org/schema/tx" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 7 http://www.springframework.org/schema/context 8 http://www.springframework.org/schema/context/spring-context-4.3.xsd 9 http://www.springframework.org/schema/tx 10 http://www.springframework.org/schema/tx/spring-tx-4.3.xsd 11 "> 12 <!-- 自动扫描包 --> 13 <context:component-scan base-package="com.supermanager.*" /> 14 15 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 16 <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> 17 <property name="url" value="jdbc:mysql://localhost:3306/supermanager"></property> 18 <property name="username" value="root"></property> 19 <property name="password" value="123456"></property> 20 </bean> 21 <!-- mybatis配置 --> 22 <bean class="org.mybatis.spring.SqlSessionFactoryBean"> 23 <property name="dataSource" ref="dataSource"></property> 24 <property name="typeAliasesPackage" value="com.supermanager.entity"></property> 25 26 </bean> 27 <!-- 映射配置器 --> 28 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 29 <property name="basePackage" value="com.supermanager.dao"></property> 30 </bean> 31 <!-- 事务管理器 --> 32 <bean id="transactionManager" 33 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 34 <property name="dataSource" ref="dataSource"></property> 35 </bean> 36 37 <!-- 开启事务注解 --> 38 <tx:annotation-driven /> 39 40 </beans>
四、log4j.xml配置
1 log4j.rootLogger =INFO,DB 2 3 log4j.logger.sm=INFO,smm 4 log4j.additivity.smm=false 5 log4j.appender.smm = org.apache.log4j.jdbc.JDBCAppender 6 log4j.appender.smm.Driver =com.mysql.jdbc.Driver 7 log4j.appender.smm.URL =jdbc:mysql://localhost:3306/supermanager 8 log4j.appender.smm.User =root 9 log4j.appender.smm.Password =123456 10 log4j.appender.smm.Sql = INSERT INTO LOGS(ltid,ltime,userId,lresult,lremark) VALUES(‘%X{ltid}‘,‘%d{yyyy-MM-dd HH:mm:ss}‘,‘%X{userId}‘,‘%X{lresult}‘,‘%X{lremark}‘)