Package org.jeecgframework.core.common.model.json

Examples of org.jeecgframework.core.common.model.json.AjaxJson


   */
  @SuppressWarnings("unchecked")
  @RequestMapping(params = "saveOrUpdate")
  @ResponseBody
  public AjaxJson saveOrUpdate(HttpServletRequest request) throws Exception{
    AjaxJson j = new AjaxJson();
    Map data = request.getParameterMap();
    if(data!=null){
      data = CommUtils.mapConvert(data);
      String tableName = (String)data.get("tableName");
      String id = (String)data.get("id");
      //打印测试
        Iterator it=data.entrySet().iterator();
        while(it.hasNext()){
          Map.Entry entry=(Map.Entry)it.next();
            Object ok=entry.getKey();
            Object ov=entry.getValue()==null?"":entry.getValue();
            logger.debug("name:"+ok.toString()+";value:"+ov.toString());
        }
        if(StringUtils.isEmpty(id)){
          //消除不是表的字段
          String [] filterName = {"tableName","saveOrUpdate"};
          data = CommUtils.attributeMapFilter(data,filterName);
          //保存数据库
          try {
            Object pkValue = null;
            pkValue = dataBaseService.getPkValue(tableName);
            data.put("id", pkValue);
          int num = dataBaseService.insertTable(tableName, data);
          if (num>0) {
            j.setSuccess(true);
            message = "添加成功";
          }else {
            j.setSuccess(false);
            message = "添加失败";
          }
        } catch (Exception e) {
          e.printStackTrace();
          j.setSuccess(false);
          message = e.getMessage();
        }
      }else{
        //消除不是表的字段
          String [] filterName = {"tableName","saveOrUpdate","id"};
          data = CommUtils.attributeMapFilter(data,filterName);
          //更新数据库
          try {
          int num = dataBaseService.updateTable(tableName, id, data);
          if (num>0) {
            j.setSuccess(true);
            message = "更新成功";
          }else {
            j.setSuccess(false);
            message = "更新失败";
          }
         
        } catch (Exception e) {
          e.printStackTrace();
          j.setSuccess(false);
          message = e.getMessage();
        }
      }
    }
    j.setMsg(message);
    j.setObj(data);
    return j;
  }
View Full Code Here


    }
  // 老的EasyUI上传方式(2013/05/28废弃)
  @RequestMapping(params = "implXls")
  @ResponseBody
    public AjaxJson implXls(HttpServletRequest request, HttpServletResponse response) {
        AjaxJson j = new AjaxJson();
        MultipartHttpServletRequest mulRequest = (MultipartHttpServletRequest) request;
        MultipartFile file = mulRequest.getFile("filedata");
        List<JpPersonEntity> listPersons;
    try {
      boolean isSuccess = true;
      listPersons = (List<JpPersonEntity>) ExcelUtil.importExcelByIs(file.getInputStream(), JpPersonEntity.class);
      for (JpPersonEntity person : listPersons) {
        person.setId(UUIDGenerator.generate());
        if (person.getAge() == null || person.getCreatedt() == null || person.getSalary() == null) {
          isSuccess = false;
          break;
        } else {
          jpPersonService.save(person);
        }
      }
      if (isSuccess)
        j.setMsg("文件导入成功!");
      else
        j.setMsg("文件格式不正确,导入失败!");
    } catch (IOException e) {
            j.setMsg("文件导入失败!");           
            logger.error(ExceptionUtil.getExceptionMessage(e));    
    } catch (Exception e) {
      j.setMsg("文件格式不正确,导入失败!");
    }
        return j;
    }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @RequestMapping(params = "saveOrUpdateMore")
  @ResponseBody
  public AjaxJson saveOrUpdateMore(HttpServletRequest request) throws Exception{
    AjaxJson j = new AjaxJson();
    Map data = request.getParameterMap();
    if(data!=null){
      data = CommUtils.mapConvert(data);
      String tableName = (String)data.get("tableName");
      String id = (String)data.get("id");
      //打印测试
        Iterator it=data.entrySet().iterator();
        while(it.hasNext()){
          Map.Entry entry=(Map.Entry)it.next();
            Object ok=entry.getKey();
            Object ov=entry.getValue()==null?"":entry.getValue();
            logger.debug("name:"+ok.toString()+";value:"+ov.toString());
        }
        Map<String,List<Map<String,Object>>> mapMore =CommUtils.mapConvertMore(data, tableName);
        if(StringUtils.isEmpty(id)){
          logger.info("一对多添加!!!!!");
          try {
            Map<String, Object> result = dataBaseService.insertTableMore(mapMore, tableName);
            data.put("id", result.get("id"));
            j.setSuccess(true);
          message = "添加成功";
        } catch (BusinessException e) {
          e.printStackTrace();
          j.setSuccess(false);
          message = e.getMessage();
        }
         
      }else{
        logger.info("一对多修改!!!!!");
        try {
          dataBaseService.updateTableMore(mapMore, tableName);
          j.setSuccess(true);
          message = "更新成功";
        } catch (BusinessException e) {
          e.printStackTrace();
          j.setSuccess(false);
          message = e.getMessage();
        }
      }
    }
    j.setMsg(message);
    j.setObj(data);
    return j;
  }
View Full Code Here

 
  // 统一的Excel上传导入方式
  @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  @ResponseBody
  public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
    AjaxJson j = new AjaxJson();
   
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
      MultipartFile file = entity.getValue();// 获取上传文件对象
      List<JpPersonEntity> listPersons;
      try {
        listPersons = (List<JpPersonEntity>) ExcelUtil.importExcelByIs(file.getInputStream(), JpPersonEntity.class);
        for (JpPersonEntity person : listPersons) {
          if(person.getAge()!=null){
            person.setId(UUIDGenerator.generate());
            jpPersonService.save(person);
          }
        }
        j.setMsg("文件导入成功!");
      } catch (IOException e) {
        j.setMsg("文件导入失败!");
        logger.error(ExceptionUtil.getExceptionMessage(e));
      }
      //break; // 不支持多个文件导入?
    }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @RequestMapping(params = "doButton")
  @ResponseBody
  public AjaxJson doButton(HttpServletRequest request){
    AjaxJson j = new AjaxJson();
    try {
      String formId = request.getParameter("formId");
      String buttonCode = request.getParameter("buttonCode");
      String tableName = request.getParameter("tableName");
      String id = request.getParameter("id");
      Map<String,Object> data  = dataBaseService.findOneForJdbc(tableName, id);
      if(data!=null){
        //打印测试
          Iterator it=data.entrySet().iterator();
          while(it.hasNext()){
            Map.Entry entry=(Map.Entry)it.next();
              Object ok=entry.getKey();
              Object ov=entry.getValue()==null?"":entry.getValue();
              logger.debug("name:"+ok.toString()+";value:"+ov.toString());
          }
        data = CommUtils.mapConvert(data);
        dataBaseService.executeSqlExtend(formId, buttonCode, data);
      }
      j.setSuccess(true);
      message = "操作成功";
    } catch (Exception e) {
      e.printStackTrace();
      message = "操作失败";
    }
    j.setMsg(message);
    return j;
  }
View Full Code Here

   * @return
   */
  @RequestMapping(params = "del")
  @ResponseBody
  public AjaxJson del(JpPersonEntity jpPerson, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    jpPerson = systemService.getEntity(JpPersonEntity.class, jpPerson.getId());
    message = "删除成功";
    jpPersonService.delete(jpPerson);
    systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
   
    j.setMsg(message);
    return j;
  }
View Full Code Here

   * @return
   */
  @RequestMapping(params = "save")
  @ResponseBody
  public AjaxJson save(JpPersonEntity jpPerson, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    if (StringUtil.isNotEmpty(jpPerson.getId())) {
      message = "更新成功";
      jpPersonService.saveOrUpdate(jpPerson);
      systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
    } else {
View Full Code Here

 
  @SuppressWarnings("unchecked")
  @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  @ResponseBody
  public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
    AjaxJson j = new AjaxJson();
   
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
      MultipartFile file = entity.getValue();// 获取上传文件对象
      ImportParams params = new ImportParams();
      params.setTitleRows(2);
      params.setSecondTitleRows(2);
      params.setNeedSave(true);
      try {
        List<CourseEntity> listCourses =
          (List<CourseEntity>)ExcelImportUtil.importExcelByIs(file.getInputStream(),CourseEntity.class,params);
        for (CourseEntity course : listCourses) {
          if(course.getName()!=null){
            courseService.saveCourse(course);
          }
        }
        j.setMsg("文件导入成功!");
      } catch (Exception e) {
        j.setMsg("文件导入失败!");
        logger.error(ExceptionUtil.getExceptionMessage(e));
      }finally{
        try {
          file.getInputStream().close();
        } catch (IOException e) {
View Full Code Here

   */
  @RequestMapping(params = "saveFormEkeditor")
  @ResponseBody
  public AjaxJson saveCkeditor(HttpServletRequest request,
      CgformFtlEntity cgformFtlEntity, String contents) {
    AjaxJson j = new AjaxJson();
    if (StringUtil.isNotEmpty(cgformFtlEntity.getId())) {
      CgformFtlEntity t = systemService.get(CgformFtlEntity.class,
          cgformFtlEntity.getId());
      try {
        MyBeanUtils.copyBeanNotNull2Bean(cgformFtlEntity, t);
        t.setFtlContent(contents);
        systemService.saveOrUpdate(t);
        j.setSuccess(true);
        j.setMsg("更新成功");
      } catch (Exception e) {
        e.printStackTrace();
        j.setSuccess(false);
        j.setMsg("更新失败");
      }
    }
    return j;
  }
View Full Code Here

   * @return
   */
  @RequestMapping(params = "del")
  @ResponseBody
  public AjaxJson del(CgformFtlEntity cgformFtl, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();
    cgformFtl = systemService.getEntity(CgformFtlEntity.class,
        cgformFtl.getId());
    message = "删除成功";
    cgformFtlService.delete(cgformFtl);
    systemService.addLog(message, Globals.Log_Type_DEL,
        Globals.Log_Leavel_INFO);

    j.setMsg(message);
    return j;
  }
View Full Code Here

TOP

Related Classes of org.jeecgframework.core.common.model.json.AjaxJson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.