通过ApplicationContext.getBean(beanName)动态加载数据。
2017-11-24 21:47
435 查看
一,前台数据
1 $.ajax({ 2 url: '/intra/coe/order/ploadTable.htm', 3 type: 'POST', 4 dataType: 'json',
data: {keyId:$("#key_keyId").val(),beanName:'cpAssetsModify',},
关键注意这个url
二,到后台的代码
(会默认的找到这个index方法,配置文件设置的)
1 @SuppressWarnings("unchecked") 2 public void index(HttpServletRequest request, HttpServletResponse response) { 3 4 String keyId = request.getParameter("keyId"); 5 6 String beanName = request.getParameter("beanName"); 7 8 String tableHead = request.getParameter("tableHead"); 9 10 String tableName = request.getParameter("tableName"); 11 12 LoadTableService loadTableService = ApplicationContext.getBean(beanName); 13 14 List<Map<String, Object>> headLst = getTableHead(tableHead); 15 if(headLst==null||headLst.size()==0){ 16 headLst = loadTableService.getHeadList(keyId); 17 } 18 Map<String, Object> tableInfo = new HashMap<String, Object>(); 19 tableInfo.put("tableName", tableName); 20 List<Map<String, Object>> bodyLst = (List<Map<String, Object>>) loadTableService.getBodyList(keyId,tableInfo);
上面的
ApplicationContext.getBean(beanName);
会把前台获取的这个bean去配置文件找,注意这个是application容器,所以就会去所有的已经加载的xml文件里面去找,包括jar包里面的xml文件
会找到下面的配置文件
1 <bean id="cpAssetsModify" 2 class=" com.bill99.seashell.boss.appcontroller.intra.product.AssetsCPModifyControler"> 3 <property name="methodNameResolver"> 4 <ref bean="paramResolver" /> 5 </property> 6 7 <property name="merchantAccountService" ref="merchantAccountService"/> 8 <property name="merchantInfoService" ref="merchantInfoService"/> 9 <property name="workorderDetailService" ref="workorderDetailService"/> 10 <property name="dynamicBuildProductClient" ref="dynamicBuildProductClient"/> 11 </bean>
这个时候返会的就是
AssetsCPModifyControler这个类的一个代理对象,注意上面的index方法是公共的,但是这个时候假如把beanname为cpAssetsModify传过来找到对应的类AssetsCPModifyControler
loadTableService.getBodyList(keyId,tableInfo);实质上就是
AssetsCPModifyControler.getBodyList(keyId,tableInfo)了。
三,接口及实现类
1 public List<Map<String, Object>> getBodyList(String keyId,Map<String, Object> tableInfo);
上面的就是接口了。
1 public class AssetsCPModifyControler extends IntraProductBaseControler implements LoadTableService{ 2 @Override 3 public List<Map<String, Object>> getBodyList(String keyId,Map<String, Object> tableInfo) { 4 List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); 5 WorkorderDetail wd = workorderDetailService.findWorkorderDetailById(keyId); 6 7 String jsonStr = wd.getProductParam(); 8 if(!StringUtil.isEmpty(jsonStr)){ 9 try 10 { 11 Map<String, Object> productMap = JsonUtils.json2Map(jsonStr); 12 if(productMap.get("productList") != null){ 13 List<Map<String,Object>> productList = (List)productMap.get("productList"); 14 //获得cp下面的终端 15 getAddTerminals(resultList,productList); 16 //获得变更的终端 和 资产下面的终端 17 getUpdateTerminals(resultList, productList); 18 int terminalNo=1; 19 for (Map<String, Object> terminalMap : resultList) { 20 terminalMap.put("terminalNo", terminalNo); 21 terminalNo++; 22 } 23 } 24 } catch (Exception e) { 25 logger.error("json2Map异常", e); 26 } 27 } 28 return resultList; 29 }
这个是实现类,在这就可以操作了。
以上就是通过
ApplicationContext.getBean(beanName)
动态的加载的一种方式。
相关文章推荐
- 通过ApplicationContextAwareSpring实现手工加载配置的javabean
- 通过ApplicationContextAwareSpring实现手工加载配置的javabean
- 通过ApplicationContextAware获取bean
- 通过ApplicationContextAware获取bean .
- applicationContext.xml配置业务层时候,显示找不到数据层的某某DAO的bean
- spring学习(五)ClassPathXmlApplicationContext的getBean获取实例bean
- ECharts通过Ajax动态加载数据到图表
- applicationContext.getBean() 随处可获取basedao
- applicationContext.getBean()
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- 一个简单的例子演示:模仿微博里面的通过浏览器的滚动条来动态加载数据
- 通过ApplicationContextAware获取spring容器中的bean
- Error creating bean with name 'bookBizImpl' defined in class path resource [applicationContext.xml]
- Echarts通过Ajax实现动态数据加载
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean faile
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Spring学习笔记之Spring中applicationContext.xml的bean里的id和name属性区别