-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerController
41 lines (30 loc) · 1.1 KB
/
customerController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.luv2code.springdemo.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import jakarta.validation.Valid;
@Controller
@RequestMapping("/customer")
public class CustomerController {
@RequestMapping("/showForm")
public String showForm(Model model) {
Customer thecustomer=new Customer();
model.addAttribute("customer",thecustomer);
//first one is name and the second one is value
return "customer-form";
}
@RequestMapping("/processForm")
public String processForm(@Valid @ModelAttribute("customer") Customer thecustomer,BindingResult theresult,Errors error)
{
System.out.printf("[",thecustomer.getLastName(),"]");
System.out.println(thecustomer.getFreePasses());
if(theresult.hasErrors()) {
System.out.println("!!!");
return "customer-form";}
else {
return "customer-confirmation";}
}
}