Skip to content

Instantly share code, notes, and snippets.

@bytestree
Created September 11, 2016 19:29
Show Gist options
  • Save bytestree/ef68b8578696dae5c5b4afde7aed4a8b to your computer and use it in GitHub Desktop.
Save bytestree/ef68b8578696dae5c5b4afde7aed4a8b to your computer and use it in GitHub Desktop.
Service layer for Restful Web Service using CRUDService interface for CRUD operations.
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);
}
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);
}
}
package com.bytestree.restful.service;
import com.bytestree.restful.model.Employee;
public interface EmployeeService extends CRUDService<Employee> {
}
@bytestree
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment