服务器端验证示例?/ Java

时间:2017-08-04 20:26:33

标签: java hibernate validation spring-mvc server-side

我正在尝试创建一个执行客户端和服务器端验证的注册表单。我正在使用Spring MVC和Hibernate来执行此操作。我已经找到了客户端,但我对如何进行服务器端验证感到困惑?这是否可能与我想要实现的目标一致?

如果我没有意义,我道歉,我是一个相当新的程序员。如果需要更多信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

import javax.validation.constraints.Max; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.CreditCardNumber; import org.hibernate.validator.constraints.Email; public class User { @NotNull(message = "username cannot be null") @Size(min = 2, max = 15) private String username; @Max(100) private int age; @Email private String email; @CreditCardNumber private String creditCardNumber; // constructors, getters, setters } 可以满足验证服务器端字段的要求。

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-validator</artifactId>
   <version>5.4.1.Final</version>
</dependency>

Maven依赖项:

'start with sheet 1
 Sheets(1).Activate
 Dim rowStartSheet1, rowStartSheet2, lastRowSheet1, lastRowSheet2 As Integer

'change this variable if your row doesn't start on 2 as in this example for sheet1 and sheet2
rowStartSheet1 = 2
rowStartSheet2 = 2

'gets you the last row in sheet 1
 lastRowSheet1 = Cells(Rows.Count, 1).End(xlUp).Row

 'this entire for block is to check if a data row in sheet 1 is in sheet 2 and if so, copy and paste the rest of the data points
For i = rowStartSheet1 To lastRowSheet1

'case 1 where column C matches column A first time around (no duplicates)
'change this variable if sheet 2 starts on a different row
Sheets(2).Activate

lastRowSheet2 = Cells(Rows.Count, 1).End(xlUp).Row

'loops through sheet 2 column A to check if it matches what we want in sheet1 Column C
For ii = rowStartSheet2 To lastRowSheet2

    'inputs if found first time around
    If Sheets(1).Cells(i, 3) = Cells(ii, 1) And Cells(ii, 7) = "" Then
        Cells(ii, 7) = Sheets(1).Cells(i, 1)
        Cells(ii, 8) = Sheets(1).Cells(i, 2)
        Exit For

    'if sheet2 column G already has info in it, create a new row
    ElseIf Sheets(1).Cells(i, 3) = Cells(ii, 1) And Cells(ii, 7) <> "" Then
        Rows(ii).Select
        Selection.Insert Shift:=xlShiftDown
        Cells(ii, 1) = Sheets(1).Cells(i, 3)
        Cells(ii, 7) = Sheets(1).Cells(i, 1)
        Cells(ii, 8) = Sheets(1).Cells(i, 2)
        Exit For
    End If

 Next ii
 Next i
 End Sub