1

I know that BeanPropertyRowMapper<>() can wrap fields comparing database fields to Class fields by name. But why when I'm using keyword "AS" i get an error.

jdbcTemplate code

   public Book showBook(int id) {
        return jdbcTemplate.query("SELECT books.id , books.name, books.author, books.year, books.people_id as peopleId, people.id as personId, people.name as personName FROM books LEFT JOIN people ON books.people_id = people.id WHERE books.id = ?",
                        new Object[]{id}, new BeanPropertyRowMapper<>(Book.class))
                .stream().findAny().orElse(null);
    }

Class fields

  private int id;

    @NotEmpty (message = "Name should not be empty")
    @Size (min = 2, max = 255, message = "Name should be correct")
    private String name;

    @NotEmpty (message = "Field author should not be empty")
    @Size (min = 2, max = 255, message = "Field author should be correct")
    private String author;

    @Min(value = 0)
    private int year;

    private int peopleId;

    private int personId;
    private String personName;
Vandal
  • 21
  • 2

0 Answers0