1
Expensive,
I have the classes below.
I am having trouble creating a tree classification, because in JSP I am passing the parameters "Id Area" and "Tree Description", in the controller I am receiving an Areaarvoreclassification object (aac), which has the other classes in it, only that they are coming null.
Class mapping is wrong?
Note: In the database, the Table Area and Tree Classification, has a relation N to N, therefore they have an associative table between them, which is called Areaarvoreclassification.
Areaarvoreclassificacao:
@Entity
@Table(name="areas_has_arvore_classificacao")
public class AreaArvoreClassificacao {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@ManyToOne
@JoinColumn(name="area_id")
private Area area;
@ManyToOne
@JoinColumn(name="arvore_classificacao_id")
private ArvoreClassificacao arvoreClassificacao;
}
Area:
@Entity
@Table(name="area")
public class Area {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@NotNull
@Column(name="descricao")
@Size(max=100)
private String descricao;
@NotNull
@Column(name="status")
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
Tree cultivation
@Entity
@Table(name="arvore_classificacao")
public class ArvoreClassificacao {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column (name="id")
private int id;
@NotNull
@Column(name="descricao")
private String descricao;
@NotNull
@Column(name="status")
private String status;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
Part of the JSP:
<div class="col-lg-12 mb-3">
<!-- INCLUIR O SELECT QUE IRA LISTAR AS ÁREAS -->
<label for="area.id">Escolha a área:</label>
<select class="form-control" name="Area.id" id="area.id" required>
<option value=""></option>
<c:forEach var="area" items="${areas }">
<option value="${area.id }">${area.descricao }</option>
</c:forEach>
</select>
</div>
<div class="col-lg-12 mb-3">
<label for="arvoreClassificacao.descricao">Descrição Arvore:</label><br>
<input type="text" name="ArvoreClassificacao.descricao" id="arvoreClassificacao.descricao" class="form-control" placeholder="Exemplo: Conhecimento - Cancelou serviço indevidamente" required>
</div>
<div class="col-lg-12 mb-3">
<button type="submit" class="btn btnForm btn-lg btn-block">Criar!</button>
</div>
Controller
@RequestMapping("CriarArvoreClassificacao")
public String criarArvore(Model model, AreaArvoreClassificacao aac) throws IOException{
// DEBUGAR PARA VER O QUE TA CHEGANDO OU SE TA CHEGANDO ALGO
System.out.println(aac);
return "";
}