コード例 #1
0
  @ResponseBody
  @RequestMapping(value = "/upload", method = RequestMethod.POST)
  public ImmutableMap<String, String> linkImgUpload(
      MultipartFile file, HttpServletRequest request) {
    if (file.isEmpty()) {
      return ImmutableMap.of("status", "0", "message", getMessage("global.uploadempty.message"));
    }
    Site site = (Site) (SystemUtils.getSessionSite());
    String linkPath = PathFormat.parseSiteId(SystemConstant.LINK_RES_PATH, site.getSiteId() + "");
    String realPath = HttpUtils.getRealPath(request, linkPath);

    SystemUtils.isNotExistCreate(realPath);

    String timeFileName = SystemUtils.timeFileName(file.getOriginalFilename());
    try {
      file.transferTo(new File(realPath + "/" + timeFileName));
    } catch (IOException e) {
      LOGGER.error("链接图片添加失败,错误:{}", e.getMessage());
      return ImmutableMap.of("status", "0", "message", getMessage("link.uploaderror.message"));
    }
    return ImmutableMap.of(
        "status",
        "1",
        "message",
        getMessage("link.uploadsuccess.message"),
        "filePath",
        (linkPath + "/" + timeFileName),
        "contentPath",
        HttpUtils.getBasePath(request));
  }
コード例 #2
0
  @RequestMapping(
      value = "/list/{p}",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String linkList(
      Link link, @PathVariable Integer p, HttpServletRequest request, ModelMap modelMap) {
    Session session = SystemUtils.getShiroSession();
    if (StringUtils.isNotBlank(link.getLinkName())) {
      session.setAttribute("linkSearch", link);
      modelMap.addAttribute("searchLink", link);
    } else {
      session.setAttribute("linkSearch", null);
    }
    Object searchObj = session.getAttribute("linkSearch");

    Page<Link> result =
        linkService.findLinkPageable((searchObj == null ? (new Link()) : ((Link) searchObj)), p);

    modelMap.addAttribute("links", result.getContent());
    modelMap.addAttribute(
        "pagination",
        SystemUtils.pagination(result, HttpUtils.getContextPath(request) + "/manager/link/list"));
    return "link/link_list";
  }