1
在我的控制器,以下使用@GetMapping作品:为什么@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";
}
我和春天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();
}
}
谷歌搜索结果:
- Add support for @GetMapping, @PostMapping etc. introduced in Spring 4.3 in ControllerLinkBuilder #471
- GetMapping and PostMapping annotations Ask
github上源:lbfreeze-blog-develop
你试过在'essayId:'后删除空格吗? (另外,你不需要编写'value =') – bphilipnyc
@bphilipnyc它在'essayId:'后面删除空格后有效 –