Browse Source

新增selectSingle 查询单挑数据

周浩 9 năm trước cách đây
mục cha
commit
a5ab26b199

+ 14 - 1
hsweb-web-service-interface/src/main/java/org/hsweb/web/service/GenericService.java

@@ -8,7 +8,7 @@ import java.util.List;
 
 /**
  * 通用Service。继承了通用mapper的常用增删改查方法
- * <p/>
+ * <p>
  * Created by zh.sqy@qq.com on 2015-07-20 0020.
  */
 public interface GenericService<Po, Pk> {
@@ -96,4 +96,17 @@ public interface GenericService<Po, Pk> {
      */
     Po selectByPk(Pk pk) throws Exception;
 
+    /**
+     * 查询只返回单个结果
+     * @param param 查询条件
+     * @return 单个结果
+     * @throws Exception
+     */
+    default Po selectSingle(QueryParam param) throws Exception {
+        param.doPaging(0, 1);
+        List<Po> list = this.select(param);
+        if (list.size() == 0) return null;
+        else return list.get(0);
+    }
+
 }