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


    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垃圾回收(GC)整理总结学习
    ConcurrentHashMap
    Java GC、新生代、老年代
    Android -- 查看手机中所有进程
    ThreadLocal
    Android -- DrawerLayout
    WeakReference与SoftReference
    ASP.NET Core Web服务器 Kestrel和Http.sys 特性详解
    微服务架构体系
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/5357325.html
Copyright © 2020-2023  润新知