Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

[Bug] Não está encontrando a pagina de listar

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:

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

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";
    }
}
2 respostas

Aqui vou mostrar onde o codigo HTML está:

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

E aqui o codigo HTML:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Customer List</title>
</head>
<body>
<h1>Customer List</h1>
<table>
  <thead>
      <th>Name</th>
      <th>Date of Birdth</th>
      <th>Age</th>
      <th>CPF</th>
      <th>Email</th>
      <th>Telephone Number</th>
      <th>Password</th>
      <th>Balance</th>
  </thead>
  <tbody>
    <tr th:each="client : ${list}">
        <td th:text="${client.name}"></td>
        <td th:text="${client.dateOfBirdth}"></td>
        <td th:text="${client.age}"></td>
        <td th:text="${client.cpf}"></td>
        <td th:text="${client.email}"></td>
        <td th:text="${client.telephoneNumber}"></td>
        <td th:text="${client.password}"></td>
        <td th:text="${client.balance}"></td>
    </tr>
  </tbody>
</table>
</body>
</html>
solução!

Oi!

Acho que o problema está nessa coluna da página:

<td th:text="${client.dateOfBirdth}"></td>

O nome do atributo está escrito errado e com isso deu erro 500 no navegador.