@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/"); } }