| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package ${controllerPackage};
- 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 ${domainPackage}.${className}Entity;
- import ${servicePackage}.${className}Service;
- /**
- * 描述:${codeName}
- * @author: ${author}
- * @since:${nowDate}
- * @version:1.0
- */
- @Controller
- @RequestMapping("/${projectName}/${lowerName}")
- public class ${className}Controller extends BaseController{
- @Autowired
- private ${className}Service ${lowerName}Service;
-
- /**
- * 列表页面
- * @return
- */
- @RequestMapping(params = "list",method = {RequestMethod.GET,RequestMethod.POST})
- public void list(@ModelAttribute ${className}Entity 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<${className}Entity> list = ${lowerName}Service.getAll(query,pageNo,pageSize);
- VelocityContext velocityContext = new VelocityContext();
- velocityContext.put("${lowerName}",query);
- velocityContext.put("pageInfos",SystemTools.convertPaginatedList(list));
- String viewName = "${projectName}/${bussPackage}/${lowerName}-list.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 详情
- * @return
- */
- @RequestMapping(params="toDetail",method = RequestMethod.GET)
- public void ${lowerName}Detail(@RequestParam(required = true, value = "id" ) String id,HttpServletResponse response,HttpServletRequest request)throws Exception{
- VelocityContext velocityContext = new VelocityContext();
- String viewName = "${projectName}/${bussPackage}/${lowerName}-detail.vm";
- ${className}Entity ${lowerName} = ${lowerName}Service.get(id);
- velocityContext.put("${lowerName}",${lowerName});
- 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 = "${projectName}/${bussPackage}/${lowerName}-add.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- }
- /**
- * 保存信息
- * @return
- */
- @RequestMapping(params = "doAdd",method ={RequestMethod.GET, RequestMethod.POST})
- @ResponseBody
- public AjaxJson doAdd(@ModelAttribute ${className}Entity ${lowerName}){
- AjaxJson j = new AjaxJson();
- try {
- String randomSeed = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
- ${lowerName}.setId(randomSeed);
- ${lowerName}Service.insert(${lowerName});
- 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();
- ${className}Entity ${lowerName} = ${lowerName}Service.get(id);
- velocityContext.put("${lowerName}",${lowerName});
- String viewName = "${projectName}/${bussPackage}/${lowerName}-edit.vm";
- ViewVelocity.view(request,response,viewName,velocityContext);
- }
- /**
- * 编辑
- * @return
- */
- @RequestMapping(params = "doEdit",method ={RequestMethod.GET, RequestMethod.POST})
- @ResponseBody
- public AjaxJson doEdit(@ModelAttribute ${className}Entity ${lowerName}){
- AjaxJson j = new AjaxJson();
- try {
- ${lowerName}Service.update(${lowerName});
- 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 {
- ${className}Entity ${lowerName} = new ${className}Entity();
- ${lowerName}.setId(id);
- ${lowerName}Service.delete(${lowerName});
- j.setMsg("删除成功");
- } catch (Exception e) {
- log.info(e.getMessage());
- j.setSuccess(false);
- j.setMsg("删除失败");
- }
- return j;
- }
- }
|