Administrator
2018-11-27 acd2b6eaf5ebd1a9d5aa1f54a741dfa6fc52ac10
fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java
@@ -7,12 +7,17 @@
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.JsonUtil;
@Controller
@@ -47,4 +52,75 @@
      out.print(JsonUtil.loadTrueResult("修改成功"));
      return;
   }
   /**
    * 查询列表 - 新后台
    * @param callback
    * @param key 查询词  名称
    * @param pageIndex
    * @param out
    */
   @RequestMapping(value = "getNewConfigList")
   public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){
      try {
         if (pageIndex == null || pageIndex < 0){
            pageIndex = 1;
         }
         List<Config> list =  configService.listObjects(key, pageIndex);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
            return;
         }
         int count = configService.getCount(key, pageIndex);
         PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count);
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 参数修改 - 新后台
    * @param callback
    * @param config
    * @param out
    */
   @RequestMapping(value = "saveModify")
   public void saveModify(String callback, Config config, PrintWriter out) {
      Long id = config.getId();
      if (id == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
         return;
      }
      try {
         Config crentconfig = configService.getConfig(id);
         if (crentconfig == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作数据已不存在"));
            return;
         }
         // key 不可修改
         config.setKey(crentconfig.getKey());
         configService.update(config);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("修改失败"));
         e.printStackTrace();
      }
   }
}