-1
I have a Java Spring MVC application, with Hibernate and JPA and HTML interface.
I have Two forms that depend on the Notebooks class registered and its attributes.
The forms have the following names, registration, change.
In the first registration form I enter the data of a new Notebook, detail only some fields such as id, numberCaderno, date, whoDigited, whoRecebeu and n°Notebooks, only this and save in the database and a new ID is created for this record.
When I do a search, in the id=1 case that was generated by the system, a form is displayed with the data of the previous form saved, these data are filled in what I do is just add new data in this second form, filling in the new data, has a checkbox in this form with the attributes statusPendentes and statusFinalized where I choose Pending or Finished, so I have it saved in the database. let’s say I opted for the checkbox statusFinalized statusFinalized in the database.
When I do the search again, in case id=1 it will fall on the same page to change, detail if I typed in the search id=1 it has to return a message on the screen, "This notebook is finished can not be changed"because I registered in the previous register as status.
Method ID of Class Controllercaderno that is called when I do a search by ID and shows the results of the form, both for statusPendentes or statusFinalized, if it is finalized, have to return the message "Este caderno bla bla", at the moment is returning the message for both as many statusPendent as statusFinalized.?
@GetMapping("id")
public String buscarNumeroID(@Valid CadernosCadastrados objeto, Model model, boolean statusPendentes, boolean statusFinalizados, Long id) {
List<CadernosCadastrados> cadernos = daoCadernosCadastrados.buscarNumeroID(id);
if(cadernos.equals(cadernos) != statusFinalizados) {
model.addAttribute("mensagem", "Este caderno está finalizado não
pode ser alterado!");
}
if(cadernos.equals(cadernos) != statusPendentes) {
model.addAttribute("cadernos", cadernos);
return "public/alterar";
}
return "public/sucessos";
}
Dao’s ID method, where I search the ID data saved in the database.
public List<CadernosCadastrados> buscarID(Long id) {
TypedQuery<CadernosCadastrados> query = entityManager.createQuery(
"SELECT d FROM CadernosCadastrados d WHERE d.id = :id order by id desc", CadernosCadastrados.class);
query.setParameter("id", id);
return query.getResultList();
}
Method to change the Controllercaderno class, where I bring the list and have the new records saved from the previous form.
@RequestMapping("alterar")
public String alterar(CadernosCadastrados objeto, Long id, BindingResult result, Model model, boolean statusPendentes, boolean statusFinalizados) {
List<CadernosCadastrados> cadernos = daoCadernosCadastrados.buscarNumeroID(id);
daoCadernosCadastrados.alterar(objeto);
return "public/sucessos";
}
Method dao Change, from the Controllercaderno class where I save the data from the previous form and save the data in the database.
public void alter(Notebooks registered object) {
entityManager.merge(objeto);
}
Here you search the notebook by the right number? List<Notessested> notebooks = from theCadernosCasted.SearchNumerCadern(numberCadern); Does the Notessested object then have two attributes statusPendent and statusFinalized? So what if one of the two attributes is null return different pages? Sorry, I can’t understand very well.
– Kaique Dias
So friend I put these attributes because when calling in the bank, and checks if it is Pending or Finished. i created this normal attribute in the Notebook class with String, the best solution is to make an Enum is not.
– Dickinson