首页 > 其他分享 >【Spring】Spring5+Spring5MVC+Mybatis+H2の環境構築(高)

【Spring】Spring5+Spring5MVC+Mybatis+H2の環境構築(高)

时间:2023-11-24 10:55:56浏览次数:39  
标签:Spring5MVC H2 Spring springframework version spring org com log4j

参考URL:

(初)https://www.cnblogs.com/lnsylt/p/10258457.html

(中)https://www.cnblogs.com/lnsylt/p/10315455.html

①pom.xml

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <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">
  3 
  4     <modelVersion>4.0.0</modelVersion>
  5     <groupId>co.com.sj</groupId>
  6     <artifactId>Spring5Spring5mvcMybatisH2</artifactId>
  7     <packaging>war</packaging>
  8     <version>1.0</version>
  9     <name>Spring5Spring5mvcMybatisH2 Maven Webapp</name>
 10     <url>http://maven.apache.org</url>
 11     <properties>
 12         <!-- エンコード(UTF8)を指定 -->
 13         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 14         <!-- 変数定義 開始 -->
 15         <junit.version>4.12</junit.version>
 16         <spring.version>5.1.4.RELEASE</spring.version>
 17         <mybatis.version>3.4.6</mybatis.version>
 18         <mybatis.spring.version>1.3.2</mybatis.spring.version>
 19         <mysql5.version>5.1.38</mysql5.version>
 20         <mysql8.version>8.0.13</mysql8.version>
 21         <log4j.version>1.2.17</log4j.version>
 22         <alibaba.fastjson.version>1.2.54</alibaba.fastjson.version>
 23         <alibaba.druid.version>1.1.12</alibaba.druid.version>
 24         <aspectjweaver.version>1.9.2</aspectjweaver.version>
 25         <slf4j.version>1.7.7</slf4j.version>
 26         <jackson.version>2.9.8</jackson.version>
 27         <jstl.version>1.2</jstl.version>
 28         <servlet-api.version>2.5</servlet-api.version>
 29         <jsp-api.version>2.0</jsp-api.version>
 30         <asm.version>7.0</asm.version>
 31         <!-- 変数定義 終了 -->
 32     </properties>
 33     <dependencies>
 34         <!-- junit -->
 35         <dependency>
 36             <groupId>junit</groupId>
 37             <artifactId>junit</artifactId>
 38             <version>${junit.version}</version>
 39             <scope>test</scope>
 40         </dependency>
 41 
 42         <!-- JSPのlib -->
 43         <dependency>
 44             <groupId>jstl</groupId>
 45             <artifactId>jstl</artifactId>
 46             <version>${jstl.version}</version>
 47         </dependency>
 48         <dependency>
 49             <groupId>javax.servlet</groupId>
 50             <artifactId>servlet-api</artifactId>
 51             <version>${servlet-api.version}</version>
 52             <scope>provided</scope>
 53         </dependency>
 54         <dependency>
 55             <groupId>javax.servlet</groupId>
 56             <artifactId>jsp-api</artifactId>
 57             <version>${jsp-api.version}</version>
 58             <scope>provided</scope>
 59         </dependency>
 60 
 61         <!-- commonsのlib -->
 62         <dependency>
 63             <groupId>commons-io</groupId>
 64             <artifactId>commons-io</artifactId>
 65             <version>2.6</version>
 66         </dependency>
 67         <!-- ファイルアップロードのLib -->
 68         <dependency>
 69             <groupId>commons-fileupload</groupId>
 70             <artifactId>commons-fileupload</artifactId>
 71             <version>1.4</version>
 72         </dependency>
 73         <dependency>
 74             <groupId>commons-logging</groupId>
 75             <artifactId>commons-logging</artifactId>
 76             <version>1.2</version>
 77         </dependency>
 78         <dependency>
 79             <groupId>org.apache.commons</groupId>
 80             <artifactId>commons-email</artifactId>
 81             <version>1.5</version>
 82         </dependency>
 83         <dependency>
 84             <groupId>org.apache.commons</groupId>
 85             <artifactId>commons-lang3</artifactId>
 86             <version>3.8.1</version>
 87         </dependency>
 88         <dependency>
 89             <groupId>org.apache.commons</groupId>
 90             <artifactId>commons-collections4</artifactId>
 91             <version>4.2</version>
 92         </dependency>
 93         <dependency>
 94             <groupId>commons-dbcp</groupId>
 95             <artifactId>commons-dbcp</artifactId>
 96             <version>1.4</version>
 97         </dependency>
 98 
 99         <!-- ASM -->
100         <dependency>
101             <groupId>org.ow2.asm</groupId>
102             <artifactId>asm</artifactId>
103             <version>${asm.version}</version>
104         </dependency>
105         <dependency>
106             <groupId>org.ow2.asm</groupId>
107             <artifactId>asm-commons</artifactId>
108             <version>${asm.version}</version>
109         </dependency>
110         <dependency>
111             <groupId>org.ow2.asm</groupId>
112             <artifactId>asm-util</artifactId>
113             <version>${asm.version}</version>
114         </dependency>
115         <dependency>
116             <groupId>org.ow2.asm</groupId>
117             <artifactId>asm-tree</artifactId>
118             <version>${asm.version}</version>
119         </dependency>
120         <dependency>
121             <groupId>org.ow2.asm</groupId>
122             <artifactId>asm-analysis</artifactId>
123             <version>${asm.version}</version>
124         </dependency>
125 
126         <!-- Springのlib -->
127         <dependency>
128             <groupId>org.springframework</groupId>
129             <artifactId>spring-aop</artifactId>
130             <version>${spring.version}</version>
131         </dependency>
132         <dependency>
133             <groupId>org.springframework</groupId>
134             <artifactId>spring-aspects</artifactId>
135             <version>${spring.version}</version>
136         </dependency>
137         <dependency>
138             <groupId>org.springframework</groupId>
139             <artifactId>spring-beans</artifactId>
140             <version>${spring.version}</version>
141         </dependency>
142         <dependency>
143             <groupId>org.springframework</groupId>
144             <artifactId>spring-context</artifactId>
145             <version>${spring.version}</version>
146         </dependency>
147         <dependency>
148             <groupId>org.springframework</groupId>
149             <artifactId>spring-context-indexer</artifactId>
150             <version>${spring.version}</version>
151             <scope>optional</scope>
152         </dependency>
153         <dependency>
154             <groupId>org.springframework</groupId>
155             <artifactId>spring-context-support</artifactId>
156             <version>${spring.version}</version>
157         </dependency>
158         <dependency>
159             <groupId>org.springframework</groupId>
160             <artifactId>spring-core</artifactId>
161             <version>${spring.version}</version>
162         </dependency>
163         <dependency>
164             <groupId>org.springframework</groupId>
165             <artifactId>spring-expression</artifactId>
166             <version>${spring.version}</version>
167         </dependency>
168         <dependency>
169             <groupId>org.springframework</groupId>
170             <artifactId>spring-instrument</artifactId>
171             <version>${spring.version}</version>
172         </dependency>
173         <dependency>
174             <groupId>org.springframework</groupId>
175             <artifactId>spring-jcl</artifactId>
176             <version>${spring.version}</version>
177         </dependency>
178         <dependency>
179             <groupId>org.springframework</groupId>
180             <artifactId>spring-jdbc</artifactId>
181             <version>${spring.version}</version>
182         </dependency>
183         <dependency>
184             <groupId>org.springframework</groupId>
185             <artifactId>spring-jms</artifactId>
186             <version>${spring.version}</version>
187         </dependency>
188         <dependency>
189             <groupId>org.springframework</groupId>
190             <artifactId>spring-messaging</artifactId>
191             <version>${spring.version}</version>
192         </dependency>
193         <dependency>
194             <groupId>org.springframework</groupId>
195             <artifactId>spring-orm</artifactId>
196             <version>${spring.version}</version>
197         </dependency>
198         <dependency>
199             <groupId>org.springframework</groupId>
200             <artifactId>spring-oxm</artifactId>
201             <version>${spring.version}</version>
202         </dependency>
203         <dependency>
204             <groupId>org.springframework</groupId>
205             <artifactId>spring-test</artifactId>
206             <version>${spring.version}</version>
207         </dependency>
208         <dependency>
209             <groupId>org.springframework</groupId>
210             <artifactId>spring-tx</artifactId>
211             <version>${spring.version}</version>
212         </dependency>
213         <dependency>
214             <groupId>org.springframework</groupId>
215             <artifactId>spring-web</artifactId>
216             <version>${spring.version}</version>
217         </dependency>
218         <dependency>
219             <groupId>org.springframework</groupId>
220             <artifactId>spring-webflux</artifactId>
221             <version>${spring.version}</version>
222         </dependency>
223         <dependency>
224             <groupId>org.springframework</groupId>
225             <artifactId>spring-webmvc</artifactId>
226             <version>${spring.version}</version>
227         </dependency>
228         <dependency>
229             <groupId>org.springframework</groupId>
230             <artifactId>spring-websocket</artifactId>
231             <version>${spring.version}</version>
232         </dependency>
233         <!-- Spring Source -->
234         <!-- <dependency> <groupId>org.jboss.javassist</groupId> <artifactId>com.springsource.javassist</artifactId> <version>3.15.0.GA</version> </dependency> -->
235 
236         <!-- JBOSSのjavassistのlib -->
237         <dependency>
238             <groupId>org.javassist</groupId>
239             <artifactId>javassist</artifactId>
240             <version>3.24.1-GA</version>
241         </dependency>
242 
243         <!-- aspectj (AOP) -->
244         <dependency>
245             <groupId>org.aspectj</groupId>
246             <artifactId>aspectjweaver</artifactId>
247             <version>${aspectjweaver.version}</version>
248         </dependency>
249 
250         <!-- mybatisのlib -->
251         <dependency>
252             <groupId>org.mybatis</groupId>
253             <artifactId>mybatis</artifactId>
254             <version>${mybatis.version}</version>
255         </dependency>
256         <dependency>
257             <groupId>org.mybatis</groupId>
258             <artifactId>mybatis-spring</artifactId>
259             <version>${mybatis.spring.version}</version>
260         </dependency>
261         <dependency>
262             <groupId>org.mybatis.caches</groupId>
263             <artifactId>mybatis-ehcache</artifactId>
264             <version>1.0.3</version>
265         </dependency>
266 
267         <!-- hibernateのLib -->
268         <dependency>
269             <groupId>org.hibernate</groupId>
270             <artifactId>hibernate-core</artifactId>
271             <version>5.4.0.Final</version>
272         </dependency>
273 
274         <!-- mysqlのlib(Ver.5とVer.8) -->
275         <dependency>
276             <groupId>mysql</groupId>
277             <artifactId>mysql-connector-java</artifactId>
278             <version>5.1.47</version>
279         </dependency>
280         <!-- <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql8.version}</version> </dependency> -->
281 
282         <!-- H2のlib -->
283         <dependency>
284             <groupId>com.h2database</groupId>
285             <artifactId>h2</artifactId>
286             <version>1.4.197</version>
287         </dependency>
288 
289         <!-- JSONのlib -->
290         <dependency>
291             <groupId>com.fasterxml.jackson.core</groupId>
292             <artifactId>jackson-core</artifactId>
293             <version>${jackson.version}</version>
294         </dependency>
295         <dependency>
296             <groupId>com.fasterxml.jackson.core</groupId>
297             <artifactId>jackson-annotations</artifactId>
298             <version>${jackson.version}</version>
299         </dependency>
300         <dependency>
301             <groupId>com.fasterxml.jackson.core</groupId>
302             <artifactId>jackson-databind</artifactId>
303             <version>${jackson.version}</version>
304         </dependency>
305 
306         <!-- ログ出力のlib -->
307         <!-- 方法一 -->
308         <dependency>
309             <groupId>org.slf4j</groupId>
310             <artifactId>slf4j-log4j12</artifactId>
311             <version>1.7.25</version>
312         </dependency>
313         <!-- 方法二 -->
314         <!-- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> -->
315 
316         <!-- Other -->
317         <dependency>
318             <groupId>taglibs</groupId>
319             <artifactId>standard</artifactId>
320             <version>1.1.2</version>
321         </dependency>
322         <dependency>
323             <groupId>com.mchange</groupId>
324             <artifactId>c3p0</artifactId>
325             <version>0.9.5.2</version>
326         </dependency>
327         <dependency>
328             <groupId>javax.annotation</groupId>
329             <artifactId>javax.annotation-api</artifactId>
330             <version>1.3.2</version>
331         </dependency>
332         <dependency>
333             <groupId>net.sf.ehcache</groupId>
334             <artifactId>ehcache-core</artifactId>
335             <version>2.6.11</version>
336         </dependency>
337 
338         <!-- import can not -->
339         <!-- <dependency> <groupId>org.aopalliance</groupId> <artifactId>com.springsource.org.aopalliance</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>net.sourceforge.cglib</groupId> <artifactId>com.springsource.net.sf.cglib</artifactId> <version>2.2.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>com.springsource.org.aspectj.weaver</artifactId> <version>1.6.0</version> </dependency> -->
340         <!-- import can not -->
341 
342         <!-- OGNL -->
343         <dependency>
344             <groupId>ognl</groupId>
345             <artifactId>ognl</artifactId>
346             <version>3.2.10</version>
347         </dependency>
348 
349         <!-- alibabaのlib -->
350         <dependency>
351             <groupId>com.alibaba</groupId>
352             <artifactId>fastjson</artifactId>
353             <version>${alibaba.fastjson.version}</version>
354         </dependency>
355         <dependency>
356             <groupId>com.alibaba</groupId>
357             <artifactId>druid</artifactId>
358             <version>${alibaba.druid.version}</version>
359         </dependency>
360 
361     </dependencies>
362     <build>
363         <finalName>SSM</finalName>
364     </build>
365 </project>
pom.xml

②web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
 3                      http://www.springmodules.org/schema/cache/springmodules-cache.xsd
 4                      http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd" 
 5                      xmlns="http://java.sun.com/xml/ns/javaee" 
 6                      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
 7                      id="WebApp_ID" version="3.0">
 8 
 9     <display-name>Spring5Spring5mvcMybatisH2</display-name>
10     <welcome-file-list>
11         <welcome-file>index.jsp</welcome-file>
12     </welcome-file-list>
13 
14     <!-- Spring -->
15     <!--/WEB-INF/applicationContext.xml を導入(BeanのContainer) -->
16     <context-param>
17         <param-name>contextConfigLocation</param-name>
18         <!-- 拡張XMLを指定する「;」で区切り -->
19         <param-value>classpath*:applicationContext.xml</param-value>
20     </context-param>
21 
22     <!-- <context-param> <param-name>spring.profiles.active</param-name> <param-value>dev</param-value> </context-param> <context-param> <param-name>spring.profiles.default</param-name> <param-value>dev</param-value> </context-param> <context-param> <param-name>spring.liveBeansView.mbeanDomain</param-name> <param-value>dev</param-value> </context-param> -->
23 
24     <!-- 文字化け -->
25     <filter>
26         <filter-name>characterEncodingFilter</filter-name>
27         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
28         <init-param>
29             <param-name>encoding</param-name>
30             <param-value>UTF-8</param-value>
31         </init-param>
32         <init-param>
33             <param-name>forceEncoding</param-name>
34             <param-value>true</param-value>
35         </init-param>
36     </filter>
37     <filter-mapping>
38         <filter-name>characterEncodingFilter</filter-name>
39         <url-pattern>/*</url-pattern>
40     </filter-mapping>
41     
42     <!--リスナー -->
43     <listener>
44         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
45     </listener>
46 
47     <!-- Spring MVC -->
48     <servlet>
49         <servlet-name>springmvc</servlet-name>
50         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
51         <init-param>
52             <param-name>contextConfigLocation</param-name>
53             <!-- 拡張XMLを指定する「;」で区切り -->
54             <param-value>classpath*:springmvc.xml</param-value>
55         </init-param>
56         <load-on-startup>1</load-on-startup>
57         <async-supported>true</async-supported>
58     </servlet>
59     <servlet-mapping>
60         <servlet-name>springmvc</servlet-name>
61         <!-- 請求URLに「*.do」を指定する、「"/"」を指定すると、すべての内容をインターセプトする(intercept) -->
62         <url-pattern>*.do</url-pattern>
63     </servlet-mapping>
64     
65 </web-app>
web.xml

③applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans
 4         http://www.springframework.org/schema/beans/spring-beans.xsd
 5         http://www.springframework.org/schema/aop
 6         http://www.springframework.org/schema/aop/spring-aop.xsd
 7         http://www.springframework.org/schema/context
 8         http://www.springframework.org/schema/context/spring-context.xsd
 9         http://www.springframework.org/schema/jee
10         http://www.springframework.org/schema/jee/spring-jee.xsd
11         http://www.springframework.org/schema/tx
12         http://www.springframework.org/schema/tx/spring-tx.xsd">
13 
14     <!-- Beanのパス(サブパスを含む)を検索 -->
15     <context:component-scan base-package="com.java.service"></context:component-scan>
16     <context:component-scan base-package="com.java.serviceimpl"></context:component-scan>
17     
18     <!-- 「@Controller」を除外の方法 -->
19     <!-- 
20     <context:component-scan base-package="com.java.*">        
21         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
22     </context:component-scan>
23     -->
24     
25     <!-- DB配置ファイル -->
26     <context:property-placeholder location="classpath*:jdbc.properties" />
27 
28     <!-- データベースの接続設定 -->
29     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
30         <property name="driverClassName" value="${jdbc.driverClassName}" />
31         <property name="url" value="${jdbc.url}" />
32         <property name="username" value="${jdbc.username}" />
33         <property name="password" value="${jdbc.password}" />
34     </bean>
35 
36     <!-- SQLセッション -->
37     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
38         <!-- データソース -->
39         <property name="dataSource" ref="dataSource"></property>
40         <!-- mybatisの業務XML -->
41         <property name="mapperLocations" value="classpath:com/java/mappers/*.xml"></property>
42         <!-- mybatisのプロパティXML -->
43         <property name="configLocation" value="classpath:mybatis-config.xml"></property>
44     </bean>
45     
46     <!-- mybatisとspringを紐付く -->
47     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
48         <!-- DAOと業務XMLを紐付く -->
49         <property name="basePackage" value="com.java.dao"></property>
50         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
51     </bean>
52 </beans>
applicationContext.xml

④springmvc.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans" 
 3     xmlns:p="http://www.springframework.org/schema/p" 
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5     xmlns:aop="http://www.springframework.org/schema/aop" 
 6     xmlns:tx="http://www.springframework.org/schema/tx" 
 7     xmlns:jee="http://www.springframework.org/schema/jee" 
 8     xmlns:context="http://www.springframework.org/schema/context" 
 9     xmlns:mvc="http://www.springframework.org/schema/mvc"
10     xsi:schemaLocation="http://www.springframework.org/schema/beans
11                             http://www.springframework.org/schema/beans/spring-beans.xsd
12                             http://www.springframework.org/schema/aop
13                             http://www.springframework.org/schema/aop/spring-aop.xsd
14                             http://www.springframework.org/schema/context
15                             http://www.springframework.org/schema/context/spring-context.xsd
16                             http://www.springframework.org/schema/jee
17                             http://www.springframework.org/schema/jee/spring-jee.xsd
18                             http://www.springframework.org/schema/mvc
19                             http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
20                             http://www.springframework.org/schema/tx
21                             http://www.springframework.org/schema/tx/spring-tx.xsd">
22 
23     <context:component-scan base-package="com.java.*">
24         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
25     </context:component-scan>
26 
27     <mvc:annotation-driven />
28 
29     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
30         <property name="prefix" value="/" />
31         <property name="suffix" value=".jsp" />
32     </bean>
33 
34     <!-- ファイルアップロード -->
35     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
36         <property name="defaultEncoding" value="utf-8" />
37         <property name="maxUploadSize" value="10485760000" />
38         <property name="maxInMemorySize" value="40960" />
39     </bean>
40     
41 </beans>
springmvc.xml

⑤mybatis-config.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-config.dtd">
 3 <configuration>
 4     <settings>
 5         <setting name="logImpl" value="LOG4J" />
 6         <setting name="lazyLoadingEnabled" value="true" />
 7         <setting name="aggressiveLazyLoading" value="false" />
 8         <setting name="cacheEnabled" value="true" />
 9     </settings>
10     <typeAliases>
11         <!-- Entity対象の設定(このような設定すれば、user.xmlの中身にパスの使用しない) -->
12         <package name="com.java.entity"></package>
13     </typeAliases>
14 </configuration>
mybatis-config.xml

⑥log4j.properties

### 初期化 ###
log4j.rootLogger=INFO,STDOUT, ROOT,D,E

### コントロールのログを出力 ###
log4j.appender.ROOT=org.apache.log4j.ConsoleAppender
log4j.appender.ROOT.Target=System.out
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.layout.ConversionPattern=%-5p - %m%n

### レベル級「INFO」以上のログを出力 ###
log4j.appender.STDOUT=org.apache.log4j.RollingFileAppender
log4j.appender.STDOUT.File=C:/Users/LNSYLT/Tools/pleiades2018/log/ssm.log
log4j.appender.STDOUT.Append=true
log4j.appender.STDOUT.MaxFileSize=1MB
log4j.appender.STDOUT.MaxBackupIndex=20
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5.12p [%C{2}][%F][%M(%L)] - %m%n

### レベル級「DEBUG」以上のログを出力 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File =C:/Users/LNSYLT/Tools/pleiades2018/log/debug.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

### レベル級「ERROR」以上のログを出力 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =C:/Users/LNSYLT/Tools/pleiades2018/log/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
log4j.properties

⑦jdbc.properties

jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:tcp://localhost/~/sjdb
jdbc.username=ssm
jdbc.password=pass
jdbc.properties

⑧UserController.java

 1 package com.java.controller;
 2 
 3 import javax.annotation.Resource;
 4 import javax.servlet.http.HttpServletRequest;
 5 import javax.servlet.http.HttpSession;
 6 
 7 import org.apache.log4j.Logger;
 8 import org.springframework.stereotype.Controller;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 
11 import com.java.entity.UserEntity;
12 import com.java.service.UserService;
13 
14 @Controller
15 @RequestMapping("/user")
16 public class UserController {
17 
18     private static final Logger logger = Logger.getLogger(UserController.class);
19 
20     @Resource
21     private UserService userService;
22 
23     @RequestMapping("/login")
24     public String login(HttpServletRequest request) {
25         logger.info("登録");
26 
27         return "/jsp/common/OK";
28     }
29 
30     @RequestMapping("/register")
31     public String register(HttpServletRequest request) {
32         logger.info("新規");
33         String username = request.getParameter("n_username");
34         String password = request.getParameter("n_password");
35         UserEntity user = new UserEntity(username, password);
36         
37         request.setAttribute("resultMsg","新規成功!");
38         HttpSession session=request.getSession();
39         session.setAttribute("resultObj", user);
40 
41         if (userService.insert(user)) {
42 
43             return "/jsp/common/OK";
44         } else {
45             return "/jsp/common/NG";
46 
47         }
48 
49     }
50 }
View Code

⑨UserDao.java

 1 package com.java.dao;
 2 
 3 import com.java.entity.UserEntity;
 4 
 5 public interface UserDao {
 6     /**
 7      * 検索
 8      * 
 9      * @param user
10      * @return
11      */
12     public UserEntity select(UserEntity user);
13 
14     /**
15      * 挿入
16      * 
17      * @param user
18      * @return
19      */
20     public UserEntity insert(UserEntity user);
21 }
UserDao.java

 ⑩UserEntity.java

 1 package com.java.entity;
 2 
 3 public class UserEntity {
 4     
 5     private String id;
 6 
 7     private String username;
 8 
 9     private String password;
10 
11     public UserEntity() {
12         super();
13     }
14 
15     public UserEntity(String username, String password) {
16         super();
17         this.id = java.util.UUID.randomUUID().toString();
18         this.username = username;
19         this.password = password;
20     }
21 
22     public String getId() {
23         return id;
24     }
25 
26     public void setId(String id) {
27         this.id = id;
28     }
29 
30     public String getUsername() {
31         return username;
32     }
33 
34     public void setUsername(String username) {
35         this.username = username;
36     }
37 
38     public String getPassword() {
39         return password;
40     }
41 
42     public void setPassword(String password) {
43         this.password = password;
44     }
45 
46     @Override
47     public String toString() {
48         return "User [id=" + id + ", username=" + username + ", password=" + password + "]";
49     }
50 }
UserEntity.java

⑪user.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE mapper  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 3   
 4 <mapper namespace="com.java.dao.UserDao">
 5     
 6     <resultMap type="com.java.entity.UserEntity" id="UserResult">
 7         <!-- UUID -->
 8         <id property="id" column="id"></id>
 9         <!-- ユーザ名 -->
10         <result property="username" column="username"></result>
11         <!-- パスワード -->
12         <result property="password" column="password"></result>
13     </resultMap>
14     
15     <!-- 検索 -->
16     <select id="select" parameterType="com.java.entity.UserEntity" resultMap="UserResult">
17         select * from user where username=#{username} and password=#{password}
18     </select>
19     
20     <!-- 挿入 -->
21     <insert id="insert" parameterType="com.java.entity.UserEntity">
22         insert into user (id,username,password) values(#{id},#{username},#{password})
23     </insert>
24 
25 </mapper>  
user.xml

⑫UserService.java

 1 package com.java.service;
 2 
 3 import com.java.entity.UserEntity;
 4 
 5 public interface UserService {
 6 
 7     /**
 8      * 検索
 9      * 
10      * @param user
11      * @return
12      */
13     public UserEntity select(UserEntity user);
14 
15     /**
16      * 挿入
17      * 
18      * @param user
19      * @return
20      */
21     public UserEntity insert(UserEntity user);
22 }
UserService.java

⑬UserServiceImpl.java

 1 package com.java.serviceimpl;
 2 
 3 import javax.annotation.Resource;
 4 
 5 import org.springframework.stereotype.Service;
 6 
 7 import com.java.dao.UserDao;
 8 import com.java.entity.UserEntity;
 9 import com.java.service.UserService;
10 
11 @Service("userService")
12 public class UserServiceImpl implements UserService {
13 
14     @Resource
15     private UserDao userDao;
16 
17     public UserEntity select(UserEntity user) {
18         return userDao.select(user);
19     }
20 
21     public UserEntity insert(UserEntity user) {
22         return userDao.insert(user);
23     }
24 
25 }
UserServiceImpl.java

⑭index.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <%
 3     String path = pageContext.getServletContext().getContextPath();
 4     String libsrc = path + "/src/jquery-easyui";
 5 %>
 6 <!DOCTYPE html>
 7 <html>
 8 <head>
 9 <meta charset="UTF-8">
10 <title>Insert title here</title>
11 <link rel="stylesheet" type="text/css" href="<%=libsrc%>/themes/default/easyui.css">
12 <link rel="stylesheet" type="text/css" href="<%=libsrc%>/themes/icon.css">
13 <link rel="stylesheet" type="text/css" href="<%=libsrc%>/demo.css">
14 <script type="text/javascript" src="<%=libsrc%>/jquery.min.js"></script>
15 <script type="text/javascript" src="<%=libsrc%>/jquery.easyui.min.js"></script>
16 <script type="text/javascript">
17     $(function(){
18         $('#id_btn_login').click(function(){
19             $.messager.alert('title','登録','info',function(){
20                 window.location.href='<%=path%>/user/login.do';
21                 window.location.href='<%=path%>/jsp/login.jsp';
22             });
23         });
24         $('#id_btn_register').click(function(){
25             $.messager.alert('title','新規','info',function(){
26                 //window.location.href='<%=path%>/user/register.do';
27                 window.location.href='<%=path%>/jsp/register.jsp';
28             });
29         });
30     });
31 </script>
32 </head>
33 <body>
34     <div>
35         <H1>Index Page</H1>
36     </div>
37     <div>
38         <button id="id_btn_login">登録</button>
39     </div>
40     <div>
41         <button id="id_btn_register">新規</button>
42     </div>
43 </body>
44 </html>
index.jsp

⑮login.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <!DOCTYPE html>
 3 <html>
 4 <head>
 5 <meta charset="UTF-8">
 6 <title>Insert title here</title>
 7 <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/src/jquery-easyui/themes/default/easyui.css">
 8 <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/src/jquery-easyui/themes/icon.css">
 9 <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/src/jquery-easyui/demo.css">
10 <script type="text/javascript" src="${pageContext.request.contextPath}/src/jquery-easyui/jquery.min.js"></script>
11 <script type="text/javascript" src="${pageContext.request.contextPath}/src/jquery-easyui/jquery.easyui.min.js"></script>
12 <script type="text/html">
13     $(function(){
14         alert('sss1111');
15         $.messager.alert('title','ログイン画面','info',function(){
16             alert('ssss');
17         });
18     });
19 </script>
20 </head>
21 <body>
22     <div>
23         <h1>ログイン画面</h1>
24     </div>
25     
26 </body>
27 </html>
login.jsp

⑯register.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <!DOCTYPE html>
 3 <html>
 4 <head>
 5 <meta charset="UTF-8">
 6 <title>Insert title here</title>
 7 </head>
 8 <body>
 9     <div>
10         <h1>新規画面</h1>
11     </div>
12     <div>
13         <form action="<%=pageContext.getServletContext().getContextPath()%>/user/register.do" method="post">
14             <table>
15                 <tr>
16                     <td>ユーザ名:</td>
17                     <td><input type="text" id="id_txt_username" name="n_username"/></td>
18                 </tr>
19                 <tr>
20                     <td>ユーザ名:</td>
21                     <td><input type="password" id="id_txt_password" name="n_password"/></td>
22                 </tr>
23                 <tr>
24                     <td scope="2">
25                         <input type="submit" name="submit" value="Submit"/>
26                     </td>
27                 </tr>
28             </table>
29         </form>
30     </div>
31 </body>
32 </html>
register.jsp

⑰NG.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <!DOCTYPE html>
 3 <html>
 4 <head>
 5 <meta charset="UTF-8">
 6 <title>Insert title here</title>
 7 </head>
 8 <body>
 9     <h2>新規失敗!!!!!</h2>
10 </body>
11 </html>
NG.jsp

⑱OK.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <!DOCTYPE html>
 3 <html>
 4 <head>
 5 <meta charset="UTF-8">
 6 <title>Insert title here</title>
 7 </head>
 8 <body>
 9     <h1>新規成功!!!!</h1>
10     <font color="red">${resultMsg}</font>
11     <font color="red">${resultObj.username}</font>
12 </body>
13 </html>
OK.jsp

 

标签:Spring5MVC,H2,Spring,springframework,version,spring,org,com,log4j
From: https://www.cnblogs.com/lnsylt/p/10316091.html

相关文章

  • 【H2】データベース設定
    (1)ユーザの作成(パスワードも追加)createusersysjpassword'sysj';(2)ユーザの役割をセットalterusersysjadmintrue;(3)ユーザを検索select*fromINFORMATION_SCHEMA.USERS;(4)データベースの削除DROPTABLEIFEXISTSTEST;(5)テーブルの作成CREATETABLETEST(IDINTPRIMARYKE......
  • java实现大文件的分片上传与下载(springboot+vue3)
    1.1项目背景对于超大文件上传我们可能遇到以下问题•大文件直接上传,占用过多内存,可能导致内存溢出甚至系统崩溃•受网络环境影响,可能导致传输中断,只能重新传输•传输时间长,用户无法知道传输进度,用户体验不佳1.2项目目标对于上述问题,我们需要对文件做分片传输。分片传输就是......
  • 分享SpringBoot2 仿B站高性能前端+后端项目
    点击下崽:分享SpringBoot2仿B站高性能前端+后端项目  提取码:cj2sSpringBoot2仿B站高性能前端+后端项目在当今的互联网时期,视频分享平台如B站等备受欢送。它们的胜利很大水平上归功于其高性能的前端和后端技术。在本文中,我们将讨论如何运用SpringBoot2框架和相关技术来创立一个相......
  • 解决Spring Cloud Gateway路由问题 503
    近期在配置SpringCloudGateway进行路由时,遇到了一些问题,经过一番排查和调试,最终解决了问题。在这篇博客中,我将分享遇到的问题、解决过程以及最终的解决方案。问题背景我使用SpringCloudGateway构建微服务架构时,希望通过网关实现请求的路由。然而,在配置路由规则时,我遇到......
  • springboot定时任务线程池配置拾遗--利用配置类进行配置
    springboot定时任务线程池配置拾遗--利用配置类进行配置目录springboot定时任务线程池配置拾遗--利用配置类进行配置1springboot自动装配1.1通过TaskSchedulingProperties获取yaml参数1.2TaskSchedulingAutoConfiguration自动配置类根据TaskSchedulingProperties的配置装配线......
  • Ossclient无法自动装配和包aliyun-oss-spring-boot-starter导入错误
    无法导包 aliyun-oss-spring-boot-starter 解决办法:把 aliyun-oss-spring-boot-starter换成即可<dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>2.8.3......
  • springboot 集成swagger3.0 并开启权限认证
    1.POM文件只需要引入一个依赖即可  2.swagger配置文件如下注意:要添加“@EnableWebMvc"注解,详细代码如下:@Configuration@EnableWebMvcpublicclassSwaggerConfig{@Value("${swagger.enabled}")booleanenabled;@BeanpublicDocketdocket(){r......
  • Springboot文件上传代码笔记
    1.在src下创建filter包,包内Class名UploadFilterpackagecom.gd.filter;importorg.apache.catalina.servlet4preview.http.HttpServletRequest;importjavax.servlet.*;importjavax.servlet.annotation.WebFilter;importjavax.servlet.http.HttpServletResponse;impor......
  • Spring_2023_11_23_3 Spring整合mybatis----注解方式
    Spring整合mybatis----注解方式2023-11-2317:18:29星期四a) 依赖的引入<!--spring基础依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><ver......
  • Spring
    Overview<ulclass="tree"> <li>  <detailsopen>   <summary>Giantplanets</summary>   <ul>    <li>     <details>      <summary>Gasgiants</summary>      <......