在 MyBatis 中,如果你想要返回 int 类型的值,可以通过以下方法实现:
修改你的映射文件(mapper.xml)中的 SQL 查询语句。确保你的查询语句返回一个整数值。例如: SELECT COUNT(*) FROM your_table</select>这里,resultType 属性设置为 java.lang.Integer,表示查询结果将被转换为 Integer 类型。
public interface YourMapper { int countRecords();}在你的 DAO 或服务类中调用此方法。例如:@Autowiredprivate YourMapper yourMapper;public int getRecordCount() { return yourMapper.countRecords();}这样,当你调用 getRecordCount() 方法时,它将返回一个 int 类型的值,表示查询结果。


