Search code examples
playframeworkjava-ee-7

does ModelAndView from Spring MVC have an equivalent in Play framework


does ModelAndView have a direct equivalent in Play framework, and if not how could I recreate SpringMVC code in Play that uses this class, is their some simple code that could do it?


Solution

  • Not in the sense that you have a single container like ModelAndView. The purpose of ModelAndView (which is basically a Map<String, Object>) is mostly to have a single container where you put all your data that is used in the template later on and give each of those data pieces a name. In Play you just give your template all your objects for your template directly.

    An example in Play could look like:

    public Result index() {
      // Somehow instantiate anObject and anotherObject
      return ok(views.html.Controller.index(anObject, anotherObject));
    }
    

    And your template index.html.scala would start with the following:

    @(anObject: AnObjectType, anotherObject: AnotherObjectType)