富文字框回顯亂碼問題解決
富文字編輯器是將樣式及內容一起放入資料庫,所用資料型別為blob型,在資料裝入資料庫及從資料庫中讀取時應注意編碼格式問題,以防止出現亂碼。出現亂碼時主要解決手段:
1.檢視建立blob物件是不是用的“utf8”編碼格式
2.查詢時是否進行了二次編碼解析,主要體現在mapper.xml檔案中。blob對應欄位要進行處理,處理內容如下:
- package cn.ffcs.drive.common.util;
- import java.io.ByteArrayInputStream;
- import java.io.UnsupportedEncodingException;
- import java.sql.Blob;
- import java.sql.CallableStatement;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.apache.ibatis.type.BaseTypeHandler;
- import org.apache.ibatis.type.JdbcType;
- /**
- * className:ConvertBlobTypeHandler
- *
- * 自定義typehandler,解決mybatis儲存blob欄位後,出現亂碼的問題
- * 配置mapper.xml:
- * <result typeHandler="cn.ffcs.drive.common.util.ConvertBlobTypeHandler"/>
- *
- * @author pengyh
- * @version 1.0.0
- * @date 2014-07-09 11:15:23
- *
- */
- publicclass ConvertBlobTypeHandler extends BaseTypeHandler<String> {
- //###指定字符集
- privatestaticfinal String DEFAULT_CHARSET =
- @Override
- publicvoid setNonNullParameter(PreparedStatement ps, int i,
- String parameter, JdbcType jdbcType) throws SQLException {
- ByteArrayInputStream bis;
- try {
- //###把String轉化成byte流
- bis = new ByteArrayInputStream(parameter.getBytes(DEFAULT_CHARSET));
- } catch (UnsupportedEncodingException e) {
- thrownew RuntimeException("Blob Encoding Error!");
- }
- ps.setBinaryStream(i, bis, parameter.length());
- }
- @Override
- public String getNullableResult(ResultSet rs, String columnName)
- throws SQLException {
- Blob blob = rs.getBlob(columnName);
- byte[] returnValue = null;
- if (null != blob) {
- returnValue = blob.getBytes(1, (int) blob.length());
- }
- try {
- //###把byte轉化成string
- returnnew String(returnValue, DEFAULT_CHARSET);
- } catch (UnsupportedEncodingException e) {
- thrownew RuntimeException("Blob Encoding Error!");
- }
- }
- @Override
- public String getNullableResult(CallableStatement cs, int columnIndex)
- throws SQLException {
- Blob blob = cs.getBlob(columnIndex);
- byte[] returnValue = null;
- if (null != blob) {
- returnValue = blob.getBytes(1, (int) blob.length());
- }
- try {
- returnnew String(returnValue, DEFAULT_CHARSET);
- } catch (UnsupportedEncodingException e) {
- thrownew RuntimeException("Blob Encoding Error!");
- }
- }
- @Override
- public String getNullableResult(ResultSet arg0, int arg1)
- throws SQLException {
- // TODO Auto-generated method stub
- returnnull;
- }
- }
定義上面類之後,在mapper.xml中配置<result property="content" column="CONTENT" typeHandler="cn.ffcs.drive.common.util.ConvertBlobTypeHandler"/>即可。
實體接收使用String接收。
轉載自http://blog.csdn.net/p793049488/article/details/37818989
相關推薦
富文字框回顯亂碼問題解決
富文字編輯器是將樣式及內容一起放入資料庫,所用資料型別為blob型,在資料裝入資料庫及從資料庫中讀取時應注意編碼格式問題,以防止出現亂碼。出現亂碼時主要解決手段:1.檢視建立blob物件是不是用的“utf8”編碼格式2.查詢時是否進行了二次編碼解析,主要體現在mapper.x
關於c#MVC後臺接收百度富文字框中的值失敗原因的解決!
最近在使用百度富文字框的時候 ,遇見了一個令我很無語的操作,我在前臺使用jQuery獲取百度富文字框中的值,路徑什麼的都是對的, 也沒有語法錯誤,但是就進不了後臺,後臺就一直接收不到資料 最後通過百度找到了解決的方法:如下 HttpRequest 類使用輸入驗證標誌來跟蹤是否對通過 Co
selenium如何處理特殊的富文字框------例如知乎富文框
常見的富文字框是input, textarea文字框,如果有iframe巢狀,需要進行表單切換,可以參考https://blog.csdn.net/supramolecular/article/details/81364061, 但是對於div富文字框,既不包括input 也不包括 textar
Ueditor 百度富文字框的使用(二次渲染)其他的在文件中都有
富文字編輯器有很多。好用的,不好用的,功能簡單的,功能複雜的。 現在,我選擇的是百度的UEditor編輯器。這個編輯器的唯一有點就是功能多。比kindeditor 這些編輯器的功能要多。當然,像layui 提供的富文字框我沒有用,所以,現在不能拿來對比。因為當初想要用layui的時候,我套了一下
富文字框TinyMCE上傳本地圖片基本配置
注意:上傳本地圖片是TinyMCE 4.3才新引入的功能,所以該配置只適合4.3及其以上 <!doctype html> <html> <head> <script src='https://cloud.tinymce.com/stable/tinymce.m
使用vue製作富文字框
這裡分享一個富文字框外掛,如圖 使用方法: 1-安裝 npm install --save vue2-editor 或者 yarn add vue2-editor 2- 使用 // Basic Use - Covers most scenarios
下拉框 回顯
引入jstl <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 下拉框回顯 <select name="queryMySelect" class="texts"> <
前臺用UMeditor富文字框的形式存取內容
完成效果圖如下: 可以去官網:https://ueditor.baidu.com/website/index.html ue版本功能多,um版本日常功能都有,我下載的um把版本 1) 需要依賴static/Ueditor <link href="${pa
freemarker 下拉框回顯
使用的是Boolean值,如果為flase,返回的則是 ' ' 空字串,否則返回 'true' 字串 <select id="hot" class="easyui-combobox" data-
ubuntu文字模式/終端中文亂碼解決
# Configuration for FbTerm # Lines starting with '#' are ignored. # Note that end-of-line comments are NOT supported, comments must be on a line of their o
layui表格資料複選框回顯設定
layui2.3版本,本身並不帶有複選框回顯功能,那麼需要從源頭解決此事,F12程式碼除錯,找到與複選框關聯的地方發現: 我們只需要在渲染資料回撥時找到每個複選框根據資料的不同來設定回顯。 layui這裡有一個坑,設定class屬性後會造成二次點選效果,千萬不要手動修改class屬性,
自己動手實現簡易的div可編輯富文字框及按下tab鍵後增加4個空格功能
需求分析:最近需要製作一個簡單的使用者評論輸入框,在網上找了一些富文字輸入框,但是它們的功能太多,不適合自己的需求,於是決定自己動手實現一個簡易的富文字輸入框。第一步:想要實現富文字輸入框並不是難事,在<div>標籤內加入 contenteditable="t
vue-cli webpack 引入 wangeditor(輕量級富文字框)
1:使用npm下載: //(注意 wangeditor 全部是小寫字母) npm install wangeditor 2: 直接在專案模板中引用 import E from 'wanged
thinkphp5下百度富文字框UEditor的使用
1到官網下載 UEditor 最新版2解壓下載的包,將解壓後的目錄放到thinkphp public資料夾下3. 引用時 html頁面<body><!-- 載入編輯器的容器 --><scriptid="container"name="con
select下拉框回顯的幾種方法
第一種: jsp程式碼: <selectid="csrqnf"name="csrqnf"id="selecte"class="shortselect"value="${nfResult}">
如何獲取富文字框中的內容
js程式碼: <!-- 文字編輯器 開始 --> <textarea name="content" id="contect_text" class="ckedito
在html頁面寫一個富文字框
第一步:獲取到富文字框的這個檔案,連結地址:https://ckeditor.com/cke4/builder(1)裡面有幾個選擇,看你需求自己進行選擇,然後滑鼠一直拖到最下面,開始下載包 下面我只是舉個例子:我選擇的事第三個full;後面還有些選擇類似。注意:
Ueditor富文字編輯器報錯解決方案
ueditor 它配置時會請求配置檔案 在Thinkphp下如果你在config.php檔案裡開啟show_page_trace=true在一切和官網配置無異前提下,上傳時出現後端配置出錯的
富文字框的使用
相關資料下載地址 首先引進相關的js、css <link rel="stylesheet" href="${basePath}/static/font-awesome-3.2.1/css/font-awesome.min.css" type="text/css"> <lin
專案中用到的富文字框編輯器wangEditor
文件地址:http://www.wangeditor.com/index.html <div id="div1"></div> <script src="js/wangEditor.min.js"></script> var E = w