Using the MyBatisresult set interceptor to meet such a requirement:
Due to frequent changes in project requirements, the project MySQL database stores JSON strings. For example, the user's basic information may change with version upgrades
Datasheet
CREATE TABLE `account` (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`infos` text NOT NULL COMMENT '用户JSON基本信息',
`createTime` int(10) unsigned NOT NULL COMMENT '创建时间',
`updateTime` int(10) unsigned NOT NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Data:
id
infos
createTime
updateTime
1
{"nickName":"Jan","region_area":"","region_city":"Shenzhen City","region_country":"China","region_province":"Guangdong Province","sex":"Male" ,"signature":"As long as you don't give up, you still have a chance!"}
1467793564
1470795733
JSONPlugin interceptor
Use the MyBatis拦截器对ResultSetHandler接口的handleResultSets interceptor to intercept the handleResultSets method of the ResultSetHandler interface:
Using the
MyBatis
result set interceptor to meet such a requirement:Datasheet
Data:
JSONPlugin interceptor
Use the
MyBatis
拦截器对ResultSetHandler
接口的handleResultSets
interceptor to intercept thehandleResultSets
method of theResultSetHandler
interface:mybatis-config.xml
Register the plugin in the mybatis configuration file:
Test output
Using
Mybatis
to achieve the following requirementsDatasheet
Data
Use
Mybatis
对Executor.class
的'qurey'
to intercept the'qurey'
method ofExecutor.class
and process the returned result setmybatis-config.xml
Register the plugin in the mybatis configuration file:
Test output