コード例 #1
0
 /*
  * 跳转至属性页面
  */
 @RequestMapping("/cfg/toEditCfgPage.do")
 public String toEditCfg(
     HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   String parentid = request.getParameter("parentid");
   String id = request.getParameter("id");
   ConfigDto dto = null;
   if (id != null && !id.trim().equals("")) {
     dto = this.service.findByID(id);
   } else {
     dto = new ConfigDto();
     dto.setParentid(parentid);
   }
   model.addAttribute("cfgDto", dto);
   return "/config/EditCfg.jsp";
 }
コード例 #2
0
  /*
   * 保存对象
   */
  @RequestMapping("/cfg/saveCfg.do")
  public String saveSysNode(
      HttpServletRequest request, HttpServletResponse response, ModelMap model, ConfigDto dto)
      throws Exception {

    response.setContentType("text/html;charset=UTF-8");
    String flag = "0";
    String message = "";
    String showType = "info";
    try {
      if (StringUtils.isNotEmpty(dto.getKey().trim()) && this.service.isExist(dto)) {
        flag = "1";
        showType = "error";
        message = "已存在Key:\"" + dto.getKey() + "\",请重新输入!";
      } else {
        if (dto.getId() != null && !dto.getId().trim().equals("")) {
          ConfigDto dtoDB = this.service.findByID(dto.getId());
          dtoDB.setName(dto.getName());
          dtoDB.setKey(dto.getKey());
          dtoDB.setValue(dto.getValue());
          dtoDB.setDescription(dto.getDescription());
          this.service.update(dtoDB);
        } else {
          dto.setId(WebConstants.generateDefaultID());
          this.service.save(dto);
        }
        message = "保存成功!";
      }
    } catch (Exception e) {
      e.printStackTrace();
      flag = "1";
      showType = "error";
      message = "保存失败";

    } finally {
      response
          .getWriter()
          .print("{'flag':'" + flag + "','msg':'" + message + "','showType':'" + showType + "'}");
    }
    return null;
  }