aspectj切入点匹配特定的注释参数值(aspectj pointcut matching a specific annotation parameter value)
我正在尝试围绕使用自定义注释注释的方法定义切入点。 注释有一个参数,我想在切入点定义中包含一个检查。
这是注释:
public @interface MyAnno { String[] types; }
如何应用注释的示例:
public class MyClass { @MyAnno(types={"type1", "type2"}) public void doSomething() { // ... } @MyAnno(types={"type3"}) public void doSomethingElse() { // ... } }
现在我想有两个切入点定义,根据注释的内容选择这两种方法。
在注释本身上创建切入点相对容易:
@Pointcut("@annotation(myAnno)") public void pointcutAnno(MyAnno myAnno) { } @Pointcut("execution(* *(..)) && pointcutAnno(myAnno)") public void pointcut(MyAnno myAnno) { }
这将匹配@MyAnno的每次出现。 但是我如何定义两个切入点,一个匹配
@MyAnno
,types
包含"type1"
,另一个匹配@MyAnno
,types
包含"type3"
I'm trying to define a pointcut around a method annotated with a custom annotation. The annotation has one parameter that I would like to include a check in the pointcut definition.
This is the annotation:
public @interface MyAnno { String[] types; }
An example of how the annotation could be applied:
public class MyClass { @MyAnno(types={"type1", "type2"}) public void doSomething() { // ... } @MyAnno(types={"type3"}) public void doSomethingElse() { // ... } }
Now I would like to have two pointcut definitions which select those two methods, based on the contents of the annotation.
Creating a pointcut on the annotation itself is relatively easy:
@Pointcut("@annotation(myAnno)") public void pointcutAnno(MyAnno myAnno) { } @Pointcut("execution(* *(..)) && pointcutAnno(myAnno)") public void pointcut(MyAnno myAnno) { }
This will match every occurrence of the of @MyAnno. But how can I define two pointcuts, one matching
@MyAnno
withtypes
containing"type1"
and the other matching@MyAnno
withtypes
containing"type3"
原文:https://stackoverflow.com/questions/47459062
最满意答案
这是你想要的吗?
= f.select :parallax_id, options_for_select(@parallax.map {|p| [p.title, p.id, {'data-icon' => p.image }]})
Is this what you want?
= f.select :parallax_id, options_for_select(@parallax.map {|p| [p.title, p.id, {'data-icon' => p.image }]})
相关问答
更多-
如何正确使用collection_select以及自定义关联(How to correctly use collection_select along with custom associations)[2022-08-09]
这里的问题是表单结构将查找:eyes属性并为其分配select将为其发送的字符串值。 但是Rails引擎期望这个属性的EyeColor对象,而不是String 。 您应该更改外键的名称: belongs_to :eye, class_name: "EyeColor", :foreign_key: "eye_id" 或更好: belongs_to :eyecolor 有了这个,你需要一个名为eye_colors的表,一个名为EyeColor的类和一个外键eye_color_id 。 顺便提问的问题: ht ... -
首先,您可以添加到Route类: class Route < ActiveRecord::Base has_many :trips end 首先,我想建议你使用装饰器,在视图中插入模型不是最好的做法。 其次,您可以使用gem'rapper ' ,在RouteDecorator类中,您可以添加用于创建要使用或显示的内容的函数。 第三,你最好使用:至少在REST风格中使用路径会更好: /routes ...这就是collection_select的工作方式。 collection_select的第一个参数是一个对象而不是一个方法 ,所以你的参数看起来就像那样。 将params[:search]更改为params[:search][:search]应该可以解决您的问题。 class StudentsController < ApplicationController def index if params[:search][:search] @students = Student.sea ...
如何在Rails中设置collection_select的HTML选项?(How do I set the HTML options for collection_select in Rails?)[2022-04-15]
许多Rails帮助器使用多个哈希参数。 第一个通常是控制帮助器本身的选项,第二个是html_options,您指定自定义ids,类等。 方法定义如下: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) 你会注意到params列表中的多个'= {}'。 要使用它,您要指定的第一组选项实际上必须括在大括号中: collection_select(:u ...Rails:如何在collection_select中添加自定义数据属性(Rails: How to add custom data-attributes in collection_select)[2023-03-30]
这是你想要的吗? = f.select :parallax_id, options_for_select(@parallax.map {|p| [p.title, p.id, {'data-icon' => p.image }]}) Is this what you want? = f.select :parallax_id, options_for_select(@parallax.map {|p| [p.title, p.id, {'data-icon' => p.image }]})我怀疑你的数据模型是解决这个问题的最佳方法(我建议使用line_items的订单模型)但是对于你给定的模型,这是解决方案: <%= f.select :quantity, ((0..@books.count).map {|i| [i,i] }) %> I doubt that your data model is the best way to solve this problem (I would suggest an order model with line_items) but for your ...首先,您需要了解有关控制器操作的更多信息 您可以在Rails指南中阅读它们 例如: def create @match = Match.create(match_params) @home_opponents = @match.home_opponents.create!(params[:match_opponents]) @away_opponents = @match.away_opponents.create!(params[:match_opponents]) if @match.s ...Rails 5 collection_select:在一列中显示多个属性(Rails 5 collection_select: Showing multiple attributes in one column)[2022-07-04]
请尝试以下代码 <%= f.collection_select :to_account_id, Account.all.map{|a| ["#{a.name} - #{a.owner.name}", a.id] } %> Try following code <%= f.collection_select :to_account_id, Account.all.map{|a| ["#{a.name} - #{a.owner.name}", a.id] } %>如何将onchange动作添加到collection_select?(How do you add onchange action to collection_select?)[2021-11-27]
我认为选项需要在哈希中(当前你有include_blank的部分)。 尝试改变这个 <%= collection_select(:sources, :source_id, Source.all, :id, :name, :include_blank => "Please select a source...", html_options = {:onchange => "updateTextArea()"} ) %> 对此 <%= collection_select(:sources, :source_i ...在Rails中更新嵌套的fields_for和collection_select(Updating nested fields_for and collection_select in Rails)[2022-01-14]
在blog_post_params添加id ,如下所示。 这对你有用。 def blog_post_params params.require(:blog_post).permit(:title, :content, :posted_by, :comments, :blog_pic, {categorizations_attributes: [:id,:category_id, :category_name]}) end Add id in blog_post_params as shown ...相关文章
更多- 【第六章】 AOP 之 6.5 AspectJ切入点语法详解 ——跟我学spring3
- Spring Data: a new perspective of data operations
- Becoming a data scientist
- hibernate中基于annotation(注解)的many2many双向
- hibernate中基于annotation(注解)的One2One双向
- hibernate中基于annotation(注解)的one2Many双向
- 基于annotation(注解)的hibernate4.1的入门初步
- 【第六章】 AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- Fading Like a Flower - Roxette
- 按钮样式
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。