In this recipe, we'll see how to call a DAO method from a controller class.
We will use the DAO class defined in the previous recipe and pretend that it has an add(User)
method. In the following recipes, we will write actual DAO methods.
Here are the steps to use a DAO method from a controller class:
In your controller class, add the DAO as an
@Autowired
field:@Controller public class UserController { @Autowired private UserDAO userDAO;
Use the DAO in any controller method:
userDAO.add(user);