WhiteLabel Erro

时间:2016-12-11 10:56:32

标签: java spring-mvc thymeleaf

我面临以下问题。我的应用程序无法识别User对象的属性。我收到以下错误:

Error

我的login.html

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
  <head>
      <title>Gamester</title>
      <meta charset="utf-8" />
      <link rel="stylesheet" th:href="@{css/style.css}" />
      <link rel="stylesheet" href="https://bootswatch.com/yeti/bootstrap.min.css" />
	  <link rel="shortcut icon" th:href="@{images/favicon.ico}" type="image/x-icon" />
  </head>
  <body>
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <div class="navbar-header">
            <img alt="Brand" th:src="@{images/logo.png}" />
        </div>
        <span class="navbar-text" style="font-size:22px">Gamester</span>
      </div>
        <!-- FORMULARIO DE LOGIN -->
	  <div class="form-login">
          <form th:action="@{/login}" method="POST">
                <input type="text" class="form-control form-control-login" id="inputEmail" name="username" placeholder="Email" />
                <input type="password" class="form-control form-control-login" id="inputPassword" name="password" placeholder="Password" />
                <button class="btn btn-default btn-lg btn-block form-control-login" id="inputEnviarLogin">Sign in</button>
          </form>
           <div class="alert alert-danger" th:if="${param.error}">
                Usuario ou Senha Incorretos
                <strong th:text="${param.error[0]}"></strong>
            </div>
	   </div>
    </nav>

	<div class="gamification">
	
	<img th:src="@{images/lateral.jpg}" />
	
	</div>
	
	
	
    <!--FORMULARIO DE CADASTRO -->
    <div class="login-home">
      <form class="form-horizontal" th:action="@{/usuario}" th:object="${usuario}" method="POST">
              <input type="hidden" th:field="*{idUsuario}" />
          <fieldset>
            <legend>Cadastre-se</legend>
            <div class="form-group">
              <div class="col-lg-10">
                <input type="text" class="form-control" th:field="*{nome}" placeholder="Nome" />
              </div>
            </div>
            <div class="form-group">
              <div class="col-lg-10">
                <input type="text" class="form-control" th:field="*{email}" placeholder="Email" />
              </div>
            </div>
            <div class="form-group">
              <div class="col-lg-10">
                <input type="text" class="form-control" placeholder="Reinsira o Email" />
              </div>
            </div>
            
            <p>
                <button type="submit" class="btn btn-success">Sign Up</button>
            </p>
            <div class="alert alert-success" th:if="${msg}">
                <strong>Sucesso!</strong> <span th:text="${msg}"></span>
            </div>
          </fieldset>
        </form>
    </div>
  </body>
</html>

我的班级Usuario。 要以表格形式发送的对象

 @Entity
       @Table(name = "USUARIO")
       public class Usuario implements Serializable {

    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @Column(name = "ID_USUARIO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_USUARIO")
    @SequenceGenerator(name = "SEQ_USUARIO", sequenceName = "SEQ_USUARIO", allocationSize = 1)
    private Long idUsuario;

    @Size(min = 1, max = 255, message = "Maximo 255 caracteres")
    @Basic(optional = false)
    @Column(name = "NOME")
    private String nome;

    @Basic(optional = false)
    @Column(name = "EMAIL")
    private String email;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUsuario")
    private List<Postagem> postagens;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUsuario1")
    private List<Amizade> listaAmizade;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUsuario2")
    private List<Amizade> listaAmizade2;

    public Usuario() {
    }

    public Usuario(Long idUsuario) {
        this.idUsuario = idUsuario;
    }

    public Usuario(Long idUsuario, String nome, String email) {
        this.idUsuario = idUsuario;
        this.nome = nome;
        this.email = email;
    }

    public Long getIdUsuario() {
        return this.idUsuario;
    }

    public void setIdUsuario(Long idUsuario) {
        this.idUsuario = idUsuario;
    }

    public String getNome() {
        return this.nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<Postagem> getPostagens() {
        return postagens;
    }

    public void setPostagens(List<Postagem> postagens) {
        this.postagens = postagens;
    }

    public List<Amizade> getListaAmizade() {
        return listaAmizade;
    }

    public void setAmizadeList(List<Amizade> listaAmizade2) {
        this.listaAmizade2 = listaAmizade2;
    }

    public List<Amizade> getListaAmizade2(){
        return this.listaAmizade2;
    }

    public void setAmizadeList2(List<Amizade> listaAmizade2) {
        this.listaAmizade2 = listaAmizade2;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUsuario != null ? idUsuario.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.idUsuario == null && other.idUsuario != null) || (this.idUsuario != null && !this.idUsuario.equals(other.idUsuario))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.crescer.social.entity.Usuario[ idUsuario=" + idUsuario + " ]";
    }

}

我的控制器,必须接收对象并写入数据库。

@Controller
@RequestMapping("/usuario")
public class UsuarioController {

    @Autowired
    UsuarioServico usuarioServico;



    @RequestMapping(method = RequestMethod.POST)
    @ModelAttribute("Usuario")
    public String save(@Valid Usuario usuario, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
        if (!bindingResult.hasErrors()) {
            usuarioServico.save(usuario);
            redirectAttributes.addFlashAttribute("msg", "Registro salvo com sucesso!");
            return "redirect:login";
        }
        return "login";
    }

}

0 个答案:

没有答案