在 MyBatis 中,如果你想要返回 int 类型的值,可以通过以下方法实现:
SELECT COUNT(*) FROM your_table
</select>
这里,resultType
属性设置为 java.lang.Integer
,表示查询结果将被转换为 Integer 类型。
public interface YourMapper {
int countRecords();
}
@Autowired
private YourMapper yourMapper;
public int getRecordCount() {
return yourMapper.countRecords();
}
这样,当你调用 getRecordCount()
方法时,它将返回一个 int 类型的值,表示查询结果。