By implementing one of the Repository interfaces, the DAO will already have some basic CRUD
methods (and queries) defined and implemented
When Spring Data creates a new Repository implementation, it analyses all the methods defined by the interfaces and tries to automatically generate queries from the method names
Let's look at an example. Lets say I have this Entity and common annotations class
@Entity
public class Person {
@Id
private int idPerson;
@Column(name = "name", length = 50)
private String name;
}
Now I want to create a class that creates some basic CRUD operations for this entity (Create, read, update and delete), This will automatically generate the necessary methods.
public interface IPersonRepo extends JpaRepository<Person, Integer>{
}
Now you can call this repo to do basic SQL operations with the Person entitiy
@Controller
public class DemoController {
@Autowired
private IPersonRepo repo;
public void do Something() {
Person p = new Person();
p.setIdPerson(1);
p.setName("eliasmanj");
repo.save(p);
}
}