jdiy获取上传表单带文件并联store

原创
2022/03/29 19:40
阅读数 63
 @Resource
    private AdminContext admincontext;
    @RequestMapping(value = "/mgmt/gamematerail",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Ret gamematerailsave(HttpServletRequest request) {
        String gameid=  request.getParameter("gameid");
        int type=0;
        List<MultipartFile> files = ((MultipartHttpServletRequest)request).getFiles("url");
        for(MultipartFile file:files)
        {
            String filetype=file.getContentType();
            if(filetype.contains("jpeg")||filetype.contains("png")||filetype.contains("gif"))
            {
                type=20;
            }else if(filetype.contains("mp4"))
            {
                type=10;
            }else {
                return Ret.fail("上传文件类型有误!");
            }
            Rs rs=admincontext.getDao().create("gamematerial");
            rs.set("gameid",gameid);
            rs.set("type",type);
            rs.set("sort",1);
            admincontext.getDao().save(rs);
            long materialid=rs.getLong("materialid");
            Store store= admincontext.getStore("gamematerial",""+materialid);
            try {
                store.set("url",file);
                rs.set("url",store.get("url").getUrl());
                admincontext.getDao().save(rs);
                return Ret.success();
            } catch (IOException e) {
                e.printStackTrace();
                return Ret.fail("处理失败");
            }
        }
        return Ret.success();
    }

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部