Pārlūkot izejas kodu

Zad 2. Dodanie kotrolera i modyfikacja pól

smoczynskaj 6 gadus atpakaļ
vecāks
revīzija
253ef8bf6a

+ 40
- 12
initial/src/main/java/zad2ppkwu/Fields.java Parādīt failu

1
 package zad2ppkwu;
1
 package zad2ppkwu;
2
 
2
 
3
+import javafx.scene.control.Hyperlink;
4
+
5
+import javax.validation.constraints.Size;
6
+
3
 /**
7
 /**
4
  * Created by Justyna on 08.04.2018.
8
  * Created by Justyna on 08.04.2018.
5
  */
9
  */
6
 public class Fields {
10
 public class Fields {
7
     private long id;
11
     private long id;
12
+
13
+    @Size(min = 5, message = "E-mail must follow the pattern: address@example.com")
8
     private String mail;
14
     private String mail;
9
-    private int nip;
10
-    private int pesel;
11
-    private int regon;
12
-    private char postcode;
15
+
16
+    @Size(min = 10, max = 10, message = "NIP value must contain 10 digits")
17
+    private long nip;
18
+
19
+    @Size(min = 11, max = 11, message = "PESEL value must contain 11 digits")
20
+    private long pesel;
21
+
22
+    @Size(min = 9, max = 14, message = "REGON value must contain 9 or 14 digits")
23
+    private long regon;
24
+
25
+    @Size(min = 6, max = 6, message = "Postcode must follow the pattern: XX-XXX")
26
+    private String postcode;
27
+
28
+    public Fields() {
29
+        super();
30
+    }
31
+
32
+    public Fields(long id, String mail, long nip, long pesel, long regon, String postcode) {
33
+        super();
34
+        this.id = id;
35
+        this.mail = mail;
36
+        this.nip = nip;
37
+        this.pesel = pesel;
38
+        this.regon = regon;
39
+        this.postcode = postcode;
40
+    }
13
 
41
 
14
     public long getId() {
42
     public long getId() {
15
         return id;
43
         return id;
27
         this.mail = mail;
55
         this.mail = mail;
28
     }
56
     }
29
 
57
 
30
-    public int getNip() {
58
+    public long getNip() {
31
         return nip;
59
         return nip;
32
     }
60
     }
33
 
61
 
34
-    public void setNip(int nip) {
62
+    public void setNip(long nip) {
35
         this.nip = nip;
63
         this.nip = nip;
36
     }
64
     }
37
 
65
 
38
-    public int getPesel() {
66
+    public long getPesel() {
39
         return pesel;
67
         return pesel;
40
     }
68
     }
41
 
69
 
42
-    public void setPesel(int pesel) {
70
+    public void setPesel(long pesel) {
43
         this.pesel = pesel;
71
         this.pesel = pesel;
44
     }
72
     }
45
 
73
 
46
-    public int getRegon() {
74
+    public long getRegon() {
47
         return regon;
75
         return regon;
48
     }
76
     }
49
 
77
 
50
-    public void setRegon(int regon) {
78
+    public void setRegon(long regon) {
51
         this.regon = regon;
79
         this.regon = regon;
52
     }
80
     }
53
 
81
 
54
-    public char getPostcode() {
82
+    public String getPostcode() {
55
         return postcode;
83
         return postcode;
56
     }
84
     }
57
 
85
 
58
-    public void setPostcode(char postcode) {
86
+    public void setPostcode(String  postcode) {
59
         this.postcode = postcode;
87
         this.postcode = postcode;
60
     }
88
     }
61
 }
89
 }

+ 10
- 0
initial/src/main/java/zad2ppkwu/FormController.java Parādīt failu

1
 package zad2ppkwu;
1
 package zad2ppkwu;
2
 
2
 
3
+import javafx.scene.control.Hyperlink;
4
+import org.springframework.web.bind.annotation.*;
5
+
3
 /**
6
 /**
4
  * Created by Justyna on 08.04.2018.
7
  * Created by Justyna on 08.04.2018.
5
  */
8
  */
9
+
10
+@RestController
6
 public class FormController {
11
 public class FormController {
12
+
13
+    @RequestMapping(value = "/fields", method = RequestMethod.POST)
14
+    public Fields fields(@RequestParam Fields fields) {
15
+        return new Fields(1, "jankowalski@example.com", Long.parseLong("0123456789"), 12123423456L, Long.parseLong("098472839"), "01-100");
16
+    }
7
 }
17
 }