zoukankan      html  css  js  c++  java
  • 默认图片展示(个人信息模块)

    1.页面中展示默认图片

    <img style=" 50px;height: 50px;margin: 5px" id="imgid" src="${ctx}/sys/user/getPicById?id=${user.id}"/>

    2.controller层

        /*
         * 显示图片
         */
        @RequestMapping(value = {"getPicById"})
        public void getPicById(User user, HttpServletRequest request, HttpServletResponse response, Model model) {
            try {
                byte[] imgData = null;
                byte[] data =user.getPic();
                if(data!=null){
                    response.setContentType("image/jpeg/bng");
                    response.setCharacterEncoding("UTF-8");        
                    imgData =FileUploadUtils.scaleImage( data, 100, 100);
                }else{
                    //反馈默认图片
        String defaultImgPath = 
    request.getSession().getServletContext().getRealPath("")+File.separator+"static"+File.separator+
    "images"+File.separator+"default.JPG"; File defaultImgFile = new File(defaultImgPath); byte[] temp = FileUploadUtils.getBytesFromFile(defaultImgFile); imgData =FileUploadUtils.scaleImage( temp, 100, 100); } if(imgData!=null){ OutputStream out = response.getOutputStream(); InputStream in = new ByteArrayInputStream(imgData); int len=0; byte[] buf = new byte[1024]; while((len =in.read(buf,0,1024))!= -1){ out.write(buf,0,len); } out.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } model.addAttribute("user", user); } }
  • 相关阅读:
    Centos 7 快速安装 Docker
    MySQL乱码
    阿里云中linux 下svn服务器安装
    java中易错点(二)
    java中易错点(一)
    mysql5.7.24 解压版安装步骤以及遇到的问题
    linux交换分区调整
    linux之切换用户su(switch user)
    linux简单常用命令
    Yum简单使用小结
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/5357325.html
Copyright © 2011-2022 走看看