File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed
src/com/luv2code/springdemo/mvc Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 11package com .luv2code .springdemo .mvc ;
22
33
4+ import javax .validation .constraints .Max ;
5+ import javax .validation .constraints .Min ;
46import javax .validation .constraints .NotNull ;
57import javax .validation .constraints .Size ;
68
@@ -9,9 +11,13 @@ public class Customer {
911 private String firstName ;
1012
1113 @ NotNull (message ="is required" )
12- @ Size (min =3 , message ="is required" )
14+ @ Size (min =1 , message ="is required" )
1315 private String lastName ;
1416
17+ @ Min (value =0 , message = "must be greater than or equal to zero" )
18+ @ Max (value =10 , message = "must be less than or equal to 10" )
19+ private int freePasses ;
20+
1521 public String getFirstName () {
1622 return firstName ;
1723 }
@@ -27,4 +33,12 @@ public String getLastName() {
2733 public void setLastName (String lastName ) {
2834 this .lastName = lastName ;
2935 }
36+
37+ public int getFreePasses () {
38+ return freePasses ;
39+ }
40+
41+ public void setFreePasses (int freePasses ) {
42+ this .freePasses = freePasses ;
43+ }
3044}
Original file line number Diff line number Diff line change @@ -35,9 +35,6 @@ public String showForm(Model model) {
3535 @ RequestMapping ("/processForm" )
3636 public String processForm (@ Valid @ ModelAttribute ("customer" ) Customer customer ,
3737 BindingResult bindingResult ) {
38-
39- System .out .println ("Last name: |" + customer .getLastName () + "|" );
40-
4138 if (bindingResult .hasErrors ()) {
4239 return "customer-form" ;
4340 } else {
Original file line number Diff line number Diff line change 99<body >
1010
1111 The customer is confirmed: ${ customer. firstName } ${ customer. lastName }
12+
1213 <br ><br >
1314
15+ Free passes: ${ customer. freePasses }
16+
1417</body >
1518
1619</html >
Original file line number Diff line number Diff line change 2525
2626 <br ><br >
2727
28+ Free passes: <form:input path =" freePasses" />
29+ <form:errors path =" freePasses" cssClass =" error" />
30+
31+ <br ><br >
32+
2833 <input type =" submit" value =" Submit" />
2934
3035 </form:form >
You can’t perform that action at this time.
0 commit comments