package com.ppcxy.cyfm.sys.web;

import com.ppcxy.common.web.controller.BaseCRUDController;
import com.ppcxy.cyfm.sys.entity.Resource;
import com.ppcxy.cyfm.sys.service.ResourceService;
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 org.springside.modules.mapper.JsonMapper;

/**
 * Created by weep on 2016-5-16.
 */
@Controller
@RequestMapping(value = "/resource")
public class ResourceController extends BaseCRUDController<Resource, Long> {
    @Autowired
    private ResourceService resourceService;

    public ResourceController() {
        setResourceIdentity("resource");
        setModelName("resource");
    }
//@RequestMapping(value = {"list", ""})
    //@PageableDefaults(sort = {"weight=desc", "id=asc"})
    //public String list(Searchable searchable, Model model) {
    //    model.addAttribute("page", resourceService.findAll(searchable));
    //    return "resource/resourceList";
    //}
    //
    //@RequestMapping(value = "create", method = RequestMethod.GET)
    //public String createForm(Model model) {
    //    model.addAttribute("resource", new Resource());
    //    model.addAttribute("action", "create");
    //    return "resource/resourceForm";
    //}
    //
    //@RequestMapping(value = "create", method = RequestMethod.POST)
    //public String create(@Valid Resource newResource, RedirectAttributes redirectAttributes) {
    //    resourceService.save(newResource);
    //    redirectAttributes.addFlashAttribute("message", "创建资源成功");
    //    return "redirect:/resource/";
    //}
    //
    ////
    //@RequestMapping(value = "update/{id}", method = RequestMethod.GET)
    //public String updateForm(@PathVariable("id") Long id, Model model) {
    //    model.addAttribute("resource", resourceService.findOne(id));
    //    model.addAttribute("action", "update");
    //    return "resource/resourceForm";
    //}
    //
    //@RequestMapping(value = "update", method = RequestMethod.POST)
    //public String update(@Valid @ModelAttribute("task") Resource resource, RedirectAttributes redirectAttributes) {
    //    resourceService.save(resource);
    //    redirectAttributes.addFlashAttribute("message", "更新资源成功");
    //    return "redirect:/resource/";
    //}
    //
    ////
    //@RequestMapping(value = "delete/{id}")
    //public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttributes) {
    //    resourceService.delete(id);
    //    redirectAttributes.addFlashAttribute("message", "删除任务成功");
    //    return "redirect:/resource/";
    //}
    //
    ///**
    // * 所有RequestMapping方法调用前的Model准备方法, 实现Struts2 Preparable二次部分绑定的效果,先根据form的id从数据库查出Task对象,再把Form提交的内容绑定到该对象上。
    // * 因为仅update()方法的form中有id属性，因此仅在update时实际执行.
    // */
    //@ModelAttribute
    //public void getTask(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
    //    if (id != -1) {
    //        model.addAttribute("task", resourceService.findOne(id));
    //    }
    //}

    @RequestMapping(value = "load")
    @ResponseBody

    public String loadResources(Model model) {
        return JsonMapper.nonEmptyMapper().toJson(resourceService.findAll());
    }
}

@@ -849,2340 +849,8 @@
    %7D
-%0A//@RequestMapping(value = %7B%22list%22, %22%22%7D)%0A    //@PageableDefaults(sort = %7B%22weight=desc%22, %22id=asc%22%7D)%0A    //public String list(Searchable searchable, Model model) %7B%0A    //    model.addAttribute(%22page%22, resourceService.findAll(searchable));%0A    //    return %22resource/resourceList%22;%0A    //%7D%0A    //%0A    //@RequestMapping(value = %22create%22, method = RequestMethod.GET)%0A    //public String createForm(Model model) %7B%0A    //    model.addAttribute(%22resource%22, new Resource());%0A    //    model.addAttribute(%22action%22, %22create%22);%0A    //    return %22resource/resourceForm%22;%0A    //%7D%0A    //%0A    //@RequestMapping(value = %22create%22, method = RequestMethod.POST)%0A    //public String create(@Valid Resource newResource, RedirectAttributes redirectAttributes) %7B%0A    //    resourceService.save(newResource);%0A    //    redirectAttributes.addFlashAttribute(%22message%22, %22%E5%88%9B%E5%BB%BA%E8%B5%84%E6%BA%90%E6%88%90%E5%8A%9F%22);%0A    //    return %22redirect:/resource/%22;%0A    //%7D%0A    //%0A    ////%0A    //@RequestMapping(value = %22update/%7Bid%7D%22, method = RequestMethod.GET)%0A    //public String updateForm(@PathVariable(%22id%22) Long id, Model model) %7B%0A    //    model.addAttribute(%22resource%22, resourceService.findOne(id));%0A    //    model.addAttribute(%22action%22, %22update%22);%0A    //    return %22resource/resourceForm%22;%0A    //%7D%0A    //%0A    //@RequestMapping(value = %22update%22, method = RequestMethod.POST)%0A    //public String update(@Valid @ModelAttribute(%22task%22) Resource resource, RedirectAttributes redirectAttributes) %7B%0A    //    resourceService.save(resource);%0A    //    redirectAttributes.addFlashAttribute(%22message%22, %22%E6%9B%B4%E6%96%B0%E8%B5%84%E6%BA%90%E6%88%90%E5%8A%9F%22);%0A    //    return %22redirect:/resource/%22;%0A    //%7D%0A    //%0A    ////%0A    //@RequestMapping(value = %22delete/%7Bid%7D%22)%0A    //public String delete(@PathVariable(%22id%22) Long id, RedirectAttributes redirectAttributes) %7B%0A    //    resourceService.delete(id);%0A    //    redirectAttributes.addFlashAttribute(%22message%22, %22%E5%88%A0%E9%99%A4%E4%BB%BB%E5%8A%A1%E6%88%90%E5%8A%9F%22);%0A    //    return %22redirect:/resource/%22;%0A    //%7D%0A    //%0A    ///**%0A    // * %E6%89%80%E6%9C%89RequestMapping%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8%E5%89%8D%E7%9A%84Model%E5%87%86%E5%A4%87%E6%96%B9%E6%B3%95, %E5%AE%9E%E7%8E%B0Struts2 Preparable%E4%BA%8C%E6%AC%A1%E9%83%A8%E5%88%86%E7%BB%91%E5%AE%9A%E7%9A%84%E6%95%88%E6%9E%9C,%E5%85%88%E6%A0%B9%E6%8D%AEform%E7%9A%84id%E4%BB%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9F%A5%E5%87%BATask%E5%AF%B9%E8%B1%A1,%E5%86%8D%E6%8A%8AForm%E6%8F%90%E4%BA%A4%E7%9A%84%E5%86%85%E5%AE%B9%E7%BB%91%E5%AE%9A%E5%88%B0%E8%AF%A5%E5%AF%B9%E8%B1%A1%E4%B8%8A%E3%80%82%0A    // * %E5%9B%A0%E4%B8%BA%E4%BB%85update()%E6%96%B9%E6%B3%95%E7%9A%84form%E4%B8%AD%E6%9C%89id%E5%B1%9E%E6%80%A7%EF%BC%8C%E5%9B%A0%E6%AD%A4%E4%BB%85%E5%9C%A8update%E6%97%B6%E5%AE%9E%E9%99%85%E6%89%A7%E8%A1%8C.%0A    // */%0A    //@ModelAttribute%0A    //public void getTask(@RequestParam(value = %22id%22, defaultValue = %22-1%22) Long id, Model model) %7B%0A    //    if (id != -1) %7B%0A    //        model.addAttribute(%22task%22, resourceService.findOne(id));%0A    //    %7D%0A    //%7D
 %0A%0A  

清理无用代码.