为什么@Getmapping在某些情况下不起作用?

时间:2017-03-07 01:42:42

标签: 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 = 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

1 个答案:

答案 0 :(得分:1)

请删除essayId:

之后的空格

此外,您无需为value =撰写@GetMapping