gpt4 book ai didi

java - 具有不同 url 但具有相同参数和相同方法功能的请求映射

转载 作者:行者123 更新时间:2023-12-02 01:14:13 25 4
gpt4 key购买 nike

下面是我的示例 Controller 方法,

    @RequestMapping(value = "/unsecure/support",  method = RequestMethod.GET)
public ResponseEntity<someDTO> getSupportNumber(@RequestParam(value = "countryId") Long countryId) {
someDTO contactNos = supportService.getSupportNumbers(countryId);
return new ResponseEntity<someDTO>(contactNos, HttpStatus.OK);
}

@RequestMapping(value = "/support", method = RequestMethod.GET)
public ResponseEntity<someDTO> getSupportNumberSecure(@RequestParam(value = "countryId") Long countryId) {
someDTO contactNos = supportService.getSupportNumbers(countryId);
return new ResponseEntity<someDTO>(contactNos, HttpStatus.OK);
}

“不安全”会被 Spring WebSecurityConfigurerAdapter 中的重写配置方法忽略,而其他 URL 将被验证。

        web.ignoring()
.antMatchers("/master/unsecure/**");

是否有可能将这两种方法合而为一,因为只有网址发生变化,或者请分享您的想法,如何有效地实现它。

最佳答案

我认为这应该有效

@RequestMapping(value = {"/unsecure/support","/support"},  method = RequestMethod.GET)
public ResponseEntity<someDTO> getSupportNumber(@RequestParam(value = "countryId") Long countryId) {
someDTO contactNos = supportService.getSupportNumbers(countryId);
return new ResponseEntity<someDTO>(contactNos, HttpStatus.OK);
}

因为@RequestMapping的value属性确实接受多个映射

 @RequestMapping(value = "/unsecure/support",  method = RequestMethod.GET)
public ResponseEntity<someDTO> getSupportNumber(@RequestParam(value = "countryId") Long countryId) {
return getSupportNumberSecure(countryId)
}

@RequestMapping(value = "/support", method = RequestMethod.GET)
public ResponseEntity<someDTO> getSupportNumberSecure(@RequestParam(value = "countryId") Long countryId) {
someDTO contactNos = supportService.getSupportNumbers(countryId);
return new ResponseEntity<someDTO>(contactNos, HttpStatus.OK);
}

关于java - 具有不同 url 但具有相同参数和相同方法功能的请求映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57669573/

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