public class MysqlJsonAdaptor extends java.lang.Object implements ValueAdaptor
public class Pet { public static Pet getInstance(ResultSet rs) throws SQLException { // 需要把所有字段从 ResultSet 取出,不然该属性无法映射 Pet pet = new Pet(); pet.setId(rs.getInt("id")); pet.setData(NutMap.WRAP(rs.getString("data"))); return pet; } @Id private int id; @ColDefine(customType = "json", type = ColType.MYSQL_JSON) private NutMap data; // ... 省略后面代码,包括字段声明以及 getter 和 setter } public class Jone { public Jone(ResultSet rs) throws SQLException { // 需要把所有字段从 ResultSet 取出,不然该属性无法映射 this.id = rs.getInt("id"); this.info = Json.fromJson(Information.class, rs.getString("info")); } @Id private int id; @ColDefine(customType = "json", type = ColType.MYSQL_JSON) private Information info; // ... 省略后面代码,包括字段声明以及 getter 和 setter }
构造器和说明 |
---|
MysqlJsonAdaptor() |
public java.lang.Object get(java.sql.ResultSet rs, java.lang.String colName) throws java.sql.SQLException
ValueAdaptor
get
在接口中 ValueAdaptor
rs
- 结果集colName
- 列名java.sql.SQLException
public void set(java.sql.PreparedStatement stat, java.lang.Object obj, int index) throws java.sql.SQLException
ValueAdaptor
一个值可以被设置到多个占位符中
set
在接口中 ValueAdaptor
stat
- 缓冲语句obj
- 值index
- 占位符位置,从 1 开始java.sql.SQLException