首页 > 代码库 > mybatis插入图片处理--mysql
mybatis插入图片处理--mysql
- 1. 数据库Scheme
1.数据库Scheme
- DROP TABLE IF EXISTS `user_graphic_t`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `user_graphic_t` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `graphic_data` blob,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=360 DEFAULT CHARSET=utf8;
2.Mapper配置文件
- <resultMap id="userGraphicMap" type="userGraphicVo">
- <id column="id" property="id" jdbcType="DECIMAL" />
- <span style="color: #ff0000;"><result column="graphic_data" property="graphicData" jdbcType="BLOB" /></span>
- </resultMap>
- <sql id="resultColumn">
- id,graphic_data
- </sql>
- <insert id="insertUserGraphic" parameterType="userGraphicVo">
- INSERT INTO user_graphic_t (
- <include refid="resultColumn" />
- )
- values (
- #{id},,#{graphicData}
- )
- </insert>
- <select id="selectUserGraphic" parameterType="java.lang.Long" resultMap="userGraphicMap">
- SELECT
- <include refid="resultColumn" />
- from user_graphic_t WHERE
- id=#{id}
- order by id desc
- </select>
3.Java bean
- public class UserGraphicVo {
- private Long id;
- private byte[] graphicData;
- //get/set方法
- }
- public void showReportImage() {
- response.setContentType("image/jpeg");
- if (!"".equals(id)) {
- List<UserGraphicVo> list = userGraphicService.findUserGraphicVoById(id);
- if(null != list && !list.isEmpty()){
- OutputStream os = null;
- try {
- os = response.getOutputStream();
- os.write(list.get(0).getGraphicData());
- os.flush();
- } catch (IOException e) {
- Log.info("读取文件出错!" + e.getMessage());
- } finally {
- if(null != os){
- try {
- os.close();
- } catch (IOException e) {
- Log.info("关闭文件输出流出错!" + e.getMessage());
- }
- }
- }
- }
- }
- }
mybatis插入图片处理--mysql
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。