Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Andras Madi-Szabo
Added: May 19, 2020 11:18 AM
Views: 125
Tags: beci vizsga
  1. import com.example.demo.models.User;
  2. import java.util.List;
  3. import org.springframework.stereotype.Service;
  4.  
  5. @Service
  6. public interface UserService {
  7.  
  8.   List<User> findAll();
  9.  
  10.   List<User> getUsersAgeGreaterThan(int age);
  11. }
  12.  
  13. ===============================
  14.  
  15. import com.example.demo.models.User;
  16. import com.example.demo.repositories.UserRepository;
  17. import java.util.List;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20.  
  21. @Service
  22. public class UserServiceImpl implements UserService{
  23.  
  24.   private UserRepository userRepository;
  25.  
  26.   @Autowired
  27.   public UserServiceImpl(UserRepository userRepository) {
  28.     this.userRepository = userRepository;
  29.   }
  30.  
  31.   @Override
  32.   public List<User> findAll() {
  33.     return userRepository.findAll();
  34.   }
  35.  
  36.   @Override
  37.   public List<User> getUsersAgeGreaterThan(int age) {
  38.     return userRepository.findAllByAgeGreaterThan(age);
  39.   }
  40. }
  41.