Java 为什么';t@Getmapping在某些情况下可以工作吗?
在我的控制器中,@GetMapping的以下用法有效:Java 为什么';t@Getmapping在某些情况下可以工作吗?,java,spring,spring-mvc,Java,Spring,Spring Mvc,在我的控制器中,@GetMapping的以下用法有效: @GetMapping(value = "/new") public String newEssay(){ return "articles/essay_new"; } 但它不是这样工作的: @GetMapping(value = "/essays/{essayId: [0-9]+}") //@RequestMapping(value = "/essays/{essayId:[0-9]+}", method = RequestMe
@GetMapping(value = "/new")
public String newEssay(){
return "articles/essay_new";
}
但它不是这样工作的:
@GetMapping(value = "/essays/{essayId: [0-9]+}")
//@RequestMapping(value = "/essays/{essayId:[0-9]+}", method = RequestMethod.GET)
public String getEssay(Model model,
@PathVariable("essayId") long essayId) throws NoFindException, ForBiddenException, ParseException {
JsEssay jsEssay = jsBiz.get(JsEssay.class, essayId);
model.addAttribute("jsEssay", jsEssay);
return "articles/essay";
}
我用Spring 4.3.3和5.0.0.M5进行了尝试
配置:
@Configuration
@ComponentScan( basePackages = {"me.freezehome.blog"},
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)
}
)
public class RootConfig {
}
@Configuration
@EnableWebMvc
@Import({WebSecurityConfig.class})
public class WebConfig extends WebMvcConfigurerAdapter{
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping(){
return new RequestMappingHandlerMapping();
}
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter(){
return new RequestMappingHandlerAdapter();
}
}
谷歌搜索结果:
github源代码:请删除
essayId:
另外,您不需要为
@GetMapping
编写value=
,您是否尝试过删除essayId:
之后的空格?(另外,您不需要编写value=
)@bphilipnyc在我删除essayId: