我正在使用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/