Mybatis

2017-12-18  本文已影响9人  icecrea
  1. dao参数:(HotelInfoModel model)
    mapper:
    parameterType="HotelInfoModel"
    #{hotelName}, #{city},#{price},#{levelEnum}

  2. dao, 参数:(@Param("model") HotelInfoModel model)
    mapper:
    parameterType: 无
    #{model.hotelName}, #{model.city},#{model.price},#{model.levelEnum}

  3. dao参数 (Map<String, Object> params)
    假设params中存放了key:“id"和“price"
    parameterType="map"
    #{price},#{id}

  4. dao参数 (@Param("map") Map<String, Ojbect> params)
    parameterType:无
    #{map.id}, #{map.price}

  5. dao参数(Map<String, Object> params)
    注:param中存放了key:“model"和"city"
    parameterType="map"
    #{model.price},#{model.id}, #{city}

  6. dao参数 (@Param("map") Map<String, Ojbect> params)
    parameterType:无
    #{map.model.id}, #{map.model.price}, #{map.city}

  7. dao参数 (List<Integer> ids)
    parameterType="java.util.List"
    <foreach collection="list" item="item" separator=",">
    #{item}

  8. dao参数(@Param("ids")List<Integer> ids)
    parameterType:无
    <foreach collection="ids" item="item" separator=",">
    #{item}

  9. dao参数(List<HotelInfoModels> models)
    parameterType="java.util.List"
    <foreach collection="list" item="item" separator=",">
    #{item.price}, #{item.hotelName}

  10. dao参数(@Param("hotelInfoModelList")List<HotelInfoModels>
    models)
    parameterType:无
    <foreach collection="hotelInfoModelList" item="item" separator=",">
    #{item.price}, #{item.hotelName}

  11. dao参数(@Param("hotleName") String hotelName,
    @Param("id") Integer id )
    parameterType:无
    #{hotelName} , #{id}


动态SQL

<if test="city != null and city !=''">
and city = #{city}
</if>
<if test="hotelName != null and hotelName !=''">
and hotel_name = #{hotelName}
</if>
<where>
<if test="city != null and city !=''">
and city = #{city}
</if>
<if test="hotelName != null and hotelName !=''">
and hotel_name = #{hotelName}
</if>
</where>
<set>
<if test="price != null and price > 0">
price = #{price},
</if>
<if test="levelEnum != null">
level = #{levelEnum},
</if>
</set>
<foreach collection="levelList" item="level" close=")"
open="(" separator=",">
#{level}
</foreach>
<choose>
<when test="hotelName != null and hotelName !=''">
where hotel_name = #{hotelName}
</when>
<when test="city != null and city !=''">
where city = #{city}
</when>
<otherwise>
</otherwise>
</choose>
上一篇 下一篇

猜你喜欢

热点阅读