记录一下我在工作中常用到的valuelist
1、前端展示标签:
使用案例
<vlh:root value="list" url="?" includeParameters="*">
<vlh:addParam name="" value="" />
<vlh:retrieve name="adapter名字" />
<vlh:row bean="bean">
<vlh:column title="" property="" format="yyyy-MM-dd" />
</vlh:row>
<!--分页-->
<vlh:paging showSummary="true" pages="10" />
</vlh:root>
2、后台配置
valueListHandler.xml 配置 所有能调用的adapter
格式:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<!--update 可读写分离-->
<bean id="updateAdapter" scope="singleton" abstract="true" class="support.valuelist.adapter.AbstractAdapter">
<property name="dataSource" ref="数据库1"/>
<property name="showSql" value="true"/>
</bean>
<!--select -->
<bean id="selectAdapter" scope="singleton" abstract="true" class="support.valuelist.adapter.AbstractAdapter">
<property name="dataSource" ref="数据库2"/>
<property name="showSql" value="true"/>
</bean>
<bean id="valueListHandler" scope="singleton" class="support.valuelist.ValueListHandlerImpl">
<property name="config.adapters">
<map>
<entry key="你要调用的adapter">
<ref bean="你要调用的adapter"/>
</entry>
</map>
</property>
</bean>
</beans>
你要调用的adapter配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="adapter名字" parent="abstractAdapter" class="可自定义adapter,然后集成Adapter">
<property name="DataSource" value="数据库"/>
<property name="showSql" value="true"/>
<property name="onlyQuery" value="true"/>
<property name="beforeList">
<list>
<bean class="support.valuelist.adapter.SubAdapter">
<property name="dataSource" ref="数据库"/>
<property name="sql"><value>sql语句/~可选参数:参数={参数}~/</value></property>
</bean>
</list>
</property>
<property name="sql"><value>查询,可以将上面查出来的当条件</value>
</property>
<property name="updateSqlMap">
<map><entry key="cycleList"><list>
<bean class="support.valuelist.adapter.Update">
<property name="dataSource" ref="数据库"/>
<property name="sql"><value>可以循环插入</value></property>
</bean>
</list></entry></map>
</property>
</bean>
</beans>
自动以adapter
public class MyAdapter extends Adapter {
}
后台调用
不在spring容器中的类获取bean
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
ValueListHandler valueListHandler = (ValueListHandler) context.getBean("valueListHandler");
Map<String, Object> para = new HashMap<String, Object>();
if(valueListHandler == null){
return ;
}
para.put("参数", 值);
valueListHandler.getValueList(adapter名字, new ValueListInfo(para));
使用完毕
天为被,地为床