【发布时间】:2015-09-21 23:01:32
【问题描述】:
我正在试验 Spring 框架的 MockMvc。要调用 MockMvc 的 perform 方法,我需要导入如下
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
部分代码
this.mockMvc.perform(get("/")).andExpect(view().name("homePage"));
我知道 get 方法是静态的,但这是我第一次看到 import 有 static 关键字。有人可以向我解释吗?为什么需要静态关键字?为什么只导入方法?我对此有点困惑。
【问题讨论】:
-
An almost identical question 过去已关闭。虽然我真的不知道为什么。 (不过它有很好的答案。)
-
它比写
this.mockMvc.perform(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get("/"))更短:) -
@zapl 2013 年 1 月的问题被关闭为“不是一个真正的问题”,2013 年 7 月的问题得分 +141。我明白了……
-
@5gon12eder 是的,有时它相当随意。尤其是简短回答的简短问题
标签: java spring junit spring-test spring-test-mvc