maven+druid+ssm配置

web.xml配置css

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.4"
 3          xmlns="http://java.sun.com/xml/ns/j2ee"
 4          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 6 
 7     <servlet>
 8         <servlet-name>springmvc</servlet-name>
 9         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
10 
11         <init-param>
12             <param-name>contextConfigLocation</param-name>
13             <param-value>classpath:config_ticket_ssm.xml</param-value>
14         </init-param>
15     </servlet>
16 
17     <servlet-mapping>
18         <servlet-name>springmvc</servlet-name>
19         <url-pattern>/</url-pattern>
20     </servlet-mapping>
21     
22     <!--中文亂碼處理-->
23     <filter>
24         <filter-name>characterEncodingFilter</filter-name>
25         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
26 
27         <init-param>
28             <param-name>encoding</param-name>
29             <param-value>UTF-8</param-value>
30         </init-param>
31     </filter>
32     <filter-mapping>
33         <filter-name>characterEncodingFilter</filter-name>
34         <url-pattern>/*</url-pattern> 35  </filter-mapping> 36 
37  <!--配置druid監控連接地址--> 38  <servlet> 39  <servlet-name>druidStaView</servlet-name> 40  <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> 41 
42  <init-param> 43  <param-name>resetEnable</param-name> 44  <param-value>true</param-value> 45  </init-param> 46  <init-param> 47  <param-name>loginUsername</param-name> 48  <param-value>jianhui</param-value> 49  </init-param> 50  <init-param> 51  <param-name>loginPassword</param-name> 52  <param-value>123</param-value> 53  </init-param> 54  </servlet> 55  <servlet-mapping> 56  <servlet-name>druidStaView</servlet-name> 57  <url-pattern>/druid/*</url-pattern> 58  </servlet-mapping> 59 
60  <!--對站點進行url統計:webStatFilter用於統計web-jdbd關聯監控的數據--> 61  <filter> 62  <filter-name>druidWebStatFilter</filter-name> 63  <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> 64 
65  <!--排除一些沒必要要的url--> 66  <init-param> 67  <param-name>namespace</param-name> 68  <param-value>/public/*,*.js,*.css,/druid*,*.jsp,*.swf</param-value> 69  </init-param> 70  <!--監控Session信息--> 71  <init-param> 72  <param-name>principalSessionName</param-name> 73  <param-value>sessionInfo</param-value> 74  </init-param> 75  <!--druid 0.2.7版本開始支持profile,配置profileEnable可以監控單個url調用的sql列表--> 76  <init-param> 77  <param-name>profileEnable</param-name> 78  <param-value>true</param-value> 79  </init-param> 80  </filter> 81  <filter-mapping> 82  <filter-name>druidWebStatFilter</filter-name> 83  <url-pattern>/*</url-pattern> 84  </filter-mapping> 85 
86 </web-app> 87
View Code

generatorConfig.xml配置java

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration  3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 <generatorConfiguration>
 6     <!--導入屬性配置 -->
 7     <properties resource="db.properties"></properties>
 8 
 9     <!--指定特定數據庫的jdbc驅動jar包的位置 -->
10     <classPathEntry location="${jdbc.driverLocation}"/>
11 
12     <context id="default" targetRuntime="MyBatis3">
13 
14         <!--&lt;!&ndash; optional,旨在建立class時,對註釋進行控制 &ndash;&gt;-->
15         <commentGenerator>
16             <property name="suppressDate" value="true"/>
17         </commentGenerator>
18 
19 
20         <!--jdbc的數據庫鏈接 -->
21         <jdbcConnection driverClass="${mysql.driver}" connectionURL="${mysql.url}" userId="${mysql.username}"
22                         password="${mysql.password}">
23         </jdbcConnection>
24 
25 
26         <!-- 非必需,類型處理器,在數據庫類型和java類型之間的轉換控制-->
27         <javaTypeResolver>
28             <property name="forceBigDecimals" value="false"/>
29         </javaTypeResolver>
30 
31         <!-- entity,用來生成含有主鍵key的類,記錄類 以及查詢Example類 32  targetPackage 指定生成的model生成所在的包名 33  targetProject 指定在該項目下所在的路徑 34         -->
35         <javaModelGenerator targetPackage="com.kehong.entity" targetProject="src/main/java">
36             <!-- 是否對model添加 構造函數 -->
37             <!--<property name="constructorBased" value="true"/>-->
38 
39             <!-- 是否容許子包,即targetPackage.schemaName.tableName -->
40             <property name="enableSubPackages" value="false"/>
41 
42             <!-- 創建的 entity對象是否 不可改變  即生成的entity對象不會有 setter方法,只有構造方法 -->
43             <!--<property name="immutable" value="true"/>-->
44 
45             <!-- 是否對類CHAR類型的列的數據進行trim操做 -->
46             <property name="trimStrings" value="true"/>
47         </javaModelGenerator>
48 
49         <!--Mapper映射文件生成所在的目錄 爲每個數據庫的表生成對應的SqlMap文件 -->
50         <!--<sqlMapGenerator targetPackage="mybatis-mapper" targetProject="src/main/resources">-->
51         <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
52             <property name="enableSubPackages" value="false"/>
53         </sqlMapGenerator>
54 
55 
56         <!-- 客戶端代碼,生成易於使用的針對Model對象和XML配置文件 的代碼 57                 type="ANNOTATEDMAPPER",生成Java entity 和基於註解的Mapper對象 58                 type="MIXEDMAPPER",生成基於註解的Java Model 和相應的Mapper對象 59                 type="XMLMAPPER",生成SQLMap XML文件和獨立的Mapper接口 60         -->
61         <!--Mapper.java所在的目錄-->
62         <javaClientGenerator targetPackage="com.kehong.dao" targetProject="src/main/java" type="MIXEDMAPPER">
63             <property name="enableSubPackages" value=""/>
64             <!--
65  定義Maper.java 源代碼中的ByExample() 方法的可視性,可選的值有: 66                     public; 67                     private; 68                     protected; 69                     default
70                     注意:若是 targetRuntime="MyBatis3",此參數被忽略 71              -->
72             <property name="exampleMethodVisibility" value=""/>
73             <!-- 方法名計數器 74               Important note: this property is ignored if the target runtime is MyBatis3. -->
75             <property name="methodNameCalculator" value=""/>
76 
77             <!-- 爲生成的接口添加父接口  -->
78             <property name="rootInterface" value=""/>
79 
80         </javaClientGenerator>
81 
82         <!--配置要自動生成的實體的表的名稱-->
83         <table tableName="emp" domainObjectName="Emp"
84                enableCountByExample="true" enableUpdateByExample="true"
85                enableDeleteByExample="true" enableSelectByExample="true"
86                selectByExampleQueryId="true">
87         </table>
88 
89         <table tableName="user" domainObjectName="User"
90                enableCountByExample="false" enableUpdateByExample="false"
91                enableDeleteByExample="false" enableSelectByExample="false"
92                selectByExampleQueryId="false">
93         </table>
94 
95     </context>
96 </generatorConfiguration>
View Code

properties配置mysql

 1 #配置數據庫驅動  2 mysql.driver = com.mysql.jdbc.Driver  3 jdbc.driverLocation=D:/develop/apache/apache-maven-3.5.4/repository/mysql/mysql-connector-java/5.1.26/mysql-connector-java-5.1.26.jar  4 
 5 #url  6 mysql.url = jdbc:mysql://localhost:3306/ticket_ssm
 7 #username  8 mysql.username = root  9 #password 10 mysql.password = admin 11 
12 #配置初始化大小、最小、最大 13 mysql.initialSize = 10
14 mysql.minIdle = 1
15 mysql.maxActive = 10
16 
17 # 配置獲取鏈接等待超時的時間 18 mysql.maxWait = 1000
19 
20 #開啓druid防火牆(防止Sql注入) 21 mysql.filters = wall
View Code

pom.xml配置web

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0"
 4          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 6 
 7 
 8   <modelVersion>4.0.0</modelVersion>
 9   <packaging>pom</packaging>
 10 
 11   <name>day50empsys</name>
 12   <!--<modules>-->
 13     <!--<module>../ticket_integration_ssm</module>-->
 14   <!--</modules>-->
 15   <groupId>com.kehong</groupId>
 16   <artifactId>day50empsys</artifactId>
 17   <version>1.0-SNAPSHOT</version>
 18   <properties>
 19     <file.encoding>UTF-8</file.encoding>
 20     <spring.version>5.0.8.RELEASE</spring.version>
 21   </properties>
 22 
 23   <dependencies>
 24     <!--文件上傳下載相關-->
 25     <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
 26     <dependency>
 27       <groupId>commons-fileupload</groupId>
 28       <artifactId>commons-fileupload</artifactId>
 29       <version>1.3.3</version>
 30     </dependency>
 31     <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
 32     <dependency>
 33       <groupId>commons-io</groupId>
 34       <artifactId>commons-io</artifactId>
 35       <version>2.6</version>
 36     </dependency>
 37     <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
 38     <dependency>
 39       <groupId>commons-logging</groupId>
 40       <artifactId>commons-logging</artifactId>
 41       <version>1.2</version>
 42     </dependency>
 43     <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
 44     <dependency>
 45       <groupId>com.alibaba</groupId>
 46       <artifactId>druid</artifactId>
 47       <version>1.1.10</version>
 48     </dependency>
 49     <!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
 50     <dependency>
 51       <groupId>javax.el</groupId>
 52       <artifactId>javax.el-api</artifactId>
 53       <version>3.0.1-b06</version>
 54     </dependency>
 55     <!-- https://mvnrepository.com/artifact/javax.inject/javax.inject -->
 56     <dependency>
 57       <groupId>javax.inject</groupId>
 58       <artifactId>javax.inject</artifactId>
 59       <version>1</version>
 60       <!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
 61     </dependency>
 62     <!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
 63     <dependency>
 64       <groupId>javax.servlet</groupId>
 65       <artifactId>jsp-api</artifactId>
 66       <version>2.0</version>
 67       <scope>provided</scope>
 68     </dependency>
 69 
 70     <!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
 71     <dependency>
 72       <groupId>javax.servlet.jsp.jstl</groupId>
 73       <artifactId>jstl</artifactId>
 74       <version>1.2</version>
 75     </dependency>
 76     <!-- https://mvnrepository.com/artifact/log4j/log4j -->
 77     <dependency>
 78       <groupId>log4j</groupId>
 79       <artifactId>log4j</artifactId>
 80       <version>1.2.17</version>
 81     </dependency>
 82     <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
 83     <dependency>
 84       <groupId>org.mybatis</groupId>
 85       <artifactId>mybatis</artifactId>
 86       <version>3.4.6</version>
 87     </dependency>
 88     <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
 89     <dependency>
 90       <groupId>org.mybatis</groupId>
 91       <artifactId>mybatis-spring</artifactId>
 92       <version>1.3.2</version>
 93     </dependency>
 94     <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
 95     <dependency>
 96       <groupId>mysql</groupId>
 97       <artifactId>mysql-connector-java</artifactId>
 98       <version>5.1.26</version>
 99     </dependency>
100     <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
101     <dependency>
102       <groupId>javax.servlet</groupId>
103       <artifactId>javax.servlet-api</artifactId>
104       <version>4.0.1</version>
105       <scope>provided</scope>
106     </dependency>
107 
108     <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
109     <dependency>
110       <groupId>org.springframework</groupId>
111       <artifactId>spring-core</artifactId>
112       <version>${spring.version}</version>
113     </dependency>
114     <dependency>
115       <groupId>org.springframework</groupId>
116       <artifactId>spring-context</artifactId>
117       <version>${spring.version}</version>
118     </dependency>
119 
120     <dependency>
121       <groupId>org.springframework</groupId>
122       <artifactId>spring-tx</artifactId>
123       <version>${spring.version}</version>
124     </dependency>
125 
126     <dependency>
127       <groupId>org.springframework</groupId>
128       <artifactId>spring-oxm</artifactId>
129       <version>${spring.version}</version>
130     </dependency>
131 
132     <dependency>
133       <groupId>org.springframework</groupId>
134       <artifactId>spring-aop</artifactId>
135       <version>${spring.version}</version>
136     </dependency>
137 
138     <dependency>
139       <groupId>org.springframework</groupId>
140       <artifactId>spring-jdbc</artifactId>
141       <version>${spring.version}</version>
142     </dependency>
143 
144     <dependency>
145       <groupId>org.springframework</groupId>
146       <artifactId>spring-web</artifactId>
147       <version>${spring.version}</version>
148     </dependency>
149 
150     <dependency>
151       <groupId>org.springframework</groupId>
152       <artifactId>spring-webmvc</artifactId>
153       <version>${spring.version}</version>
154     </dependency>
155 
156     <dependency>
157       <groupId>org.springframework</groupId>
158       <artifactId>spring-context-support</artifactId>
159       <version>${spring.version}</version>
160     </dependency>
161 
162     <dependency>
163       <groupId>org.springframework</groupId>
164       <artifactId>spring-test</artifactId>
165       <version>${spring.version}</version>
166     </dependency>
167     <dependency>
168       <groupId>org.springframework</groupId>
169       <artifactId>spring-orm</artifactId>
170       <version>${spring.version}</version>
171     </dependency>
172     <dependency>
173       <groupId>junit</groupId>
174       <artifactId>junit</artifactId>
175       <version>4.12</version>
176       <scope>test</scope>
177     </dependency>
178   </dependencies>
179 
180 
181 
182   <!--&lt;!&ndash;解決maven 找不到mapper映射文件:放在resoyrses裏面不用配置&ndash;&gt;-->
183   <build>
184     <!--<resources>-->
185       <!--<resource>-->
186         <!--<directory>mapper</directory>-->
187         <!--<includes>-->
188           <!--<include>**/*.properties</include>--> 189  <!--<include>**/*.xml</include>-->
190         <!--</includes>-->
191         <!--<filtering>false</filtering>-->
192       <!--</resource>-->
193 
194       <!--<resource>-->
195         <!--<directory>src/main/resources</directory>-->
196         <!--<includes>-->
197           <!--<include>**/*.properties</include>--> 198  <!--<include>**/*.xml</include>-->
199         <!--</includes>-->
200       <!--</resource>-->
201     <!--</resources>-->
202 
203   <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
204     <plugins>
205       <plugin>
206         <groupId>org.mybatis.generator</groupId>
207         <artifactId>mybatis-generator-maven-plugin</artifactId>
208         <version>1.3.2</version>
209         <configuration>
210           <verbose>true</verbose>
211           <overwrite>true</overwrite>
212         </configuration>
213       </plugin>
214     </plugins>
215   </pluginManagement>
216 </build>
217 
218 </project>
View Code

config.xml配置spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--開啓掃描-->
    <context:component-scan base-package="com.kehong.controller,com.kehong.util,com.kehong.service"/>
    <!--開啓註解-->
    <mvc:annotation-driven/>
    <!--配置視圖-->
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <!--鏈接池路徑-->
    <context:property-placeholder location="classpath:db.properties" file-encoding="UTF-8"/>
    <!--配置鏈接池-->
    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${mysql.driver}"/>
        <property name="url" value="${mysql.url}"/>
        <property name="username" value="${mysql.username}"/>
        <property name="password" value="${mysql.password}"/>
        <property name="initialSize" value="${mysql.initialSize}"/>
        <property name="minIdle" value="${mysql.minIdle}"/>
        <property name="maxActive" value="${mysql.maxActive}"/>
        <property name="maxWait" value="${mysql.maxWait}"/>
        <property name="filters" value="${mysql.filters}"/>

        <!--經過proxyFilters屬性配置監控統計攔截的filters用於統計sql-->

        <property name="proxyFilters">
            <list>

            </list>
        </property>
    </bean>
    <!--監控統計過濾器配置-->
    <bean id="statFilter" class="com.alibaba.druid.filter.stat.StatFilter">
        <!--開啓合併sql-->
        <property name="mergeSql" value="true"/>
        <!--開啓慢查詢,200毫秒-->
        <property name="slowSqlMillis" value="200"/>
        <!--將執行緩慢的sql打印到日誌文件中-->
        <property name="logSlowSql" value="true"/>
    </bean>


    <!--配置監控統計過濾器的日誌處理器-->
    <bean id="log4jFilter" class="com.alibaba.druid.filter.logging.Log4jFilter">
        <property name="resultSetLogEnabled" value="false" />
        <property name="statementExecutableSqlLogEnable" value="true" />
    </bean>

    <!--配置sqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--數據源-->
        <property name="dataSource" ref="druidDataSource"/>
        <!--配置映射文件-->
        <property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
    </bean>

    <!--使用動態實現接口-->
    <bean id="scannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <!--mybatis接口地址-->
        <property name="basePackage" value="com/kehong/dao"/>
    </bean>

    <!--攔截器-->
    <mvc:interceptors>
        <mvc:interceptor>
            <!--要攔截的路徑-->
            <mvc:mapping path="/**"/>
            <!--剔除不能被攔截的路徑:路徑必須和請求的路徑的格式規範一致-->
            <mvc:exclude-mapping path="/login"/>
            <mvc:exclude-mapping path="/toUserLogin"/>
            <mvc:exclude-mapping path="/userLoginMsg"/>
            <mvc:exclude-mapping path="/error"/>
            <mvc:exclude-mapping path="//static/**"/>
            <mvc:exclude-mapping path="/logout"/>
            <!--配置攔截器-->
            <bean class="com.kehong.interceptor.UserLoginInterceptorEctends"/>
        </mvc:interceptor>
    </mvc:interceptors>

    <!--訪問靜態文件-->
    <mvc:resources mapping="/static/**" location="/,/WEB-INF/"  />
</beans>
View Code

 

 

 

建立maven時注意:sql

相關文章
相關標籤/搜索