First of all, remember to put this in the section head
te tu jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
and add as dependency https://mvnrepository.com/artifact/javax.servlet/jstl/1.2
.
Then there are several options.
Option 1 :
In public String listDBUser(Map<String, Object> map)
you do not receive an object of type Map<String, Object>
as an argument, but ModelMap
or Model
.
@Controller
public class DBUserController {
@Autowired
private DBUserService dbuserService;
@RequestMapping("/")
public String listDBUser(ModelMap map) { // <-- recibir argumento de tipo ModelMap
map.addAttribute("DBUserList", dbuserService.listDBUser()); // <-- adicionar la lista en el atributo DBUserList
return "DBUser"; // <-- suponinendo que "DBUser" es el nombre de tu vista
}
}
Option 2 :
You do not return String
of method listDBUser
, but ModelAndView
You do not need to send a Map
as a parameter to the listDBUser
method (service in url /
).
driver
@Controller
public class DBUserController {
@Autowired
private DBUserService dbuserService;
@RequestMapping("/")
public ModelAndView listDBUser() { // <-- quitar argumento aqui y cambiar retorno a ModelAndView
// crear objeto ModelAndView para retornar
ModelAndView modelAndView = new ModelAndView("DBUser"); // <-- suponinendo que "DBUser" es el nombre de tu vista
modelAndView.addObject("DBUserList", dbuserService.listDBUser());
return modelAndView;
}
}
This excellent tutorial explains these concepts.