一,用Mapjava
Daoapp
public interface TopicUpdateDao { Topic selectByPrimaryKey(Integer id); List<Topic> selectNow(Map<String, Object> map); }
Mappercode
<select id="selectNow" resultMap="BaseResultMap" parameterType="java.util.Map"> select <include refid="Base_Column_List" /> from topic_update WHERE uptime = (SELECT MAX(uptime) FROM topic_update) ORDER BY rank LIMIT #{begin,jdbcType=INTEGER},#{size,jdbcType=INTEGER}; </select>
以前一直是用Map,忽然以为不太方便,我写的mapper,别人在service层调用我写的dao时不知道须要哪些参数,就查了一下有没有其余方法。xml
2、用@Param注解,这方法这样在调用dao层就知道须要哪些参数,很直观。class
Daodate
public interface TopicUpdateDao { Topic selectByPrimaryKey(Integer id); List<Topic> selectNow(@Param("begin") Integer begin, @Param("size") Integer size); }
Mapper.xmlList
<select id="selectNow" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from topic_update WHERE uptime = (SELECT MAX(uptime) FROM topic_update) ORDER BY rank LIMIT #{begin,jdbcType=INTEGER},#{size,jdbcType=INTEGER}; </select>
3、占位,dao层和上面同样多个参数,mapper用#{x}表示第几个参数,第一个是0,类推。select
<select id="selectNow" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from topic_update WHERE uptime = (SELECT MAX(uptime) FROM topic_update) ORDER BY rank LIMIT #{0},#{1}; </select>
这个方法不太直观。jdbc