Expensive,
I have the classes below.
I'm having trouble creating a TreeResource, because in JSP I'm passing the parameters "Id Area" and "Description Tree", in the controller I'm getting an AreaArvoreClassification object (aac), which has the other classes in it, are coming null .
Is the class mapping wrong?
Note: In the database, the Area Table and Classification Tree, has a N to N relationship, so they have an associative table between them, which is called AreaArvoreClassification.
AreaArvoreClassification:
@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;
}
}
Arvore Classification
@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 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 "";
}