From 3b29b5fd093df20a2776d17ea0a912924028245e Mon Sep 17 00:00:00 2001 From: wentch <22250530@qq.com> Date: Thu, 31 Dec 2015 15:17:44 +0800 Subject: [PATCH] --- convert.html | 54 ++++++++++++++++++++++----------------- stylesheets/highlight.css | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/convert.html b/convert.html index f016b2a93..c593b11d0 100644 --- a/convert.html +++ b/convert.html @@ -68,29 +68,7 @@ public UserRecord() { } - public int getUserid() { - return userid; - } - - public void setUserid(int userid) { - this.userid = userid; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } + /** 以下省略getter setter方法 */ } public static void main(String[] args) throws Exception { @@ -106,7 +84,7 @@ /** * 以下功能是为了屏蔽password字段。 - * 等价于在 public String getPassword() 加上 @ConvertColumn : + * 等价于 public String getPassword() 加上 @ConvertColumn : * * @ConvertColumn(ignore = true, type = ConvertType.JSON) * public String getPassword() { @@ -123,6 +101,34 @@ System.out.println(childConvert.convertTo(user2)); //应该也是 {"userid":100,"username":"redkalename"} } +

      JsonConvert 支持非空构造函数:

+
public class UserRecord {
+
+    private int userid;
+
+    private String username = "";
+
+    private String password = "";
+
+    @java.beans.ConstructorProperties({"userid", "username", "password"})
+    public UserRecord(int userid, String username, String password) {
+        this.userid = userid;
+        this.username = username;
+        this.password = password;
+    }
+
+    public int getUserid() {
+        return userid;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+}