首页 > 代码库 > Jeecg Controller层的模版----自己的版本

Jeecg Controller层的模版----自己的版本

自己修改了下Controller版本,改变原因,
1.msg面临的并发危险,
2.ModelAndView基本毫无作用的地位
3.ModelMap代替Request
出来的结果如图,使用了静态变量代替了view
效果如下:





模板是

package ${bussiPackage}.controller.${entityPackage};
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;

import ${bussiPackage}.entity.${entityPackage}.${entityName}Entity;
import ${bussiPackage}.service.${entityPackage}.${entityName}ServiceI;

/**   
 * @Title: Controller
 * @Description: ${ftl_description}
 * @author JueYue
 * @date ${ftl_create_time}
 * @version V1.1
 *
 */
@Controller
@RequestMapping("/${entityName?uncap_first}Controller")
public class ${entityName}Controller extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(${entityName}Controller.class);
    //列表界面
    private static final String ${entityName?upper_case}_LIST_PAGE = "${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}List";
    //新增修改界面
    private static final String ${entityName?upper_case}_ADD_OR_UPDATE_PAGE = "${bussiPackage?replace(".","/")}/${entityPackage}/${entityName?uncap_first}";

    @Autowired
	private ${entityName}ServiceI ${entityName?uncap_first}Service;
	@Autowired
	private SystemService systemService;

	/**
	 * ${ftl_description}列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "${entityName?uncap_first}")
	public String ${entityName?uncap_first}(HttpServletRequest request) {
		return ${entityName?upper_case}_LIST_PAGE;
	}

	/**
	 * easyui AJAX请求数据
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param ${entityName?uncap_first}
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(${entityName}Entity ${entityName?uncap_first},HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(${entityName}Entity.class, dataGrid);
		//查询条件组装器
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ${entityName?uncap_first}, request.getParameterMap());
		this.${entityName?uncap_first}Service.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}

	/**
	 * 删除${ftl_description}
	 * 
	 * @return
	 */
	@RequestMapping(params = "del")
	@ResponseBody
	public AjaxJson del(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		${entityName?uncap_first} = systemService.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
        j.setMsg("${ftl_description}删除成功");
		${entityName?uncap_first}Service.delete(${entityName?uncap_first});
		systemService.addLog(j.getMsg(), Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
		return j;
	}


	/**
	 * 添加${ftl_description}
	 * 
	 * @param ${entityName?uncap_first}
	 * @return
	 */
	@RequestMapping(params = "save")
	@ResponseBody
	public AjaxJson save(${entityName}Entity ${entityName?uncap_first}, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
            j.setMsg("${ftl_description}更新成功");
			${entityName}Entity t = ${entityName?uncap_first}Service.get(${entityName}Entity.class, ${entityName?uncap_first}.getId());
			try {
				MyBeanUtils.copyBeanNotNull2Bean(${entityName?uncap_first}, t);
				${entityName?uncap_first}Service.saveOrUpdate(t);
				systemService.addLog(j.getMsg(), Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
			} catch (Exception e) {
				e.printStackTrace();
                j.setMsg("${ftl_description}更新失败");
			}
		} else {
            j.setMsg("${ftl_description}添加成功");
			${entityName?uncap_first}Service.save(${entityName?uncap_first});
			systemService.addLog(j.getMsg(), Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
		}
		return j;
	}

	/**
	 * ${ftl_description}列表页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "addorupdate")
	public String addorupdate(${entityName}Entity ${entityName?uncap_first}, ModelMap map) {
		if (StringUtil.isNotEmpty(${entityName?uncap_first}.getId())) {
			${entityName?uncap_first} = ${entityName?uncap_first}Service.getEntity(${entityName}Entity.class, ${entityName?uncap_first}.getId());
            map.put("${entityName?uncap_first}Page", ${entityName?uncap_first});
		}
		return ${entityName?upper_case}_ADD_OR_UPDATE_PAGE;
	}
}

大家也上传下自己的风格吧,适合自己的才是最好的