私はこのエラーを取得する私のフォームを送信しようとしているときは、よく私は、オブジェクト「status_product」を作成する必要がオブジェクト= 'statutProduits'の検証に失敗しました。エラー数:2
ホワイトレーベルのエラーページ
このアプリケーションはのための明示的なマッピングを持っていません/ error、これはフォールバックとして が表示されています。
木曜日12月7日04:07:23 GMT + 01:00 2017予期しないエラー (type = Bad Request、status = 400)が発生しました。 object = 'statutProduits'の検証に失敗しました。エラー数:2
エラーページに2つの検証エラーが表示されています。私はこの時点でかなり失われています。うまくいけば、誰かが私を助けることができる、それは私が現時点で進歩を妨げている。
StatutProduitsクラス:
package com.example.demo.entities;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author G557437
*/
@Entity
@Table(name = "STATUT_PRODUITS", catalog = "", schema = "PACKOUT")
public class StatutProduits 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)
@NotNull
@Column(name = "ID_STATUT_PRODUIT")
private BigDecimal idStatutProduit;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 45)
@Column(name = "CODE")
private String code;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 45)
@Column(name = "LIBELLE")
private String libelle;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 10)
@Column(name = "CREE_PAR")
private String creePar;
@Column(name = "DATE_CREATION")
@Temporal(TemporalType.TIMESTAMP)
private Date dateCreation;
@Size(max = 10)
@Column(name = "MAJ_PAR")
private String majPar;
@Column(name = "DATE_MAJ")
@Temporal(TemporalType.TIMESTAMP)
private Date dateMaj;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idStatutProduit")
private List<Produits> produitsList;
public StatutProduits() {
}
public StatutProduits(BigDecimal idStatutProduit) {
this.idStatutProduit = idStatutProduit;
}
public StatutProduits(BigDecimal idStatutProduit, String code, String libelle, String creePar) {
this.idStatutProduit = idStatutProduit;
this.code = code;
this.libelle = libelle;
this.creePar = creePar;
}
public BigDecimal getIdStatutProduit() {
return idStatutProduit;
}
public void setIdStatutProduit(BigDecimal idStatutProduit) {
this.idStatutProduit = idStatutProduit;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getCreePar() {
return creePar;
}
public void setCreePar(String creePar) {
this.creePar = creePar;
}
public Date getDateCreation() {
return dateCreation;
}
public void setDateCreation(Date dateCreation) {
this.dateCreation = dateCreation;
}
public String getMajPar() {
return majPar;
}
public void setMajPar(String majPar) {
this.majPar = majPar;
}
public Date getDateMaj() {
return dateMaj;
}
public void setDateMaj(Date dateMaj) {
this.dateMaj = dateMaj;
}
public List<Produits> getProduitsList() {
return produitsList;
}
public void setProduitsList(List<Produits> produitsList) {
this.produitsList = produitsList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idStatutProduit != null ? idStatutProduit.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 StatutProduits)) {
return false;
}
StatutProduits other = (StatutProduits) object;
if ((this.idStatutProduit == null && other.idStatutProduit != null) || (this.idStatutProduit != null && !this.idStatutProduit.equals(other.idStatutProduit))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.sagemcom.tn.entities.StatutProduits[ idStatutProduit=" + idStatutProduit + " ]";
}
}
コントローラクラス:
package com.example.demo.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.dao.StatutProduitsRepository;
import com.example.demo.entities.StatutProduits;
@Controller
public class StatutProduitsController {
@Autowired
StatutProduitsRepository statutproduitsrepository ;
@RequestMapping(value="/form", method=RequestMethod.GET)
public String formStatProduit(Model model) {
model.addAttribute("statproduit",new StatutProduits());
return "FormStatutProduit";
}
@RequestMapping(value="/save", method=RequestMethod.POST)
public String save(Model model, StatutProduits statproduit) {
statutproduitsrepository.save(statproduit);
return "Confirmation";
}
}
thymleaf:あなたのC言語で
<body>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">Statut d'un produit</div>
<div class="panel-body">
<form th:action="@{save}" method="post">
<div class="form-group">
<label class="control-label">ID</label>
<input class="form-control" type="number" name="idStatutProduit"
th:value="${statproduit.idStatutProduit}"/>
</div>
<div class="form-group">
<label class="control-label">Code</label>
<input class="form-control" type="text" name="code"
th:value="${statproduit.code}"/>
</div>
<div class="form-group">
<label class="control-label">Cree par</label>
<input class="form-control" type="text" name="creePar"
th:value="${statproduit.creePar}"/>
</div>
<div class="form-group">
<label class="control-label">Date creation</label>
<input class="form-control" type="date" name="dateCreation"
th:value="${statproduit.dateCreation}"/>
</div>
<div class="form-group">
<label class="control-label">Date maj</label>
<input class="form-control" type="date" name="dateMaj"
th:value="${statproduit.dateMaj}"/>
</div>
<div class="form-group">
<label class="control-label">Libelle</label>
<input class="form-control" type="text" name="libelle"
th:value="${statproduit.libelle}"/>
</div>
<div class="form-group">
<label class="control-label">Maj par</label>
<input class="form-control" type="text" name="majPar"
th:value="${statproduit.majPar}"/>
</div>
<div>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
</body>
ホワイトレーベルのエラーページ を使用して、コントローラの状況を確認するので、あなたが、フォールバックとしてこれを見ています。 Thu Dec 07 04:50:31 GMT + 01:00 2017 予期しないエラーが発生しました(type = Internal Server Error、status = 500)。 SpringEL式を評価している例外: "statproduit.idStatutProduit"(FormStatutProduit:22) –
if条件に "error"を返しましたか? –
'@ NotNull'アノテーションを' idStatutProduit'から削除すると、データベースからauto_increment値が生成されるはずです。手動でauto_incrementを使用したくない場合は、 –