Mybatis 采坑記錄--set標簽的使用


 

 <!--根據poi_info表的id和city_id更新flag_hinterland_flows的poi_id和city_id-->
    <select id="selectPoiAndCityId" parameterType="java.lang.Long" resultType="com.wormpex.gs.stat.service.dao.entity.baseinfo.PoiAndCityId">
        select n.id as poiId,n.city_id as cityId,n.code as code from poi_info n inner join flag_hinterland_flows m 
/*1用inner join,只返回滿足匹配條件的數據,減少數據庫io次數*/
on m.flag_code=n.code <where> <if test="id != null"> n.id<![CDATA[<=]]>#{id,jdbcType=BIGINT} </if> </where> </select> <update id="updatePoiAndCityId" parameterType="com.wormpex.gs.stat.service.dao.entity.baseinfo.PoiAndCityId" > update flag_hinterland_flows <set> poi_id=#{poiId,jdbcType=BIGINT}, <if test="cityId != null"> city_id=#{cityId,jdbcType=BIGINT}, </if> </set> /*2set標簽可以自動忽略if標簽中多余的逗號,但是,對於if標簽里面再嵌套一層if的時候,set標簽就不能自動忽略了*/ where /*3where放到set標簽外邊*/ flag_code=#{code,jdbcType=VARCHAR} </update>

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com