当mybatis使用between…and…该如何操作
首先我们来看看mysql中使用between…and…
查询年龄在10~30这个区间内的数量
那么如何在mybatis中实现between…and…呢?
1、service层,方法中含有两个形参,分别表示起始年龄和结束年龄(区间的左右)
int ageStatistics(Integer startAge,Integer endAge);
2、dao层,使用@Param传参
int ageStatistics(@Param("startAge")Integer startAge,@Param("endAge")Integer endAge);
3、mapper.xml中
<!--属性与表字段映射-->
<resultMap id="treeInfoMap" type="Map">
<result column="sample_area" jdbcType="VARCHAR" property="sample_area"/>
<result column="sample_region" jdbcType="VARCHAR" property="sample_region"/>
<result column="plant_type_title" jdbcType="VARCHAR" property="plant_type_title"/>
<result column="count(1)" property="num" jdbcType="VARCHAR" />
</resultMap>
<select id="ageStatistics" parameterType="Integer" resultType="Integer">
select count(1) from t_applet_map where plant_age BETWEEN #{startAge} and #{endAge}
</select>
测试接口效果
以上就是全部内容了,创作不易,求三连支持!!!