溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

@ResponseBody處理Clob數(shù)據(jù)

發(fā)布時間:2020-06-11 15:42:05 來源:網(wǎng)絡(luò) 閱讀:2344 作者:Gynwn 欄目:開發(fā)技術(shù)

數(shù)據(jù)表

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()處理,開始能夠解決問題,后面出現(xiàn)數(shù)據(jù)庫報錯的情況

sql.xml

<select id="gettest"
		resultMap="hashmap">
		select to_char(t.config) as config,
		       t.taskid
		from test t
	</select>

數(shù)據(jù)庫報錯

@ResponseBody處理Clob數(shù)據(jù)

3、去掉@ResponseBody,將返回的結(jié)果打印出來,發(fā)現(xiàn)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為具體內(nèi)容。

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問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI