@RequestParam註解有三個參數分別是: value、 required、 defaultValuehtml
代碼:spring
@RequestMapping(value="test1", method = RequestMethod.GET)瀏覽器
public String reqTest1(@RequestParam("name") String name){springboot
return name;
}app
經過@RequestParam註解生命接收用戶傳入的參數,這樣當咱們在瀏覽器輸入http://localhost:8080/test1?name=123ide
不設置參數的keyui
例如:http://localhost/p/8324234spa
代碼以下:code
@RequestMapping(value="/test2/{id}", method = RequestMethod.GET)htm
public Integer reqTest2(@PathVariable("id") Integer id){
return id;
}
resources資源springboot默認只映射static、 template兩個文件夾下的文件
若是咱們要在resources下新建一個image資源,想要讓spring boot找到它,只需在項目主類中配置一下就好 @SpringBootApplication public class MyApplication extends WebMvcConfigurerAdapter{ public static void main(String[] args){ SpringApplication.run(MyApplication.class,args); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry){ super.addResourceHandlers(registry); //這種方式會在默認的基礎上增長,不會影響默認的方式 registry.addResourceHandler("/image/**").addResourceLocations("classpath:/image/"); } }