title: EL1008E: Property or field 'username' cannot be found on object of type '...User' - maybe not public or not valid?
body: <p>As the title suggested, I am encountering some issues during some experiments with thymeleaf and spring. Here is the exception:</p>
  
  <pre><code>org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'username' cannot be found on object of type 'com.black.spring.boot.eventsharing.demo.domain.User' - maybe not public or not valid?
  </code></pre>
  
  <p>Here is my user controller:</p>
  
  <pre class="lang-java prettyprint-override"><code>@GetMapping
      public ModelAndView list(@RequestParam(value="async",required=false) boolean async,
                               @RequestParam(value="pageIndex",required=false,defaultValue="0") int pageIndex,
                               @RequestParam(value="pageSize",required=false,defaultValue="10") int pageSize,
                               @RequestParam(value="name",required=false,defaultValue="") String name,
                               Model model) {
  
          Pageable pageable = PageRequest.of(pageIndex, pageSize);
          Page&lt;User&gt; page = userService.listUsersByNameLike(name, pageable);
          List&lt;User&gt; list = page.getContent(); 
          model.addAttribute("page", page);
          model.addAttribute("userList", list);
          for (User user : list) {
              System.out.println("!!!!!!" + user.toString() + "!!!!!");
          }
          return new ModelAndView(async?"users/list :: #mainContainerRepleace":"users/list", "userModel", model);
      }
  </code></pre>
  
  <p>I have done some basic experiments when my code calls the controllers, here is the system print:</p>
  
  <pre><code>!!!!!!User{id=1, name='asd', email='asd@12', username='asd', password='asd', avatar='null'}!!!!!
  </code></pre>
  
  <p>Here is my html code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;tr th:each="user : ${userModel.userList}"&gt;
      &lt;td th:text="${user.id}"&gt;place_holder_id&lt;/td&gt;
      &lt;td th:text="${user.username}"&gt;place_holder_user_name&lt;/td&gt;
      &lt;td th:text="${user.name}"&gt;place_holder_name&lt;/td&gt;
      &lt;td th:text="${user.email}"&gt;place_holder_email&lt;/td&gt;
      &lt;td&gt; ...
  </code></pre>
  
  <p>Here is my User.java</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
      @NotEmpty(message = "Name should not be empty")
      @Size(min=2, max=20)
      @Column(nullable = false, length = 20)
      private String name;
  
      @NotEmpty(message = "Email should not be empty")
      @Size(max=50)
      @Email(message= "invalid email format" )
      @Column(nullable = false, length = 50, unique = true)
      private String email;
  
      @NotEmpty(message = "Username should not be empty")
      @Size(min=3, max=20)
      @Column(nullable = false, length = 20, unique = true)
      private String username;
  
      @NotEmpty(message = "Password should not be empty")
      @Size(max=100)
      @Column(length = 100)
      private String password;
  
      @Column(length = 200)
      private String avatar;
  
      protected User() {
      }
  
      public User(Long id, String name, String email, String username) {
          this.id = id;
          this.name = name;
          this.email = email;
          this.username = username;
      }
  
      public String getUserName() { return username; }
  
      public void setUserName(String username) { this.username = username; }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) { this.password = password; }
  
      public String getAvatar() { return avatar; }
  
      public void setAvatar(String avatar) { this.avatar = avatar; }
  
      public Long getId() { return id; }
  
      public void setId(Long id) { this.id = id; }
      public String getName() { return name; }
      public void setName(String name) { this.name = name; }
      public String getEmail() { return email; }
      public void setEmail(String email) { this.email = email; }
      @Override
      public String toString() {
          return "User{" +
                  "id=" + id +
                  ", name='" + name + '\'' +
                  ", email='" + email + '\'' +
                  ", username='" + username + '\'' +
                  ", password='" + password + '\'' +
                  ", avatar='" + avatar + '\'' +
                  '}';
      }
  }
  
  </code></pre>
  
  <p>I think the error message means that in my User, there is no attribute called "username", but I do have that variable. I am not sure what's wrong, any tips will be highly appreciated.</p>