Java tutorial
/******************************************************************************* * Copyright (c) 2005, 2014 springside.github.io * * Licensed under the Apache License, Version 2.0 (the "License"); *******************************************************************************/ package com.kingen.web; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.ArrayUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Maps; import com.kingen.aop.ControllerLogAnnotation; import com.kingen.bean.PersonSkillScore; import com.kingen.bean.SkillCat; import com.kingen.service.skill.SkillService; import com.kingen.util.FastJsonUtil; import com.kingen.util.JsonResultBuilder; import com.kingen.util.Page; import com.kingen.util.TreeConverter; import com.kingen.util.mapper.BeanMapper; import com.kingen.vo.SkillAndScoreVo; import com.kingen.vo.TreeNode; /** * * @author wj * @date 2017-2-6 */ @Controller @RequestMapping(value = "/skill") public class SkillController extends CommonController { private static Logger logger = LoggerFactory.getLogger(SkillController.class); @Autowired private SkillService service; @RequestMapping(value = "/") @RequiresPermissions("skill:view") @ControllerLogAnnotation(moduleName = "??", option = "?") public String execute(Model m, HttpServletResponse response) throws Exception { return "skill/tree"; } @RequestMapping(value = "/score") @RequiresPermissions("skillScore:view") @ControllerLogAnnotation(moduleName = "??", option = "?") public String score(Model m, HttpServletResponse response) throws Exception { return "skill/score-list"; } /** * ?grid */ //?jsonstring ?jsonObject @RequestMapping(value = "/treeData") public @ResponseBody Object data(Page<SkillCat> page, HttpServletResponse response) { List<SkillCat> all = service.list(); List<TreeNode> allConverted = BeanMapper.mapList(all, TreeNode.class); Map<String, Object> json = Maps.newHashMapWithExpectedSize(1); //?chidlren,return toComplexJsonString(offices);?.jsonString??????? json.put("children", TreeConverter.toComplexTree(allConverted)); return json; } /** * */ @RequestMapping(value = "score/data") public void scoredata(String userId, Page<SkillAndScoreVo> page, HttpServletResponse response) { page = service.findPersonScore(page, userId); writeJson(response, page); } @RequestMapping(value = "toEdit") public String toEdit(String id, String pid, String action, HttpServletResponse response, HttpServletRequest request, Model model) { model.addAttribute("action", action); model.addAttribute("id", id);//null? ?? model.addAttribute("pid", pid);//null? ?? return "skill/edit"; } @RequestMapping(value = "/one") public void one(String id, HttpServletResponse response) { SkillCat u = service.unique(id); writeJson(response, u); } /** * */ @ControllerLogAnnotation(moduleName = "??-?", option = "") @RequestMapping(value = "deleteCascade") public void deleteCascade(String id, HttpServletResponse response) { JSONObject json = new JSONObject(); try { service.delCascade(id); json = JsonResultBuilder.success(true).msg("?").json(); } catch (Exception e) { json = JsonResultBuilder.success(false).msg("").json(); logger.error(e.getMessage()); e.printStackTrace(); } writeJson(response, json); } /** * * @throws Exception */ @RequestMapping(value = "save") @ControllerLogAnnotation(moduleName = "??-?", option = "") public void save(SkillCat data, HttpServletResponse response) { JSONObject json = new JSONObject(); try { service.add(data); json = JsonResultBuilder.success(true).msg("??").json(); } catch (Exception e) {//service ? // TODO Auto-generated catch block e.printStackTrace(); json = JsonResultBuilder.success(false).msg(e.getMessage()).json(); logger.error(e.getMessage()); } writeJson(response, json); } /** * */ @RequestMapping(value = "update") @ControllerLogAnnotation(moduleName = "??-?", option = "") public void update(SkillCat data, HttpServletResponse response) { JSONObject json = new JSONObject(); try { service.updateForm(data); json = JsonResultBuilder.success(true).msg("??").json(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); json = JsonResultBuilder.success(false).msg(e.getMessage()).json(); logger.error(e.getMessage()); } writeJson(response, json); } /** * ? * @throws Exception */ @RequestMapping(value = "score/saveBatch") @ControllerLogAnnotation(moduleName = "??-?", option = "?") public void saveBatch(String userId, /* PersonSkillScore[] scores ,*/String scores, HttpServletResponse response) { JSONObject json = new JSONObject(); try { List<PersonSkillScore> scoresCollect = FastJsonUtil.toList(scores, PersonSkillScore.class); service.saveBatch(userId, scoresCollect); json = JsonResultBuilder.success(true).msg("??").json(); } catch (Exception e) {//service ? // TODO Auto-generated catch block e.printStackTrace(); logger.error(e.getMessage()); json = JsonResultBuilder.success(false).msg(e.getMessage()).json(); } writeJson(response, json); } }