给定多个like范围去模糊查询
<select id="getBanKuaiBylunpartID2" resultMap="BaseResultMap" parameterType="map" >
select
<include refid="###" />
from 表名
<where>
id = #{id'id,jdbcType=VARCHAR}
and
(
<foreach collection="这个是传过来的map" item="item" index="index" >
bname1 like CONCAT('%',#{item},'%') or
</foreach>
1=0
)
</where>
</select>
两表中属性1对多的关系查询
<resultMap id="BaseResultMap" type="com.carbbs.service.model.Modelone" >
<id column="id" property="id" jdbcType="INTEGER" />
<.....>
<collection property="otherbbs" ofType="com.carbbs.service.model.Modeltwo">
<id column="otherbbs_id" property="id" jdbcType="INTEGER"/>
<...>
</collection>
</resultMap>
在resultMap标签里使用collection
并且在model层的Modelone类中加入如下属性
private List<Modeltwo> modeltwo; 然后再添加set 和get 方法
然后用select关联查询
select
a.id,a.bankuaiid,
c.id as otherbbs_id,
from modelone a,modeltwo c
where a.bankuaiid = c.id
and
a.uid = #{uid,jdbcType=INTEGER}
上面是1对多的,下面是1对1的
也是在xml文件里的resultMap标签这次添加的是
<association property="###" column="bankuai_id" javaType="bankuai">
<id column="bankuai_id" property="id" jdbcType="INTEGER" />
</association>
这次只需在resultMap标签中的实体类model中添加BanKuai这个实体类属性
private BanKuai bankuai;同样的set和get方法
然后和上面一样的关联查询。