日期:2014-05-16 浏览次数:20884 次
<bean id="testQuery1" class="org.ecside.easyda.DataAccessModel"> <!-- 注入一个标准的数据源 --> <property name="dataSource" ref="test_datasource" /> <property name="sqls"> <map> <!-- 这个key的名字随便取 --> <entry key="queryInfoByNameGender" > <value> select * from user_info where 1=1 #{IF:USERNAME!=EMPTY} and username like #{USERNAME} #{/IF} #{IF:GENDER!=EMPTY} and gender=#{GENDER} #{/IF} </value> </entry> </map> </property> </bean>
// 这里也可以使用 Ioc 注入。 DataAccessModel dam=(DataAccessModel)factory.getBean("testQuery1"); //parameterMap为传入参数,key为USERNAME GENDER。 List list=(List)dam.executeQuery("queryInfoByNameGender", parameterMap);
public static Map getParameterMap(HttpServletRequest request) { Map parameterMap = new HashMap(); Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String[] s = request.getParameterValues(name); if (s != null) { if (s.length == 1) { parameterMap.put(name, request.getParameterValues(name)[0]); } else { parameterMap.put(name, request.getParameterValues(name)); } } } return parameterMap; }
<entry key="queryInfoByNameGender" > <value> select * from user_info where 1=1 #{IF:i_user_name!=EMPTY} and username like #{i_user_name} #{/IF} #{IF:i_user_gender!=EMPTY} and gender=#{i_user_gender} #{/IF} </value> </entry>
<bean id="myEasyDA" class="demo.MyDataAccessModel"> <property name="dataSource" ref="test_datasource" /> <property name="sqls"> <map> <entry key="baseInfo1" > <value> {call CM_CUST_REAL_INFO_P( #{I_SERVICE_KIND}, #{I_SERVICE_NO}, #{I_CITY_CODE}, #{I_SERVICE_ID}, #{I_CUSTOMER_ID}, #{OUT:OUT_F_CUST_NAME}, #{OUT:OUT_F_GENDER}, #{OUT:OUT_F_DUTY}, #{OUT:OUT_F_PRODUCT_NAME}, #{OUT:OUT_F_POINT_VALUE}, #{OUT:OUT_F_STATUS}, #{OUT:ON_FLAG}, #{OUT:OS_PROMPT} )} </value> </entry> <entry key="updateUser" > <value&