Hibernate 存储SQL Server image 类型的文件

    xiaoxiao2021-12-03  19

    1.MyEclipse反向工程后得到image的对应的类型竟然是String,要把它改成byte[]

    private byte[] avatar; 2.在XX.hbm.xml配置文件中,相应字段改为binary

    <property name="avatar" type="binary"> <column name="avatar" /> </property> 3.直接在网页上显示

    在服务器端将实体类转换为json数据返回给

    在网页上用内容拼接到img标签的src属性中

    $.getJSON("${ctx}/query/monitor/ajaxEmployee.do?code="+employeeCode,function(data){ if(data != null){ $("#"+counterCode).find(".employee_code").text(data.id.code).end() .find(".employee_name").text(data.name).end() .find(".employee_jobTitle").text(data.jobTitle).end() .find(".employee_head").attr("src","data:image/jpg;base64,"+data.avatar); } });

    转载请注明原文地址: https://ju.6miu.com/read-680070.html

    最新回复(0)