springmvc + mybatis 遍历Map

spring的application.xml中

数据源:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- enterpriseUser数据库 -->
<bean id="enterpriseUserDataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${td.jdbc.enterpriseuser.driverClassName}"/>
<property name="url" value="${td.jdbc.enterpriseuser.url}"/>
<property name="username" value="${td.jdbc.enterpriseuser.username}"/>
<property name="password" value="${td.jdbc.enterpriseuser.password}"/>
<property name="initialSize" value="${td.jdbc.enterpriseuser.initialSize}"/>
<property name="maxTotal" value="${td.jdbc.enterpriseuser.maxActive}"/>
<property name="maxIdle" value="${td.jdbc.enterpriseuser.maxIdle}"/>
<property name="minIdle" value="${td.jdbc.enterpriseuser.minIdle}"/>
<property name="testOnBorrow" value="${td.jdbc.enterpriseuser.testOnBorrow}"/>
<property name="validationQuery" value="${td.jdbc.enterpriseuser.validationQuery}"/>
</bean>

sessionFactory:

1
2
3
4
5
6
7
8
bean id="enterpriseSqlFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据库连接池 -->
<property name="dataSource" ref="enterpriseDataSource" />
<!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml" />
<!-- 扫描sql配置文件:mapper需要的xml文件 -->
<property name="mapperLocations" value="classpath:mybatis/enterprise_mapper/*.xml" />
</bean>

Mapper.xml中的一个查询:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<select id="queryBitmapIsolateParams" resultType="java.util.Map" parameterType="java.util.Map">
<!-- 具体的sql -->
${sql}
<!-- 具体参数 -->
<where>
<if test="params != null">
<foreach collection="params.keys" item="key" separator="and">
<choose>
<when test="#{params[#{key}]} == null"> `${key}` IS NULL </when>
<otherwise> `${key}` = #{params[${key}]} </otherwise>
</choose>
</foreach>
</if>
</where>
</select>
本文结束啦感谢您的阅读

本文标题:springmvc + mybatis 遍历Map

文章作者:Smartfoot

原始链接:http://blog.bestsmartfoot.top/2018/08/20/a4/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

公众号