Mybatis使用between....and....操作

当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>

测试接口效果
在这里插入图片描述
以上就是全部内容了,创作不易,求三连支持!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值