Passing model data to the view
As of now, we have implemented a very simple HomeCotroller
, and tested it. But in the web application, we have also passed model data to the view layer. That model data we passed in the model (in a simple word, it is Map
), and that model is returned by the controller along with logical view name. As you already know, Spring MVC supports several return types of the handler method. Let's see the following example:
package com.packt.patterninspring.chapter10.bankapp.web.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import com.packt.patterninspring.chapter10.bankapp.model.Account; import com.packt.patterninspring.chapter10.bankapp.service.AccountService; ...