发表于: 2018-01-09 23:28:04

1 582


今天完成的事情:

1.  文件上传接口80%

2. 在框架里调用memecache


明天计划的事情

1. 小课堂

2. 文件上传的文件后缀判断 文件下载接口


遇到的问题:



收获:

1.  文件上传接口80%

@RequestMapping(value = "/a/u/file/up", method = RequestMethod.POST)
public String fileUp(HttpServletRequest request, HttpServletResponse response,
                    ModelMap model, @RequestParam("file") MultipartFile multipartFile, Integer belong,Integer type){

String message = null;
   try {
       if(DataUtils.isNullOrEmpty(belong) || DataUtils.isNullOrEmpty(type)) {
           log.info("类型或归属为空  type:" + type+ "  belong" + belong);
           model.addAttribute("code", -1000);
           model.addAttribute("message", "参数不能为空");
           return "/common/fail";
       }
       String fileType= fileType = FileUtil.type(Integer.valueOf(type));
       String fileBelong= fileBelong = FileUtil.belong(Integer.valueOf(belong));
       if(fileType.equals("文件没有类型") || fileBelong.equals("文件没有类型")){
           log.info("类型或归属类型错误  fileType:" + fileType+ "  fileBelong" + fileBelong);
           model.addAttribute("code",-1004);
           model.addAttribute("message","参数非法");
           return "/common/fail";
       }


       String userName = "asds";


       File file = FileUtil.multipartToFile(multipartFile);
       log.info("multipartFileName:"+multipartFile.getOriginalFilename());
       String fileRename = FileUtil.fileRename(userName,multipartFile.getOriginalFilename());
       message = fileApiUtil.uploadFile(fileBelong, fileRename,file,multipartFile.getContentType());
       String url = fileApiUtil.fileUrl(fileBelong,fileRename);
       log.info("文件的url: "+ url);
       model.addAttribute("code",0);
       model.addAttribute("message",message);
       model.addAttribute("url",url);
       return "/file/uploadSuccess";
   }catch (Throwable t) {
        t.printStackTrace();
       log.error("异常错误type:" + type+ "  belong" + belong);
       model.addAttribute("code", -7000);
       model.addAttribute("message", message);
   }
   return "/common/fail";
}





2. 在框架里调用memecache

1. 在memecache_client.xml里配置一下

<region name="memcache" listenerClass="com.gemantic.dal.cache.listener.DefaultListenerImpl" strategyClass="com.gemantic.memcached.route.strategy.DefaultStrategy">
  <keyPattern value="[0-9]$" datasource ="default"/>
</region>


因为框架里的方法没有实现可以设定有效时间的接口,所以继承原有方法,在写一个实现即可:

public class Memcache extends CacheHelper {

public static void put(String region, String key, Object value,Long var3) throws CacheException {
       Cache cache = getListCache(region);
       if(null != cache) {
        cache.put(key, value, var3);
       }
   }
}


调用:

node = SCANodeFactory.newInstance().createSCANode("META-INF/playlearn-ojbk-service/server.composite");
node.start();
Memcache.put("memcache","id","23",4L);
try {
Thread.sleep(1000*3);
}catch (InterruptedException e){
e.printStackTrace();
}
log.info(Memcache.get("memcache","id"));



任务进度:文件接口 

 任务延期原因:接口文档没有整理好

 第二次延期时间到:1-9

 第二次延期时间到:1-10

DOME时间:2018-2-9




返回列表 返回列表
评论

    分享到