Created
September 11, 2016 19:29
-
-
Save bytestree/ef68b8578696dae5c5b4afde7aed4a8b to your computer and use it in GitHub Desktop.
Service layer for Restful Web Service using CRUDService interface for CRUD operations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytestree.restful.service; | |
import java.io.Serializable; | |
import java.util.List; | |
public interface CRUDService<E> { | |
E save(E entity); | |
E getById(Serializable id); | |
List<E> getAll(); | |
void delete(Serializable id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytestree.restful.service; | |
import java.io.Serializable; | |
import java.util.List; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import com.bytestree.restful.model.Employee; | |
import com.bytestree.restful.repository.EmployeeRepository; | |
@Service | |
public class DefaultEmployeeService implements EmployeeService { | |
@Autowired | |
private EmployeeRepository employeeRepository; | |
@Override | |
public Employee save(Employee entity) { | |
return employeeRepository.save(entity); | |
} | |
@Override | |
public Employee getById(Serializable id) { | |
return employeeRepository.findOne((Long) id); | |
} | |
@Override | |
public List<Employee> getAll() { | |
return employeeRepository.findAll(); | |
} | |
@Override | |
public void delete(Serializable id) { | |
employeeRepository.delete((Long) id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytestree.restful.service; | |
import com.bytestree.restful.model.Employee; | |
public interface EmployeeService extends CRUDService<Employee> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For complete example refer RESTful Web Service CRUD Operations with Spring Boot