在我的控制器中,以下@GetMapping的使用有效:
@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();
}
}
Google结果:
github来源:lbfreeze-blog-develop
答案 0 :(得分:1)
请删除essayId:
此外,您无需为value =
撰写@GetMapping
。