Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Sep 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.