Pojo类 User.java
public class User implements Serializable{
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String password;
private String phone;
private String email;
private Date created;
private Date updated;
...(省略掉相关getter setter方法);
测试方法:
@Test
public void getByTokenKeyTest(){
String token="d9c37f9c-303b-4e42-895c-b9b97ff44cea";
User user=userCache.getByTokenKey(token);
System.out.println(user.toString());
System.out.println(JSON.toJSONString(user));
}
输出
//System.out.println(user.toString()) 输出
User{id=222, username='Test', password='sdfafafaf', phone='135864545322', email='AAAA@AAAAA.AAAA', created=Tue Jul 18 10:43:31 CST 2017, updated=Tue Jul 18 10:43:31 CST 2017}
// System.out.println(JSON.toJSONString(user));
{"email":"AAAA@AAAAA.AAAA","id":222,"password":"sdfafafaf","phone":"135864545322","updated":1500345811648,"username":"Test"}
pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.35</version>
</dependency>
3条答案
按热度按时间i86rm4rw1#
是不是只有一个有getter?
bvk5enib2#
谢谢,经提醒检查了通过MyBatis自动代码生成的Getter,Setter的相关方法,发现created的getter方法错了。该方法被错误的声明为public Date getCreated(Date created)。
20jt8wwn3#
试试 https://github.com/kimmking/mybatis-generator-lombok-plugin
@luoweipeter