Transform MVC to layered Architecture in Spring Boot

245 Views Asked by At

I have a classic Spring Boot app, you can see the structure: enter image description here

I am trying to modify it to have at the end a Layered Architecture. The problem is that to isolate the layers we must to use APIs between layers,so I have no idea how to create API's for each Layer, maybe you can give some examples? Here is the classic structure of Layered Arch. enter image description here

And this is my structure.

enter image description here

Some codes from my app:

@Controller
public class UserController {
…
@PostMapping("/saveUser")
public String saveUser(@ModelAttribute("user") User theUser…){
    theUser.setPassword(value);
    userService.save(theUser);
}
…
}

...

@Service
@Component("userService")
public class UserServiceImpl implements Services<User> {
…
@Override
@Transactional
public void save(User theUser) {
   theUser.setPassword(passwordEncoder.encode(theUser.getPassword()));
   userDao.saveUser(theUser);

}
…
}

...

@RestController
@RequestMapping("/api")
public class AnnonceRestController {
@GetMapping("/announce-all")
public List<Annonce> findAll() {
    return annonceService.findAll();
}


@PostMapping("/announce-create")
public Annonce addAnnonce(@RequestBody Annonce theAnnonce) {

    theAnnonce.setId(0);
    theAnnonce.setDate(null);
    annonceService.save(theAnnonce);

    return theAnnonce;
}
0

There are 0 best solutions below