温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

@ResponseBody处理Clob数据

发布时间:2020-06-11 15:42:05 来源:网络 阅读:2322 作者:Gynwn 栏目:开发技术

数据表

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>

数据库报错

@ResponseBody处理Clob数据

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>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI