在 IntelliJ IDEA 中查找注释
我可以使用 SSR(结构搜索和替换)轻松找到项目中某些注释的所有提及。例如,我有以下基于 spring 的代码:
class DashboardController {
@RequestMapping("/dashboard")
public void doDashboard() {
[...]
}
}
如果我按模式搜索 org.springframework.web.bind.annotation.RequestMapping ,我会找到我的代码。但是,如果我想查找带有参数化注释的方法,因此只查找带有“/dashboard”url 注释 @RequestMapping
的方法,该怎么办?
我可以简单地通过 @RequestMapping("/dashboard")
字符串进行搜索,但注释可以通过多种方式编写:
@RequestMapping("/dashboard")
@RequestMapping(value = "/dashboard", method = {RequestMethod.POST})
@RequestMapping(headers = "content-type=application/*", value = "/dashboard")
等等。
I can easily find all mentions of some annotation in my project using SSR (structural search and replace). For example I have following spring based code:
class DashboardController {
@RequestMapping("/dashboard")
public void doDashboard() {
[...]
}
}
If I search by pattern org.springframework.web.bind.annotation.RequestMapping
than I will find my code. But what if I want to find methods annotated with parametrized annotation, so find only method with annotations @RequestMapping
for "/dashboard" url?
I can simply search by @RequestMapping("/dashboard")
string, but annotation can be written in several ways:
@RequestMapping("/dashboard")
@RequestMapping(value = "/dashboard", method = {RequestMethod.POST})
@RequestMapping(headers = "content-type=application/*", value = "/dashboard")
etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 IntelliJ IDEA 14 中使用结构搜索和替换。复制现有模板带注释的方法并将“/dashboard”作为参数添加到注释中,如下所示:
您可能还想编辑 $Annotation$ 变量并给它文本/正则表达式“RequestMapping”
这应该找到注释的所有可能格式(仅在方法上)。
Use Structural Search and Replace in IntelliJ IDEA 14. Copy the existing template annotated methods and add "/dashboard" as an argument to the annotation like so:
You might also want to edit the $Annotation$ variable and give it the text/regexp "RequestMapping"
This should find all possible formats of the annotation (on methods only).
你为什么不搜索这个:
Why don't you search this :
为什么不直接对
@RequestMapping("/dashboard")
进行文本搜索,它不太可能给出那么多误报。Why not just do a text search for
@RequestMapping("/dashboard")
, its unlikely to give that many false positives.