I'm new on Java environment (Spring Boot), and try to manipulate the injections. I have a table Section, a Section can have a parent or not, but if a Section Object is parent we have to be able to list of its childrenSection.
This is my Service
@Override
public SectionDTO addSectionByParent(SectionDTO sectionDTO, Long parentId) {
log.warn(" Checking the theParentSectionId:={}",parentId);
Section parent = sectionRepository.findById(parentId).orElseThrow(() -> new RuntimeException("SectionParent not found exception"));
Section section = sectionMapper.fromSectionDTO(sectionDTO);
section.setParentSection(parent);
Section addSection = sectionRepository.save(section);
return sectionMapper.fromSection(addSection);
}
This is my Controller
@GetMapping("/newa/{varId}")
public ModelAndView newSectionByParentId(@PathVariable Long varId){
ModelAndView mav = new ModelAndView("detail/forma");
SectionDTO sectionDTO = new SectionDTO();
SectionDTO sectionParent = sectionService.showSection(varId);
mav.addObject("detail",sectionDTO);
mav.addObject("pro",sectionParent);
return mav;
}
@PostMapping("/savingx")
public String savingx(@ModelAttribute("section") @Valid SectionDTO sectionDTO, BindingResult bindingResult, @RequestParam(value = "parentId", required = false) Long parentId){
SectionDTO sectionParent = sectionService.showSection(parentId);
String returnValue;
if (bindingResult.hasErrors()) {
return "project/forma";
}
System.out.println("******************* parentId : "+ parentId);
if (sectionParent != null) {
sectionDTO.setParentId(sectionParent.getParentId());
sectionService.addSectionByParent(sectionDTO, sectionParent.getProductId());
}
returnValue = "redirect:/product/detail/by/parent/{sectionId}";
return returnValue;
}
When running this Controller, this is the error I have
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
nothing explicit
Please may u explain me what's going wrong ??