Access the service layer from the controller

1

Hello,

I'm developing a REST web service that queries data from Apache Solr. I'm using Spring boot + date with Solr repositories. I do not know how to interconnect the service, repository, and controller layers.

I have the following structure:

Controller

Repository

Service

Aclassrepresentingtheconfiguration

Logs

How can the controller access the service layer?

Thank you.

    
asked by anonymous 24.04.2017 / 19:04

1 answer

0

I usually do the following:

The Controller accesses the Service and the Service accesses the Repository. Example:

Controller:

@RestController
public class TesteController {

     @Autowired
     private TesteService testeService;

     public void fazAlgumaCoisa() {
         List<Teste> testes = testeService.fazAlgumaCoisa();
         // mais codigo
     }
}

Service:

@Service
public class TesteService {

    @Autowired
    private TesteRepository testeRepository;

    public List<Teste> fazAlgumaCoisa() {
        testeRepository.findAll();
    }
}

Repository:

@Repository
public interface TesteRepository extends JpaRepository<Teste, Long> {

}
    
21.05.2017 / 23:00