0

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 ??

Sany
  • 27
  • 4
  • no Exeption on IntelliJ, but on the browser I have Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. – Sany Jul 20 '23 at 13:53
  • this article might be helpful to you https://stackoverflow.com/questions/31134333/this-application-has-no-explicit-mapping-for-error – Black Bear Jul 20 '23 at 18:32

2 Answers2

0

Make sure that your main class is in a root package above other classes.

When you run a Spring Boot Application, (i.e. a class annotated with @SpringBootApplication), Spring will only scan the classes below your main class package.

com
   +- APP
         +- Application.java  <--- your main class should be here, above your controller classes
         |
         +- model
         |   +- user.java
         +- controller
             +- UserController.java
Avinash Gupta
  • 208
  • 5
  • 18
0

Sorry If I took a lot of time to answer, for this code, I was doing something showing me that I didn't understand the concept of injection.

finally, this was the code I was suppose to put in my Controller, something very simple:

@PostMapping("/savingx/{parentId}")
public String savingxx(@ModelAttribute("section") SectionDTO sectionDTO, @PathVariable Long parentId, BindingResult bindingResult, Model model){
    sectionService.addSectionByParent(sectionDTO, parentId);
        returnValue= "redirect:/product/detail/by/parent/{parentId}";
}

Thanks a lot for your contributions

Sany
  • 27
  • 4