简体   繁体   English

如何在DropWizard中验证单个参数

[英]How to validate a single parameter in DropWizard

I want to validate some input parameters in DropWizard as documented here: https://dropwizard.github.io/dropwizard/manual/core.html#validation 我想验证DropWizard中的某些输入参数,如此处记录: https ://dropwizard.github.io/dropwizard/manual/core.html#validation

This example validates an object's properties, which works fine, but my service doesn't receive an object, but the parameters directly. 此示例验证了对象的属性,该属性可以正常工作,但是我的服务未接收到对象,而是直接接收了参数。 This is a simplification of my code: 这是我的代码的简化:

@GET
@Path("/MyResource/{myresourceId}")
public MyResource detail(@PathParam("myresourceId") @Valid @Size(min = 2, max = 5) String myresourceId) {

The @Valid and @Size annotations seem to be ignored in this case. 在这种情况下,@ Valid和@Size注释似乎被忽略。 Anyone knows if this is possible and if so how to do it right? 有人知道这是否可能吗,如果可以,怎么做正确呢? Thanks. 谢谢。

It's not possible with those annotations as method parameters. 这些注释不能用作方法参数。 Have a look at this thread . 看看这个线程

You might be able to write some AOP code to support this (depending on how you're initializing your resources). 您也许可以编写一些AOP代码来支持此操作(取决于您如何初始化资源)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM