Mybatis傳值方式

1)傳遞對象類型java

<!-- 插入 -->
<insert id="insert" parameterType="com.yujin.domain.Role">
    INSERT INTO t_roles(name,description) VALUES(#{name},#{description})
</insert>
public interface RoleDao {
    void insert(Role role);
 }

2)傳遞Map能夠傳遞多個參數app

<!-- Map傳遞參數 -->
    <select id="getByMap" parameterType="map" resultType="com.yujin.domain.Role">
        SELECT 
            id,name,description 
        FROM 
            t_roles r
        WHERE
            r.id=#{id}
    </select>

public interface RoleDao {  
    List<Role> getByMap(Map<String,Object> maps);
 }

3)企業開發Map的妙用dom

<select id="selectByTerm" parameterType="Map" resultMap="BaseResultMap">
        select * FROM order_detail
        <where>
            <if test="status!=null and status!='' ">
                and status=#{status}
            </if>
            <if test="isActivity!=null and isActivity!='' ">
                and is_activity=#{isActivity}
            </if>
            <if test="userId!=null and userId!='' ">
                and user_id=#{userId}
            </if>
            <if test="shopId!=null and shopId!='' ">
                and shop_id=#{shopId}
            </if>
            <if test="orderId!=null and orderId!='' ">
                and order_id=#{orderId}
            </if>
            <if test="goodsId!=null and goodsId!='' ">
                and goods_id=#{goodsId}
            </if>
            <if test="goodsProvalueId!=null and goodsProvalueId!='' ">
                and goods_provalue_id=#{goodsProvalueId}
            </if>
            <if test="test!=null and test!='' ">
                and #{test}
            </if>
            ORDER BY buy_date DESC
        </where>
        <if test="start!=null and end!=null">
            limit #{start},#{end}
        </if>
    </select>

package com.xtxq.dao.order;
import com.xtxq.domain.order.OrderDetail;
import java.util.Map;
public interface OrderDetailMapper {
     * @param  map
     * @return 
     */
    List<OrderDetail> selectByTerm(Map<String, Object> map);
}
相關文章
相關標籤/搜索