第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無法將自定義驗(yàn)證應(yīng)用于 requestParam

無法將自定義驗(yàn)證應(yīng)用于 requestParam

紅糖糍粑 2023-04-26 16:24:17
我有我的 RequestParam,我需要驗(yàn)證它,但是 mu 自定義驗(yàn)證不適用,我的控制器@RestController@Validatedclass ExchangeController {    private static final Logger logger = Logger.getLogger(ExchangeController.class.getName());    @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")    @Autowired    @Qualifier("dataService")    private CurrencyExchangeService currencyExchangeService;    @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")    public Object converting(@RequestParam("fromCurrency") @NotNull @CurrencyValidation String fromCurrency,                             @RequestParam("toCurrency") @NotNull String toCurrency,                             @RequestParam("amount") @NotNull String amount) throws IOException {        BigDecimal convertedAmount = currencyExchangeService.convert(fromCurrency, toCurrency, new BigDecimal(amount));        return new ExchangeRateDTO(fromCurrency, toCurrency, new BigDecimal(amount), convertedAmount);    }}和自定義驗(yàn)證public class ConstractCurrencyValidator implements            ConstraintValidator<CurrencyValidation, String> {        @Override        public void initialize(CurrencyValidation currency) {        }        @Override        public boolean isValid(String currency, ConstraintValidatorContext constraintValidatorContext) {            return currency != null && Currency.getAvailableCurrencies().contains(Currency.getInstance(currency));        }    }
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊

需要在我的@interface CustomValidation. 這意味著驗(yàn)證也可以用于參數(shù)。

@Target({ ElementType.PARAMETER })


查看完整回答
反對(duì) 回復(fù) 2023-04-26
?
MMTTMM

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊

在配置中啟用參數(shù)驗(yàn)證:


 @Bean

public Validator validator() {

    return new LocalValidatorFactoryBean();

}


@Bean

public MethodValidationPostProcessor methodValidationPostProcessor() {

    MethodValidationPostProcessor methodValidationPostProcessor = new MethodValidationPostProcessor();

    methodValidationPostProcessor.setValidator(validator());

    return methodValidationPostProcessor;

}


查看完整回答
反對(duì) 回復(fù) 2023-04-26
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)