2017-03-07 70 views
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(); 
    } 
} 

谷歌搜索结果:

github上源:lbfreeze-blog-develop

+0

你试过在'essayId:'后删除空格吗? (另外,你不需要编写'value =') – bphilipnyc

+0

@bphilipnyc它在'essayId:'后面删除空格后有效 –

回答

1

请后essayId:

同时删除的空间,你不需要写value =@GetMapping

相关问题