• 默认图片展示(个人信息模块)


    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); } }
  • 相关阅读:
    JVM结构
    redis缓存淘汰策略
    idea常用快捷键
    Spring常用注解
    redis持久化
    crontab定时调度
    redis五种数据类型
    LVM实验报告
    fdisk以及parted分区实验
    fdisk与parted的区别以及parted为何可分128个区
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/5357325.html
Copyright © 2020-2023  润新知