Return HTML or JSON to the Spring controller method

I am wondering how to return HTML or JSON to the same method depending on the logic in the Spring controller method. I did it in .NET, just need to know how to do it in Spring.

    UserModel user = new UserModel();       
    user.setFirstName("Michael");
    user.setLastName("Flynn");

    model.getList().add(user);
    model.setSearchTerm("test");

    if(true)
    {
        return new ModelAndView("controls/tables/users", "model", model);
    }
    else
        return model;
+3
source share
2 answers

I needed to find out recently, and I got lucky with this blog from SpringSource.

0
source

Source: https://habr.com/ru/post/1790081/


All Articles