mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
fix json date format
This commit is contained in:
@@ -48,7 +48,9 @@ public class Register extends HttpServlet {
|
|||||||
checkPhoneNumber(request.getParameter("phone")),
|
checkPhoneNumber(request.getParameter("phone")),
|
||||||
wechat
|
wechat
|
||||||
);
|
);
|
||||||
Redirect.message(response, result.equals("Register_Success") ? 1 : 0, result);
|
boolean isSuccess = result.equals("Register_Success");
|
||||||
|
if (isSuccess) request.getSession().invalidate();
|
||||||
|
Redirect.message(response, isSuccess ? 1 : 0, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class TicketSubmit extends HttpServlet {
|
|||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.save(t);
|
s.save(t);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
|
request.getSession().invalidate();
|
||||||
return new Response(Response.ResponseCode.OK, t);
|
return new Response(Response.ResponseCode.OK, t);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.*;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
@@ -9,7 +8,7 @@ import org.hibernate.service.ServiceRegistry;
|
|||||||
|
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.text.DateFormat;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
@@ -20,7 +19,10 @@ import java.text.DateFormat;
|
|||||||
public class SQLCore {
|
public class SQLCore {
|
||||||
|
|
||||||
public static DataSource ds;
|
public static DataSource ds;
|
||||||
public static Gson gson = new GsonBuilder().setDateFormat(DateFormat.LONG, DateFormat.LONG).create();
|
public static Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
||||||
|
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||||
|
.create();
|
||||||
public static SessionFactory sf;
|
public static SessionFactory sf;
|
||||||
public static ServiceRegistry sr;
|
public static ServiceRegistry sr;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package love.sola.netsupport.wechat;
|
package love.sola.netsupport.wechat;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
import love.sola.netsupport.config.Lang;
|
import love.sola.netsupport.config.Lang;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* ***********************************************
|
||||||
* Created by Sola on 2015/12/2.
|
* Created by Sola on 2015/12/2.
|
||||||
@@ -16,4 +19,14 @@ public class TestMessageFormat {
|
|||||||
assert Lang.messages != null;
|
assert Lang.messages != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonDate() {
|
||||||
|
Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
||||||
|
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||||
|
.create();
|
||||||
|
Date date = new Date();
|
||||||
|
assert gson.fromJson(gson.toJson(date), Date.class).compareTo(date) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user