数据表
create table test
(
TASKID NUMBER(10) not null,
CONFIG CLOB
)
controller
@ResponseBody
@RequestMapping("/getTest")
public List getTest(HttpServletRequest request, HttpServletResponse response){
return this.Service.getTest();
}
sql.xml
<select id="gettest"
resultMap="hashmap">
select t.config as config,
t.taskid
from test t
</select>
1、没有做任何处理情况,程序报错如下
Caused by:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class
oracle.sql.LobDBAccessImpl and no properties discovered to create
BeanSerializer (to avoid exception, disable
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain:
java.util.ArrayList[0]->java.util.HashMap["CONFIG"]->oracle.sql.CLOB["dbaccess"])
2、在sql.xml中,对CLOB字段Config进行to_char()处理,开始能够解决问题,后面出现数据库报错的情况
sql.xml
<select id="gettest"
resultMap="hashmap">
select to_char(t.config) as config,
t.taskid
from test t
</select>
数据库报错
3、去掉@ResponseBody,将返回的结果打印出来,发现config是一个对象
controller
//@ResponseBody
@RequestMapping("/getTest")
public List getTest(HttpServletRequest request, HttpServletResponse response){
System.out.println(this.Service.getTest());
return this.Service.getTest();
}
debug
[{CONFIG=oracle.sql.CLOB@16e2b70,TASKID=38}]
4、在Mybatis中采用resultMap处理,程序正常,debug时config为具体内容。
sql.xml
<select id="gettest"
resultMap="testMap">
select t.config as config,
t.taskid
from test t
</select>
<resultMap type="hashmap" id="testMap">
<result property="CONFIG" column="config" javaType="String" jdbcType="CLOB"/>
<result property="TASKID" column="taskid"/>
</resultMap>
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。