标签:exclude ons bmp template int package json src amp
页面加载的时候,callback函数将对应信息字典表id,通过callback回调函数传给Action,action调用业务层,业务层调用DAO从数据库里面将需要的数据,再由Action传给页面。
package com.mycrm.web.action; import java.io.IOException; import java.util.List; import org.apache.logging.log4j.core.config.json.JsonConfiguration; import org.apache.struts2.ServletActionContext; import com.mycrm.domain.BaseDict; import com.mycrm.service.BaseDictService; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import net.sf.json.JSONArray; import net.sf.json.JsonConfig; /* * 字典的Action */ public class BaseDictAction extends ActionSupport implements ModelDriven<BaseDict> { // 模型驱动 private BaseDict baseDict = new BaseDict(); @Override public BaseDict getModel() { return baseDict; } //注入Service private BaseDictService baseDictService; public void setBaseDictService(BaseDictService baseDictService) { this.baseDictService = baseDictService; } //根据类型名称查询字典的方法,findByTypeCode public String findByTypeCode() throws IOException{ System.out.println("BasedictAction中的findByTypeCode方法执行了"); List<BaseDict> list = baseDictService.findByTypeCode(baseDict.getDict_type_code()); //将list转成JSON,引入包 jsonlib/fastjson /** * JSONConfig:转JSON的配置对象 * JSONArray: 将数组和list集合转成JSON * JSONObject: 将对象和MAP集合转成JSON */ //jsonConfig.setExcludes去掉不必要的字段 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setExcludes(new String[]{"dict_sort","dict_enable","dict_memo"}); JSONArray jsonArray = JSONArray.fromObject(list,jsonConfig); //将JSON打印到页面: ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); ServletActionContext.getResponse().getWriter().println(jsonArray.toString()); return NONE; } }
package com.mycrm.service.impl; import java.util.List; import com.mycrm.dao.BaseDictDao; import com.mycrm.domain.BaseDict; import com.mycrm.service.BaseDictService; /** * * 字典业务层的实现类 */ public class BaseDictServiceImpl implements BaseDictService { // 注入Dao private BaseDictDao baseDictDao; public void setBaseDictDao(BaseDictDao baseDictDao) { this.baseDictDao = baseDictDao; } @Override public List<BaseDict> findByTypeCode(String dict_type_code) { return baseDictDao.findByTypeCode(dict_type_code) ; } }
package com.mycrm.dao.impl; import java.util.List; import org.springframework.orm.hibernate5.support.HibernateDaoSupport; import com.mycrm.dao.BaseDictDao; import com.mycrm.domain.BaseDict; public class BaseDictDaoImpl extends HibernateDaoSupport implements BaseDictDao { @Override public List<BaseDict> findByTypeCode(String dict_type_code) { return (List<BaseDict>) this.getHibernateTemplate().find("from BaseDict where dict_type_code=?", dict_type_code); } }
标签:exclude ons bmp template int package json src amp
原文地址:https://www.cnblogs.com/ltfxy/p/10363552.html