gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:51:43 24 4
gpt4 key购买 nike

在我的 Controller 中,@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();
}
}

谷歌结果:

github来源:lbfreeze-blog-develop

最佳答案

请删除essayId:后面的空格

此外,您不需要为 @GetMapping 编写 value =

关于java - 为什么 @Getmapping 在某些情况下不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42638707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com