【Mybatis】传Map与传String


ShipStatic ship=shipService.getShipInfoBymmsi(mmsi);
public interface ShipStaticMapper extends Mapper<ShipStatic> {
ShipStatic getShipinfoBymmsi(String mmsi);
}
<select id="getShipinfoBymmsi" parameterType="string" resultMap="BaseResultMap">
SELECT
*
FROM
ship_static
<where>
mmsi = #{mmsi}
</where>
</select>


public interface ShipImageMapper extends Mapper<ShipImage> {
List<ShipImage> getShipImageByMmsi(String mmsi);
List<ShipImage> getImagesByMMSI(Map<String,Object> params);
}
两种不同的方式:
1.传Map
 1 Map<String,Object> params=new HashMap<String, Object>();
 2 params.put("mmsi",mmsi);
 3 List<ShipImage> imageList=shipImageMapper.getImagesByMMSI(params);
 4 
 5 <select id="getImagesByMMSI" parameterType="java.util.Map" resultMap="BaseResultMap">
 6    SELECT a.*  from ship_image a
 7     <where>
 8         <if test="mmsi != null and mmsi!=''">
 9             and a.ship_id = #{mmsi}
10         </if>
11     </where>
12 </select>
2.传String
 1 List<ShipImage> images = shipImageMapper.getShipImageBymmsi(mmsi);
 2 
 3 <select id="getShipImageByMmsi" parameterType="string" resultMap="BaseResultMap">
 4     SELECT
 5     *
 6     FROM
 7     ship_image
 8     <where>
 9         ship_id = #{mmsi}
10     </where>
11 </select>

 

posted @ 2017-08-08 15:01  Legolas_4  阅读(571)  评论(0编辑  收藏  举报