後端設定某個或多個字段作為表單校驗唯一性

2021-10-20 05:43:15 字數 1557 閱讀 8594

指定某一字段作為唯一校驗性主要邏輯:

獲取需要校驗的字段值和該物件的主鍵(為null時需要處理),在該字段值在sql中作為判斷條件進行查詢並且只獲取一條(limit 1),如果有一條記錄則說明存在,如果沒有則不存在;

第二判斷條件:則用於修改:排除本身

controller層
//屬性名稱 型別 編號 作為唯一校驗if(

!(tsmpropertytemplateservice.

checkpropertytemplateunique

(tsmpropertytemplate)))

service層
/**

* 校驗: 屬性名稱 型別 編號

** @param tsmpropertytemplate

* @title:checkpropertytemplateunique

* @description:用於校驗:屬性名稱 型別 編號

* @author:雲諾

* @date:2021/2/25

* @return:boolean

*/boolean

checkpropertytemplateunique

(tsmpropertytemplate tsmpropertytemplate)

;

serviceimp
@override

public

boolean

checkpropertytemplateunique

(tsmpropertytemplate template)

return

true

;}

/**

* 校驗

** @param name

* @param type

* @param code

* @return

*/tsmpropertytemplate checkdeptnameunique

(@param

("name"

) string name,

@param

("type"

) string type,

@param

("code"

) string code)

;

"checkdeptnameunique"

resulttype

="tsmpropertytemplate"

>

select id, `name`, `type`, dic_code, code, `describe`, remark, del_flag

where del_flag='0'

and name=# and type=# and code=$ limit 1

select

>

根據表單中的某個字段分割表單並選取欄位中的最大值

在乙個表中根據某個欄位的值來將表分割再選取其中的最大值。比如各個班級中的成績最高的乙個如 student sid classnum score 1 1 89 2 4 80 3 3 82 4 3 90 5 2 89 6 1 97 create table student select sid,clas...

SQL找某個字段最大的記錄或連線

有一種經常遇到的情況可以小結一下,比如乙個表中乙個account id對應多個loan id,這個時候找最大的loan id那條記錄就是形如 select distinct on account id loan id,from table order by account id,loan id de...

oracle中查詢某個欄位在哪些表中作為外來鍵

select from user cons columns cl where cl.column name 外來鍵的名稱 查詢表的外來鍵 包括名稱,引用表的表名和對應的鍵名,下面是分成多步查詢 select from user constraints c where c.constraint typ...