In Spring MVC, how to send information to the view (.jsp) without using ModelAndView?

5

I'm developing a web application in Spring MVC.

I have a method that returns a list (java.util.List) and needs to pass it to the view (.jsp), however without updating the page.

I would like to know some other way to pass the Java information to the view, but without using ModelAndView, because when I use the page it is updated.

    
asked by anonymous 25.09.2015 / 18:48

1 answer

2

As stated in the comment, you need Ajax to avoid page loading.

An example using Jquery:

$.ajax({
    url: '/lista',
    success: function(data) {
         //Aqui você recebe sua lista
    }
});

Your controller would look like this:

@ResponseBody//O spring vai retornar sua lista como texto, vai traduzir para Json
@RequestMapping(value = "/lista")
public List<Item> listagem() {
    //Aqui você retorna sua lista contendo os objetos
    return listaDao.findAll();
}
    
15.06.2017 / 17:48