I have a REST service producing JSON and consuming JSON.
A lot of this are simple CRUD operations. My initial idea was to simply use the DAOs directly in the controller:
@ResponseBody()
@RequestMapping(value="/cars/{carID}", method = RequestMethod.PUT)
public Car saveCar(@PathVariable Long carId, @RequestBody Car car) {
carDAO.save(car);
return car
}
In this example, Car is a persistent @Entity and the save method is just a wrapper for EntityManger.persist();
I heard that it is generally a bad idea to use persistence classes in the controllers for your API. Is that true? If so, why and what is the alternative?
Is this a good idea? Do I need a service layer? If not when would I need it?
Assume the application grows and the operations get even more complex, would I then need a service layer?