您好,登錄后才能下訂單哦!
數據表
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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。