本文將介紹,SSM中mybatis 框架如何獲取Select Count(*)返回int 的值。
1. Service 代碼:
public boolean queryByunitclass(String unitclass, String unitsubclass) throws Exception {
int count = matceMachineUnitMapper.queryByunitclass(unitclass, unitsubclass);
if (count > 0) {
return true;
} else {
return false;
}
}
1
2
3
4
5
6
7
8
9
2. mybatis文件中resultType定義為”java.lang.Integer”:
<select id="queryByunitclass" resultType="java.lang.Integer">
SELECT COUNT(*) FROM unit
where unitclass = #{unitclass} and unitsubclass = #{unitsubclass}
</select>
1
2
3
4
3. DAO中Mapper java 代碼(接口文件中方法返回值寫成int,即可接收到):
/**
* 查詢該分類和子分類是否被使用,使用的個數
* @param unitclass
* @param unitsubclass
* @return
*/
public int queryByunitclass(@Param("unitclass") String unitclass, @Param("unitsubclass") String unitsubclass);
————————————————
版權聲明:本文為CSDN博主「直立行走的大瓶子」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weistin/article/details/79864150