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

Googleの検索結果:

githubのソース:lbfreeze-blog-develop

+0

あなたは 'essayId:'の後にスペースを削除しようとしましたか? (また、 'value ='を書く必要はありません) – bphilipnyc

+0

@bphilipnyc 'essayId:'の後のスペースを削除した後で動作します –

答えて

1

後にスペースを削除してくださいessayId:

@GetMappingに書き込む必要はありません。

関連する問題