我正在使用Play 2.0.4框架,并且可以通过将其放在控制器部分中来成功创建一个接受Map[String, String]模板的模板:

Map<String, String> test = new HashMap<String, String>();
return ok(views.html.template.render(test));


并在template.scala.html中:

@(map : Map[String, String])


但是,如果将第一个String更改为Int(控制器部分为Integer),则会出现以下异常:

 error: method render in class template cannot be applied to given types;


是否可以在Play框架中定义Integer-> String映射,如果可以,如何实现?

编辑:
当我将控制器中的代码更改为:

Map<Integer, String> test = new HashMap<Integer, String>();


并在模板中执行以下操作:

@(map: Map[Int, String])

最佳答案

在模板中,您指定Map的键是scala.Int,但是给它一个以Map作为键的java.lang.Integer

解决方案是将模板中的行更改为

@(map: Map[Integer, String])

关于java - Play框架模板中的Map [Int,String],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15901587/

10-11 20:36
查看更多