Browse Source

jfinal 4.0

James 6 years ago
parent
commit
9b1094e894

+ 5 - 0
src/main/java/com/jfinal/core/converter/Converters.java

@@ -179,6 +179,11 @@ public class Converters {
 		// mysql type: timestamp, datetime
 		@Override
 		public java.sql.Timestamp convert(String s) throws ParseException {
+			// 支持 html5 的 datetime 组件,格式为:2019-01-23T11:22
+			if(s.indexOf(' ') == -1 && s.indexOf('T') != -1 && s.indexOf('-') != -1 && s.indexOf(':') != -1) {
+			    s = s.replace("T", " ");
+			}
+			
 			if (timeStampWithoutSecPatternLen == s.length()) {
 				s = s + ":00";
 			}

+ 5 - 1
src/main/java/com/jfinal/core/converter/TypeConverter.java

@@ -101,10 +101,14 @@ public class TypeConverter {
 	/**
 	 * 将 String 数据转换为指定的类型
 	 * @param type 需要转换成为的数据类型
-	 * @param s 被转换的 String 类型数据,注意: s 参数不接受 null 值,否则会抛出异常
+	 * @param s 被转换的 String 类型数据
 	 * @return 转换成功的数据
 	 */
 	public final Object convert(Class<?> type, String s) throws ParseException {
+		if (s == null) {
+			return null;
+		}
+		
 		// mysql type: varchar, char, enum, set, text, tinytext, mediumtext, longtext
 		if (type == String.class) {
 			return ("".equals(s) ? null : s);	// 用户在表单域中没有输入内容时将提交过来 "", 因为没有输入,所以要转成 null.