@Enhances Grails控制器(@Enhances Grails Controller)
我有一个如此定义的特征:
@Enhances(ControllerArtefactHandler.TYPE) trait NullCheckTrait { def nullCheck(def object) { // code here } }
当我从我的控制器调用
nullCheck(foo)
,我得到No signature of method
异常的No signature of method
。 如果我在控制器上implements NullCheckTrait
,它工作正常。 我已经读过@Enhances
只有在我创建一个grails插件并将其放在那里时才会起作用。 我很好奇这是否是一个已知问题,并且有一种方法可以让@Enhances
与控制器使用相同的grails应用程序。I have a Trait defined like so:
@Enhances(ControllerArtefactHandler.TYPE) trait NullCheckTrait { def nullCheck(def object) { // code here } }
When I call
nullCheck(foo)
from my controller, I get theNo signature of method
exception. If Iimplements NullCheckTrait
on the controller, it works fine. I've read that@Enhances
will only work if I create a grails plugin and put the trait there. I'm curious if this is a known issue and if there is a way to get the@Enhances
to work from the same grails application as the controller.
原文:https://stackoverflow.com/questions/36228424
更新时间:2023-09-04 15:09
最满意答案
这应该这样做:
scala> import collection.JavaConverters._ import collection.JavaConverters._ scala> val x = Map(1 -> 2, 3 -> 4) x: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4) scala> val a: java.util.Dictionary[Int, Int] = new java.util.Hashtable(x.asJava) a: java.util.Dictionary[Int,Int] = {3=4, 1=2}
This should do it:
scala> import collection.JavaConverters._ import collection.JavaConverters._ scala> val x = Map(1 -> 2, 3 -> 4) x: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4) scala> val a: java.util.Dictionary[Int, Int] = new java.util.Hashtable(x.asJava) a: java.util.Dictionary[Int,Int] = {3=4, 1=2}
相关问答
更多-
您可以使用JavaConverters而不是JavaConversions显式指定要转换的JavaConversions如下所示: import scala.collection.JavaConverters._ def javaIt: java.util.Iterator[java.util.Map[String, Object]] = ??? def scalaIt = javaIt.asScala map {_.asScala} // Iterator[scala.collection.mutabl ...
-
如何通过java代码将java HashMap转换为不可变的Scala映射?(How to convert a java HashMap to immutable Scala map via java code?)[2023-07-04]
您可以使用JavaConverters执行此操作 import java.util.HashMap; import scala.Predef; import scala.Tuple2; import scala.collection.JavaConverters; import scala.collection.immutable.Map; public class ToScalaTest { public static Map toScalaMap(HashMap在Java中使用scala地图(Using scala map in Java)[2021-08-26]
HTH。 从Scala方面很容易做到。 scala> import collection.JavaConverters._ import collection.JavaConverters._ scala> val m = Map("one"->1) m: scala.collection.immutable.Map[String,Int] = Map(one -> 1) scala> val jm = m.asJava jm: java.util.Map[String,Int] = {one=1} ...如何通过java代码将java Map转换为不可变的Scala映射?(How to convert a java Map to immutable Scala map via java code?)[2024-02-29]
你的代码是正确的。 问题可能是您构建或运行代码的方式,或者您可能没有所有必需的导入。 以下适用于Eclipse和Scala 2.12的Scala IDE版本4.6.1: package org.soreadytohelp; import java.util.HashMap; import scala.Predef; import scala.Tuple2; import scala.collection.JavaConverters; import scala.collection.immutable. ...有没有更好的方法将Scala Map转换为Java Map?(Is there a better way to convert a Scala Map to Java Map?)[2023-03-28]
有一些对象JavaConverters可以帮到你: import scala.collection.JavaConverters.mapAsJavaMapConverter Map("param1"-> 1, "param2"-> 2).asJava //> res0: java.util.Map[String,Int] = {param1=1, param2=2} 编辑:使用通配符导入确实是一个糟糕的编程习惯,因为它们会混淆您的命名空间,并且可能会在范围中引入意外的隐式转换/值。 因此将通配符导入更改 ...如何使用java Map
where scala Map [String,Any]是否需要?(How to use java Map [2023-07-30]where scala Map[String, Any] is requred?) 可能是这样的: val jmap = new HashMap[String, Object] jmap.put("1", new Date) import scala.collection.JavaConverters._ val smap = jmap.asScala.mapValues(_.asInstanceOf[Any]).toMap test(smap) def test(m: Map[String, Any]): Unit = { println(m) ...这是一个类似的例子 假定数据结构和验证功能已定义 val myMap = Map(1 -> "Value1",2 -> "Value2") val time = System.currentTimeMillis def validate(str:String, time:Long) = true 然后直接翻译你的代码就可以了 myMap.filter(entry => validate(entry._2, time)).map(_._1).take(1) Here is a similar sampl ...Java:将遗留类型Dictionary的实例转换为Map(Java: Convert an instance of the legacy type Dictionary to a Map)[2022-07-24]
使用Guava和Java 8: IteratorkeysIter = Iterators.forEnumeration(dict.keys()); Map dictCopy = Maps.toMap(keysIter, dict::get); 纯Java 8中的替代方法: List keys = Collections.list(dict.keys()); Map dictCopy = keys.stream ... 你有两个问题:scala中的Map和List与java版本不同。 scala.collection.JavaConversions.mapAsScalaMap创建一个可变映射,所以使用可变映射,以下工作: import scala.collection.JavaConversions._ import scala.collection.mutable.Map val f = new java.util.LinkedHashMap[String, java.util.ArrayList[String]] v ...这应该这样做: scala> import collection.JavaConverters._ import collection.JavaConverters._ scala> val x = Map(1 -> 2, 3 -> 4) x: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4) scala> val a: java.util.Dictionary[Int, Int] = new java.util.Hashtabl ...相关文章
更多- Grails 应用的迷惑
- 第四章 Controller接口控制器详解(1)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解 (4)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解(5)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解(6)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解(2)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解(3)——跟着开涛学SpringMVC
- 第四章 Controller接口控制器详解(7 完)——跟着开涛学SpringMVC
- 第六章 注解式控制器详解(注解式控制器运行流程及处理器定义)——跟着开涛学SpringMVC
- Spring四种注解(@Component、@Repository、@Service、@Controller)的区别-java cms开发五
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)