使用Scala中的aspectj修改方法参数值(Modify a method parameter value using aspectj in Scala)
我有一种情况,我需要在scala中使用aspectj修改方法参数值。 我正在使用@Before注释来获取字段。
@Before("execution (* com.myapp.EmployeeController.delete(..))") def checkIfWorkflowEnabled(joinPoint: ProceedingJoinPoint): Object = { //get the fields and modify oen field //check some condition and if success, update the isActive field to false //then proceed with what was going on before }
我的控制器方法:
def delete(id:Long, isActive:Boolean)= { ??? }
但我无法使用aspectj更新字段'isActive'。
编辑:
正如Andy所说,我明白我们只能在around方法中修改方法args。 现在,我有另一个疑问。 在around方法中,是否会在实际方法调用之前和之后执行方面? 如何在删除方法执行之前修改方法args然后像往常一样继续。 并且在完成delete方法之后,调用其他一些方法。
I have a situation where I need to modify the method parameter value using aspectj in scala. I am using @Before annotation to get the fields.
@Before("execution (* com.myapp.EmployeeController.delete(..))") def checkIfWorkflowEnabled(joinPoint: ProceedingJoinPoint): Object = { //get the fields and modify oen field //check some condition and if success, update the isActive field to false //then proceed with what was going on before }
My Controller method:
def delete(id:Long, isActive:Boolean)= { ??? }
But I am not able to update the field 'isActive' using aspectj.
EDIT:
As Andy said, I understood that we can modify the method args only in around method. Now, I have another doubt. In around method, will the aspect be executed before and after the actual method invocation? How can I modify the method args before the delete method execution and then just proceed as usual. And after completion of the delete method, invoke some other method.?
原文:https://stackoverflow.com/questions/28560059
最满意答案
“s”是问题,它不是javascript正则表达式的有效修饰符。 唯一有效的修饰符是/ g(全局)/ i(不区分大小写)和/ m(多行)。
The "s" is the problem, it's not a valid modifier for javascript regular expressions. The only valid modifiers are /g (global) /i (case-insensitive) and /m (multi-line).
相关问答
更多-
没有区别。 它们在功能上是相同的。 有趣的是,如果您使用[而不是[[ ,实际上由于评估顺序而导致可检测到的差异: [ -s "$file1" -a "$file1" -nt "$(echo side effect >&2)" ] [ -s "$file1" ] && [ "$file1" -nt "$(echo side effect >&2)" ] 在这种情况下,第一行将打印“副作用”,而第二行不打印。 但是,这只是[而不是[[ ]] 。 There is no difference. They' ...
-
test1警告出现,test2警报没有 - 它们之间的正则表达式无效?(test1 alert appears, test2 alert doesn't - invalid regex between them?)[2023-01-14]
“s”是问题,它不是javascript正则表达式的有效修饰符。 唯一有效的修饰符是/ g(全局)/ i(不区分大小写)和/ m(多行)。 The "s" is the problem, it's not a valid modifier for javascript regular expressions. The only valid modifiers are /g (global) /i (case-insensitive) and /m (multi-line). -
它看起来像这样执行: (test1, test2, test3) = ("3"), (test4 = "4"), (test5 = "5"), (test6 = "6") # Equivalent: test1 = "3" test2 = test4 = "4" test3 = test5 = "5" ; test6 = "6" It looks like it's executing like this: (test1, test2, test3) = ("3"), (test4 = "4 ...
-
添加开始模式^ /^[a-z\d ,]+$/i.test(user_input) 否则,只有在该行末尾匹配时才进行测试。 试试这里: regexpal Add the start pattern ^ /^[a-z\d ,]+$/i.test(user_input) Otherwise you test only if you match at the end of the line. Try here: regexpal
-
jQuery正则表达式测试(jQuery regex test)[2021-09-05]
你是什么意思“它似乎不起作用”? 我刚刚测试了你的例子,它按预期工作。 唯一的问题是你试图在字符串内的任何地方找到数字模式。 这意味着你的正则表达式接受像abc3.4def这样的东西。 但是我想你想要字符串只包含一个十进制数字? 然后你必须在开头和结尾添加^和$符号,告诉test你要匹配整个字符串。 所以正则表达式成为: /^\d+(\.\d{1,2})?$/ 这是你的问题吗? 如果没有,我可以发布一个对我有用的完整网页,如果它可以对你有任何帮助。 What do you mean by “it does ... -
jQuery正则表达式检查字段的工作,但警报消息不会改变(jQuery Regex Check on field works but alert message doesn't change)[2023-07-30]
好的,所以我很快找到了解决方案 - 这是因为我的函数在失败之前不会返回值。 需要添加一个return true; if语句之外。 希望这可以帮助任何有类似问题的人:) Ok, so I found the solution rather quickly - it's because my function doesn't return a value until it fails. Needed to add a return true; outside of the if statement. Hope ... -
查找所有实例并显示警报 - 第2部分,现在使用正则表达式(Find all instances and display alert - part 2, now with regex)[2022-06-14]
答案就像优雅一样简单: var val = document.getElementById("Textbox1").value; if(!/[^0-9!@#$%^&*()+=;./{}|:<>?\[\]\\\'\"]{7}/.test(val)) { // handle invalid value } 这将测试字符串的长度是7个字符,并且在“^”之后的括号内不包含任何字符(也有些字符使用“\”进行转义)。 你可以在控制台中测试: /[^0-9!@#$%^&*()+=;./{}|:<>?\[\]\\ ... -
PHP Codeigniter解析数组([0] => test2 [1] => test1)(PHP Codeigniter parsing array ( [0] => test2 [1] => test1))[2024-01-27]
你可以做一个简单的重映射功能: $out = array(); foreach ($blog_entries as $index => $array) { $out[] = array('title' => $array[$index], 'body' => $array['body']); } 样本输出: array(5) { [0]=> array(2) { ["title"]=> string(7) "Title 1" ["body"]=> strin ... -
如果启用了extglobs,则此代码仅在语法上有效。 使用shopt -s extglob启用它们: shopt -s extglob search() { grep foobar ~/!(test1|test2) } 据推测,你的init文件已经在运行这个命令(例如extglobs最终为你的交互式会话开启),但是在函数的定义之后。 This code is only syntactically valid if extglobs are enabled. Use shopt -s extglob ...
-
尝试这个。 你有一些大括号没有正确关闭,你的相等检查也没有正确完成。 你的小提琴也没有导入jQuery。 var reg = new RegExp("^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$"); $('#button1').on('click', function() { var walletCheck = $('#wallet').val(); if (reg.test(walletCheck)) { alert("Valid addre ...