Repository in Spring Framework For Beginners

Repository in spring is classes use to interact with database, that is simplify as CRUD (create, read, update and delete). To make a class repository, you add a @Repository annotation to the interfaces, but you also need to extends one of spring repository class that is CrudRepository, JpaRepository or PagingAndSortingRepository. And you need to mention your DAO, for example.

public interface UserRepository extends JpaRepository<UserDao, Long> {

class UserDao{
private Long id;
private String name;

Actually that's enough, now you can use your repository anywhere you want, just inject that component, for example to find a user you can use it.

public Class UserController{

private UserRepository userRepository;

public List<UserDao> allUser(){
return userRepository.findAll();

The above class is an example on how to get all user expose by endpoint "user/findAll".


Popular posts from this blog

Is Nox Player a Malware? Nox Android Emulator

ASUS Battery Health Charging Software To Make Your Battery Life Longer

How To Uninstall Angular CLI, The Angular Framework

Flutter AppBar, With Icon, Title and Actions Link

ERROR 1348 Column Password Is Not Updatable When Updating MySQL Root Password