Mybatis @MapKey /IN foreach

XML

    <resultMap id="BaseResultMap" type="com.vrm.entity.VehicleInfo">
        <result column="id" property="id" jdbcType="BIGINT" />
        <result column="frame_no" property="frameNo" jdbcType="VARCHAR"/>
        <result column="vehicle_no" property="vehicleNo" jdbcType="VARCHAR"/>
        <result column="version" property="version" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="test" resultMap="BaseResultMap">
        SELECT id,frame_no ,vehicle_no ,version 
        FROM t_v_info 
        WHERE id IN
        <foreach collection="vehicleIds" item="vehicleId" open="(" close=")" separator=",">
            #{vehicleId}
        </foreach>
    </select>

DAO

    @MapKey("frameNo")
    Map<String,VehicleInfo> test(@Param("vehicleIds") List<Long> vehicleIds);

Entity

@Data
public class VehicleInfo implements Serializable{

    private static final long serialVersionUID = 1L;

    private Long id;
    private String frameNo;
    private String vehicleNo;
    private Integer version;
}
posted @ 2020-04-18 11:46  是谁扭曲了时空  阅读(228)  评论(0编辑  收藏  举报