1
我正在试验Spring框架的MockMvc。要调用执行MockMvc的方法,我需要有一个进口如下静态库的导入如何在Java/Spring中工作?
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
部分代码
this.mockMvc.perform(get("/")).andExpect(view().name("homePage"));
我知道get方法是静态的,但它是我第一次看到进口有静态关键字。有人能够向我解释这一点吗?为什么需要static关键字?为什么只有方法被导入?我对此有点困惑。
[一个几乎相同的问题](https://stackoverflow.com/questions/14209169/static-import-in-java)在过去关闭。虽然我不知道为什么。 (尽管如此,它仍然有很好的答案。) – 5gon12eder
[“import”之后的“static”修饰符的含义是什么意思?](http://stackoverflow.com/questions/162187/what-does-the-static-modifier-后导入的意思) – zapl
它更短,然后编写'this.mockMvc.perform(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get(“/”))''没有导入:) – zapl