| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package com.jeecg.p3.demo.web;
- import java.util.UUID;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.velocity.VelocityContext;
- import org.jeecgframework.minidao.pojo.MiniDaoPage;
- import org.jeecgframework.p3.core.common.utils.AjaxJson;
- import org.jeecgframework.p3.core.page.SystemTools;
- import org.jeecgframework.p3.core.util.plugin.ViewVelocity;
- import org.jeecgframework.p3.core.web.BaseController;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.jeecg.p3.demo.entity.JeecgP3demoEntity;
- import com.jeecg.p3.demo.service.JeecgP3demoService;
- /**
- * 描述:P3测试表
- * @author: www.jeecg.org
- * @since:2017年05月15日 20时07分37秒 星期一
- * @version:1.0
- */
- @Controller
- @RequestMapping("/demo/jeecgP3demo")
- public class JeecgP3demoController extends BaseController{
- @Autowired
- private JeecgP3demoService jeecgP3demoService;
-
- /**
- * 列表页面
- * @return
- */
- @RequestMapping(params = "list",method = {RequestMethod.GET,RequestMethod.POST})
- public void list(@ModelAttribute JeecgP3demoEntity query,HttpServletRequest request,HttpServletResponse response,
- @RequestParam(required = false, value = "pageNo", defaultValue = "1") int pageNo,
- @RequestParam(required = false, value = "pageSize", defaultValue = "10") int pageSize) throws Exception{
- try {
- LOG.info(request, " back list");
- //分页数据
- MiniDaoPage<JeecgP3demoEntity> list = jeecgP3demoService.getAll(query,pageNo,pageSize);
- VelocityContext velocityContext = new VelocityContext();
- velocityContext.put("jeecgP3demo",query);
- velocityContext.put("pageInfos",SystemTools.convertPaginatedList(list));
- String viewName = "demo/p3/jeecgP3demo-list.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 详情
- * @return
- */
- @RequestMapping(params="toDetail",method = RequestMethod.GET)
- public void jeecgP3demoDetail(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request)throws Exception{
- VelocityContext velocityContext = new VelocityContext();
- String viewName = "demo/p3/jeecgP3demo-detail.vm";
- JeecgP3demoEntity jeecgP3demo = jeecgP3demoService.get(id);
- velocityContext.put("jeecgP3demo",jeecgP3demo);
- ViewVelocity.view(request,response,viewName,velocityContext);
- }
- /**
- * 跳转到添加页面
- * @return
- */
- @RequestMapping(params = "toAdd",method ={RequestMethod.GET, RequestMethod.POST})
- public void toAddDialog(HttpServletRequest request,HttpServletResponse response)throws Exception{
- VelocityContext velocityContext = new VelocityContext();
- String viewName = "demo/p3/jeecgP3demo-add.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- }
- /**
- * 保存信息
- * @return
- */
- @RequestMapping(params = "doAdd",method ={RequestMethod.GET, RequestMethod.POST})
- @ResponseBody
- public AjaxJson doAdd(@ModelAttribute JeecgP3demoEntity jeecgP3demo){
- AjaxJson j = new AjaxJson();
- try {
- String randomSeed = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
- jeecgP3demo.setId(randomSeed);
- jeecgP3demoService.insert(jeecgP3demo);
- j.setMsg("保存成功");
- } catch (Exception e) {
- log.info(e.getMessage());
- j.setSuccess(false);
- j.setMsg("保存失败");
- }
- return j;
- }
- /**
- * 跳转到编辑页面
- * @return
- */
- @RequestMapping(params="toEdit",method = RequestMethod.GET)
- public void toEdit(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request) throws Exception{
- VelocityContext velocityContext = new VelocityContext();
- JeecgP3demoEntity jeecgP3demo = jeecgP3demoService.get(id);
- velocityContext.put("jeecgP3demo",jeecgP3demo);
- String viewName = "demo/p3/jeecgP3demo-edit.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- }
- /**
- * 编辑
- * @return
- */
- @RequestMapping(params = "doEdit",method ={RequestMethod.GET, RequestMethod.POST})
- @ResponseBody
- public AjaxJson doEdit(@ModelAttribute JeecgP3demoEntity jeecgP3demo){
- AjaxJson j = new AjaxJson();
- try {
- jeecgP3demoService.update(jeecgP3demo);
- j.setMsg("编辑成功");
- } catch (Exception e) {
- log.info(e.getMessage());
- j.setSuccess(false);
- j.setMsg("编辑失败");
- }
- return j;
- }
- /**
- * 删除
- * @return
- */
- @RequestMapping(params="doDelete",method = RequestMethod.GET)
- @ResponseBody
- public AjaxJson doDelete(@RequestParam(required = true, value = "id" ) String id){
- AjaxJson j = new AjaxJson();
- try {
- JeecgP3demoEntity jeecgP3demo = new JeecgP3demoEntity();
- jeecgP3demo.setId(id);
- jeecgP3demoService.delete(jeecgP3demo);
- j.setMsg("删除成功");
- } catch (Exception e) {
- log.info(e.getMessage());
- j.setSuccess(false);
- j.setMsg("删除失败");
- }
- return j;
- }
- }
|