mybatis-3
mybatis-3 copied to clipboard
mybatis get LimitSegment.rowCount incorrectly
MyBatis version
3.4.6
Database vendor and version
mysql 5.6.16-log mysql.connector.version 8.0.11
Test case or example project
CREATE TABLE TABLE_DEMO
(
id bigint auto_increment comment '主键 ID' primary key,
shop_lng varchar(32) null comment '店铺经度',
shop_lat varchar(32) null comment '店铺纬度',
);
INSERT INTO TABLE_DEMO (id, shop_lng,shop_lat) VALUES (1, '120.003446','30.280146');
List<Map<String, Object>> query(
@Param(value = "maxLng") BigDecimal maxLng,
@Param(value = "minLng") BigDecimal minLng,
@Param(value = "maxLat") BigDecimal maxLat,
@Param(value = "minLat") BigDecimal minLat,
@Param(value = "limitSize") Integer limitSize);
select id, shop_lng,shop_lat from table_demo where
CAST(t.shop_lng AS DECIMAL(10,6))<= #{maxLng,jdbcType=DECIMAL}
and
CAST(t.shop_lng AS DECIMAL(10,6))>= #{minLng,jdbcType=DECIMAL}
and
CAST(t.shop_lat AS DECIMAL(10,6))<= #{maxLat,jdbcType=DECIMAL}
and
CAST(t.shop_lat AS DECIMAL(10,6))>= #{minLat,jdbcType=DECIMAL}
limit #{limitSize}
Steps to reproduce
public List<Map<String, Object>> query() {
List<ShippingShopGeoInfo> list = mapper.query(
new BigDecima("120.003446"),new BigDecimal("120.003446"),new BigDecimal("30.280146"),new BigDecimal("30.280146"),100
);
return list;
}
Expected result
result: [{id: 1, "shopLng": "120.003446","shopLat": "30.280146"}]
Actual result
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
please check you paramterType is right if you follow you paramterType like that :
<select id="query" resultType="map" parameterType="int">
</select>
this will throw java.math.BigDecimal cannot be cast to java.lang.Integer
- how to fix: remove parameterType="int"
please check you paramterType is right if you follow you paramterType like that :
<select id="query" resultType="map" parameterType="int"> </select>
this will throw java.math.BigDecimal cannot be cast to java.lang.Integer
- how to fix: remove parameterType="int"
but in actually,I use the param annotation inject params.,so I didn't write the paramterType , and if i use "$" to fill the limit, it can output a expected result
Hello @riceorfreedom ,
I couldn't reproduce it. Please provide it as an executable project like these and share it on your GitHub repo.
No response. Closing.