Java-MyBatis-????????? MyBatis ??? in ?????????2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java-MyBatis-????????? MyBatis ??? in ?????????2相关的知识,希望对你有一定的参考价值。
?????????????????? and logs float name ?????? span inf user
ylbtech-Java-MyBatis-????????? MyBatis ??? in ?????????2 |
1.???????????? |
????????????
???SQL??????????????????????????????in???????????????????????????????????????:
select * from HealthCoupon where useType in ( ???4??? , ???3??? )
???????????????MyBatis????????????in??????,?????????????????????,???????????????:
Map<String, Object> selectByUserId(@Param("useType") String useType) <select id="selectByUserId" resultMap="BaseResultMap" parameterType="java.lang.String"> select * from HealthCoupon where useType in (#{useType,jdbcType=VARCHAR}) </select>
??????useType="2,3";???????????????,???????????????,??????MyBatis?????????????????????MyBatis????????????foreach????????????IN??????,foreach????????????:
foreach???????????? collection?????????????????????????????????List????????????map??????
?collection??? ?????????mapper.java???@Param??????????????????????????????
?item??? ???????????????????????????????????????????????????????????????????????????????????????????????????#{}????????????????????????
index???????????????????????????????????????????????????(??????)
open???????????? sql????????????????????????????????????()?????????
?close?????????
separator???????????????????????????????????????????????????????????????
????????????????????????????????????:
(???)???selectByIdSet(List idList)
????????????????????????List, ??????????????????collection???????????????????????? list
List<User> selectByIdSet(List idList); <select id="selectByIdSet" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> from t_user WHERE id IN <foreach collection="list" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </select>
(???)???List<User> selectByIdSet(String[] idList)
????????????????????????Array,??????????????????collection???????????????????????? array
List<User> selectByIdSet(String[] idList); <select id="selectByIdSet" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> from t_user WHERE id IN <foreach collection="array" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </select>
(???)?????????????????????
??????????????????????????????,?????????????????????????????????????????????@Param("xxx")??????????????????????????????????????????Map???????????????
3.1 @Param("xxx")??????
List<User> selectByIdSet(@Param("name")String name, @Param("ids")String[] idList); <select id="selectByIdSet" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List" /> from t_user WHERE name=#{name,jdbcType=VARCHAR} and id IN <foreach collection="idList" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </select>
3.2 Map??????
Map<String, Object> params = new HashMap<String, Object>(2); params.put("name", name); params.put("idList", ids); mapper.selectByIdSet(params); <select id="selectByIdSet" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from t_user where name = #{name} and ID in <foreach item="item" index="index" collection="idList" open="(" separator="," close=")"> #{item} </foreach> </select>
2.???????????? |
3.???????????? |
4.???????????? |
5.???????????? |
6.???????????? |
?????????ylbtech ?????????http://ylbtech.cnblogs.com/ ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? |
以上是关于Java-MyBatis-????????? MyBatis ??? in ?????????2的主要内容,如果未能解决你的问题,请参考以下文章
Java-MyBatis-????????? MyBatis ??? in ?????????2