Estou criando outro projeto pra ir treinando em quanto não sai o resto da formação. Só que na hora de abrir a pagina de listar ele apresenta esse erro:
Vou deixar o codigo abaixo:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode(of = "id")
@Entity
@Table(name = "tb_clients")
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private LocalDate dateOfBirth;
private Integer age;
private String cpf;
private String email;
private String telephoneNumber;
private String password;
private BigDecimal balance;
private Boolean active;
public Client(CustomerRegistrationData data) {
this.name = data.name();
this.dateOfBirth = data.dateOfBirth();
this.cpf = data.cpf();
this.email = data.email();
this.telephoneNumber = data.telephoneNumber();
this.password = data.password();
this.balance = BigDecimal.ZERO;
this.active = true;
}
}
@Service
public class ClientService {
@Autowired
private IClientRepository repository;
@Autowired
private List<ICustomerValidator> validator;
public Client create(CustomerRegistrationData data) {
var client = new Client(data);
client.setAge(calculateAge(client.getDateOfBirth()));
client.setTelephoneNumber(removePhoneNumberMask(client.getTelephoneNumber()));
client.setCpf(removeCpfMask(client.getCpf()));
validator.forEach(v -> v.validate(client));
return repository.save(client);
}
private int calculateAge(LocalDate dateOfBirth) {
LocalDate currentDate = LocalDate.now();
return Period.between(dateOfBirth, currentDate).getYears();
}
private String removePhoneNumberMask(String phoneNumber) {
if (phoneNumber != null) {
return phoneNumber.replaceAll("\\D", ""); // Removes all non-digit characters
}
return null;
}
private String removeCpfMask(String cpf) {
if (cpf != null) {
return cpf.replaceAll("\\D", ""); // Removes all non-digit characters
}
return null;
}
public List<Client> customerList() {
return repository.findAll();
}
}
@Controller
@RequestMapping("client")
public class ClientController {
@Autowired
private ClientService service;
@GetMapping("/form")
public String form() {
return "clients/form";
}
@GetMapping("/customerList")
public String customerList(Model model) {
model.addAttribute("list",service.customerList());
return "clients/customerList";
}
@PostMapping("/form")
@Transactional
public String register(CustomerRegistrationData data) {
Client client = service.create(data);
return "clients/form";
}
}