00062 Upgrade JAVA to 1.8; Servlet 3.0
							parent
							
								
									a16e41c2c8
								
							
						
					
					
						commit
						46714a429a
					
				|  | @ -8,6 +8,8 @@ | |||
| 
 | ||||
| 使用的技术与版本号 | ||||
| <ol> | ||||
|  <li>JDK (1.8.0_40)</li> | ||||
|  <li>Servlet (3.1.0)</li> | ||||
|  <li>Spring (4.1.6.RELEASE)</li> | ||||
|  <li>Spring Security (4.0.1.RELEASE)</li> | ||||
|  <li>spring-security-oauth2 (2.0.7.RELEASE)</li> | ||||
|  |  | |||
							
								
								
									
										21
									
								
								pom.xml
								
								
								
								
							
							
						
						
									
										21
									
								
								pom.xml
								
								
								
								
							|  | @ -23,9 +23,9 @@ | |||
| 
 | ||||
|         <!--jdbc execute sql config--> | ||||
|         <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver> | ||||
|         <jdbc.url>jdbc:mysql://localhost:3306/wdcy_test?autoReconnect=true&useUnicode=true&characterEncoding=utf8</jdbc.url> | ||||
|         <jdbc.user>wdcy</jdbc.user> | ||||
|         <jdbc.pass>wdcy</jdbc.pass> | ||||
|         <jdbc.url>jdbc:mysql://localhost:3306/oauth2_test?autoReconnect=true&useUnicode=true&characterEncoding=utf8</jdbc.url> | ||||
|         <jdbc.user>andaily</jdbc.user> | ||||
|         <jdbc.pass>andaily</jdbc.pass> | ||||
|         <!--if do not use execute sql, change the value to true--> | ||||
|         <jdbc.execute.skip>false</jdbc.execute.skip> | ||||
|         <test.skip>false</test.skip> | ||||
|  | @ -47,19 +47,20 @@ | |||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>2.3.2</version> | ||||
|                 <version>3.2</version> | ||||
|                 <configuration> | ||||
|                     <encoding>utf-8</encoding> | ||||
|                     <source>1.7</source> | ||||
|                     <target>1.7</target> | ||||
|                     <encoding>UTF-8</encoding> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
| 
 | ||||
|             <plugin> | ||||
|                 <artifactId>maven-war-plugin</artifactId> | ||||
|                 <version>2.0.2</version> | ||||
|                 <version>2.6</version> | ||||
|                 <configuration> | ||||
|                     <warSourceExcludes>*/classes/spring-oauth-server.properties</warSourceExcludes> | ||||
|                     <packagingExcludes>*/classes/spring-oauth-server.properties</packagingExcludes> | ||||
|                     <archive> | ||||
|                         <manifestEntries> | ||||
|                             <Implementation-BuildNumber> | ||||
|  | @ -168,8 +169,8 @@ | |||
|         <!-- provided dependency --> | ||||
|         <dependency> | ||||
|             <groupId>javax.servlet</groupId> | ||||
|             <artifactId>servlet-api</artifactId> | ||||
|             <version>2.4</version> | ||||
|             <artifactId>javax.servlet-api</artifactId> | ||||
|             <version>3.1.0</version> | ||||
|             <scope>provided</scope> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|  |  | |||
|  | @ -1,16 +1,17 @@ | |||
| package com.monkeyk.sos.domain; | ||||
| 
 | ||||
| import com.monkeyk.sos.infrastructure.DateUtils; | ||||
| import com.monkeyk.sos.domain.shared.GuidGenerator; | ||||
| import com.monkeyk.sos.infrastructure.DateUtils; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| import java.util.Date; | ||||
| import java.time.LocalDateTime; | ||||
| 
 | ||||
| /** | ||||
|  * @author Shengzhao Li | ||||
|  */ | ||||
| public abstract class AbstractDomain implements Serializable { | ||||
| 
 | ||||
|     private static final long serialVersionUID = 6569365774429340632L; | ||||
|     /** | ||||
|      * Database id | ||||
|      */ | ||||
|  | @ -25,7 +26,7 @@ public abstract class AbstractDomain implements Serializable { | |||
|     /** | ||||
|      * The domain create time. | ||||
|      */ | ||||
|     protected Date createTime = DateUtils.now(); | ||||
|     protected LocalDateTime createTime = DateUtils.now(); | ||||
| 
 | ||||
|     public AbstractDomain() { | ||||
|     } | ||||
|  | @ -55,13 +56,10 @@ public abstract class AbstractDomain implements Serializable { | |||
|         this.guid = guid; | ||||
|     } | ||||
| 
 | ||||
|     public Date createTime() { | ||||
|     public LocalDateTime createTime() { | ||||
|         return createTime; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isNewly() { | ||||
|         return id == 0; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean equals(Object o) { | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ package com.monkeyk.sos.domain.oauth; | |||
| import com.monkeyk.sos.infrastructure.DateUtils; | ||||
| 
 | ||||
| import java.io.Serializable; | ||||
| import java.util.Date; | ||||
| import java.time.LocalDateTime; | ||||
| 
 | ||||
| /** | ||||
|  * @author Shengzhao Li | ||||
|  | @ -13,7 +13,7 @@ public class OauthClientDetails implements Serializable { | |||
| 
 | ||||
|     private static final long serialVersionUID = -6947822646185526939L; | ||||
| 
 | ||||
|     private Date createTime = DateUtils.now(); | ||||
|     private LocalDateTime createTime = DateUtils.now(); | ||||
|     private boolean archived = false; | ||||
| 
 | ||||
|     private String clientId; | ||||
|  | @ -87,11 +87,11 @@ public class OauthClientDetails implements Serializable { | |||
|         return trusted; | ||||
|     } | ||||
| 
 | ||||
|     public Date createTime() { | ||||
|     public LocalDateTime createTime() { | ||||
|         return createTime; | ||||
|     } | ||||
| 
 | ||||
|     public OauthClientDetails createTime(Date createTime) { | ||||
|     public OauthClientDetails createTime(LocalDateTime createTime) { | ||||
|         this.createTime = createTime; | ||||
|         return this; | ||||
|     } | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ package com.monkeyk.sos.domain.user; | |||
| 
 | ||||
| import com.monkeyk.sos.domain.AbstractDomain; | ||||
| 
 | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
|  | @ -100,7 +101,7 @@ public class User extends AbstractDomain { | |||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     public User createTime(Date createTime) { | ||||
|     public User createTime(LocalDateTime createTime) { | ||||
|         this.createTime = createTime; | ||||
|         return this; | ||||
|     } | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| package com.monkeyk.sos.infrastructure; | ||||
| 
 | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.format.DateTimeFormatter; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| /** | ||||
|  | @ -18,27 +19,26 @@ public abstract class DateUtils { | |||
|     private DateUtils() { | ||||
|     } | ||||
| 
 | ||||
|     public static Date now() { | ||||
|         return new Date(); | ||||
|     public static LocalDateTime now() { | ||||
|         return LocalDateTime.now(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     //Create new  SimpleDateFormat
 | ||||
|     private static SimpleDateFormat newDateFormat(String pattern) { | ||||
|         return new SimpleDateFormat(pattern, Locale.SIMPLIFIED_CHINESE); | ||||
|     public static String toDateTime(LocalDateTime date) { | ||||
|         return toDateTime(date, DEFAULT_DATE_TIME_FORMAT); | ||||
|     } | ||||
| 
 | ||||
|     public static String toDateTime(Date date) { | ||||
|         return toDateText(date, DEFAULT_DATE_TIME_FORMAT); | ||||
|     public static String toDateTime(LocalDateTime dateTime, String pattern) { | ||||
|         return dateTime.format(DateTimeFormatter.ofPattern(pattern, Locale.SIMPLIFIED_CHINESE)); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public static String toDateText(Date date, String pattern) { | ||||
| 
 | ||||
|     public static String toDateText(LocalDate date, String pattern) { | ||||
|         if (date == null || pattern == null) { | ||||
|             return null; | ||||
|         } | ||||
|         SimpleDateFormat dateFormat = newDateFormat(pattern); | ||||
|         return dateFormat.format(date); | ||||
|         return date.format(DateTimeFormatter.ofPattern(pattern, Locale.SIMPLIFIED_CHINESE)); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ import org.springframework.jdbc.core.RowMapper; | |||
| 
 | ||||
| import java.sql.ResultSet; | ||||
| import java.sql.SQLException; | ||||
| import java.time.ZoneId; | ||||
| 
 | ||||
| /** | ||||
|  * 2015/11/16 | ||||
|  | @ -45,7 +46,7 @@ public class OauthClientDetailsRowMapper implements RowMapper<OauthClientDetails | |||
|         clientDetails.refreshTokenValidity(getInteger(rs, "refresh_token_validity")); | ||||
| 
 | ||||
|         clientDetails.additionalInformation(rs.getString("additional_information")); | ||||
|         clientDetails.createTime(rs.getTimestamp("create_time")); | ||||
|         clientDetails.createTime(rs.getTimestamp("create_time").toLocalDateTime()); | ||||
|         clientDetails.archived(rs.getBoolean("archived")); | ||||
| 
 | ||||
|         clientDetails.trusted(rs.getBoolean("trusted")); | ||||
|  |  | |||
|  | @ -35,7 +35,6 @@ import java.util.List; | |||
| public class UserRepositoryJdbc implements UserRepository { | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     private static UserRowMapper userRowMapper = new UserRowMapper(); | ||||
| 
 | ||||
|     @Autowired | ||||
|  | @ -77,7 +76,7 @@ public class UserRepositoryJdbc implements UserRepository { | |||
|                 ps.setString(1, user.guid()); | ||||
|                 ps.setBoolean(2, user.archived()); | ||||
| 
 | ||||
|                 ps.setTimestamp(3, new Timestamp(user.createTime().getTime())); | ||||
|                 ps.setTimestamp(3, Timestamp.valueOf(user.createTime())); | ||||
|                 ps.setString(4, user.email()); | ||||
| 
 | ||||
|                 ps.setString(5, user.password()); | ||||
|  |  | |||
|  | @ -36,7 +36,7 @@ public class UserRowMapper implements RowMapper<User> { | |||
|         user.guid(rs.getString("guid")); | ||||
| 
 | ||||
|         user.archived(rs.getBoolean("archived")); | ||||
|         user.createTime(rs.getTimestamp("create_time")); | ||||
|         user.createTime(rs.getTimestamp("create_time").toLocalDateTime()); | ||||
| 
 | ||||
|         user.email(rs.getString("email")); | ||||
|         user.phone(rs.getString("phone")); | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ | |||
| <web-app xmlns="http://java.sun.com/xml/ns/javaee" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||||
| 		  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||||
|          version="2.5"> | ||||
| 		  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||||
|          version="3.0"> | ||||
| 
 | ||||
|     <display-name>spring-oauth-server</display-name> | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,47 @@ | |||
| /* | ||||
|  * Copyright (c) 2015 MONKEYK Information Technology Co. Ltd | ||||
|  * www.monkeyk.com | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * This software is the confidential and proprietary information of | ||||
|  * MONKEYK Information Technology Co. Ltd ("Confidential Information"). | ||||
|  * You shall not disclose such Confidential Information and shall use | ||||
|  * it only in accordance with the terms of the license agreement you | ||||
|  * entered into with MONKEYK Information Technology Co. Ltd. | ||||
|  */ | ||||
| package com.monkeyk.sos.infrastructure; | ||||
| 
 | ||||
| import org.testng.annotations.Test; | ||||
| 
 | ||||
| import java.sql.Timestamp; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| 
 | ||||
| import static org.testng.Assert.assertEquals; | ||||
| import static org.testng.Assert.assertNotNull; | ||||
| 
 | ||||
| /* | ||||
|   * @author Shengzhao Li | ||||
|   */ | ||||
| public class DateUtilsTest { | ||||
| 
 | ||||
| 
 | ||||
|     @Test | ||||
|     public void convert() { | ||||
| 
 | ||||
|         LocalDateTime localDateTime = LocalDateTime.of(2015, 4, 3, 12, 30, 22); | ||||
| 
 | ||||
|         final LocalDate localDate = localDateTime.toLocalDate(); | ||||
|         System.out.println(localDate); | ||||
| 
 | ||||
|         final Timestamp timestamp = Timestamp.valueOf(localDateTime); | ||||
|         assertNotNull(timestamp); | ||||
|         System.out.println(timestamp); | ||||
| 
 | ||||
| 
 | ||||
|         final String text = DateUtils.toDateTime(localDateTime); | ||||
|         assertEquals(text,"2015-04-03 12:30:22"); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	 Li Shengzhao
						Li Shengzhao