小编Har*_*ini的帖子

在休眠验证器中将参数从验证传递到自定义验证器

我正在尝试使用自定义验证器来验证 bean。但是验证器需要从调用验证的方法传递给它的信息。有没有办法做到这一点?

我无法在初始化中传递它,因为它在创建 bean 时不可用。

要验证的 Bean

class vehicle {
   @VehicleNameValidator
   String vehicleName;
}
Run Code Online (Sandbox Code Playgroud)

注解

@Target({ElementType.FIELD})
@Retention(RUNTIME)
@Constraint(validatedBy = VehicleNameValidatorImpl.class)
@Documented
public @interface VehicleNameValidator {
    String message() default "Invalid vehicle Name";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };
}
Run Code Online (Sandbox Code Playgroud)

自定义验证器

public class VehicleNameValidatorImpl implements ConstraintValidator<VehicleNameValidator, String[]> {

    @Override
    public boolean isValid(String vehicleName, ConstraintValidatorContext constraintValidatorContext) {
        boolean isValid = logicmethod()//some logic here
        return isValid;
    }
}
Run Code Online (Sandbox Code Playgroud)

主要方法

public static void main(String[] args) {
   String whatIwantToPass = …
Run Code Online (Sandbox Code Playgroud)

java bean-validation javax.validation

5
推荐指数
1
解决办法
9449
查看次数

httpclient调用webapi发布数据不起作用

我需要使用字符串参数对post方法进行简单的webapi调用.

下面是我正在尝试的代码,但是当在webapi方法上遇到断点时,接收的值是null.

StringContent stringContent = new System.Net.Http.StringContent("{ \"firstName\": \"John\" }", System.Text.Encoding.UTF8, "application/json");
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.PostAsync(url.ToString(), stringContent);
Run Code Online (Sandbox Code Playgroud)

和服务器端代码:

 // POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
Run Code Online (Sandbox Code Playgroud)

请帮忙...

c# asp.net-web-api

4
推荐指数
1
解决办法
4万
查看次数

Herocard在skype Microsoft bot框架中没有显示超过3个按钮

我在Hero卡中添加了6个按钮并尝试显示它们.它在团队和模拟器中工作正常但在Skype上不起作用.它只显示3个按钮.

 private List<CardAction> GetCardButton(List<string> opts)
    {
        List<CardAction> cardButtons = new List<CardAction>();
        int i = 1;
        foreach(string opt in opts)
        {
            CardAction plButton = new CardAction()
            {
                Title = opt,
                Type = "postBack",
                Text = i.ToString(),
                Value = i.ToString()
            };
            cardButtons.Add(plButton);
            i++;
        }

        return cardButtons;

    }
 //passing list of strings.
 List<CardAction> cardButtons = GetCardButton(cardOpts);

        HeroCard plCard = new HeroCard()
        {
            Title = "Try here",
            Text = "with:",
            Buttons = cardButtons

        };
        plAttachment = plCard.ToAttachment();
Run Code Online (Sandbox Code Playgroud)

但在Skype中我只看到前3个按钮.有什么方法可以使卡可滚动或减少按钮大小?

c# skype botframework

4
推荐指数
1
解决办法
607
查看次数

在 asp .net mvc 中分配给输入文本值时字符串被截断

我有一个显示动态数据的视图。我正在从动态数据构建一个字符串并将其分配给文本框值属性。但是我的复选框值被截断。

System.Text.StringBuilder MyStringBuilder = new System.Text.StringBuilder("Hello world");
        MyStringBuilder.Append(dynamic data retrieved);
        <input type="text" value=@MyStringBuilder />
Run Code Online (Sandbox Code Playgroud)

但是当我获取值时,它返回 Hello 并截断剩余的字符串。知道我哪里出错了吗?

c# asp.net asp.net-mvc razor

3
推荐指数
1
解决办法
1737
查看次数

使用mockito测试具有CompletableFuture.allOf的方法

我有一个名为 doParallelThings 的方法:

public Dummy doParallelThings(Map<String, String> mapp) throws Exception {
        Dummy dummy = new Dummy();

        CompletableFuture<Ans1> one = firstService.getOne(mapp.get("some1"), mapp);
        CompletableFuture<Ans2> two = secondService.getTwo(headersMap.get("some2"), mapp);

        CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(one, two);
        try {
            combinedFuture.get();
            dummy.setOne(one.get());
            dummy.setTwp(two.get());

        } catch (Throwable e) {

        }
        return dummy;
    }
Run Code Online (Sandbox Code Playgroud)

代码工作正常,但当我尝试测试它时, combinedFuture.get();进入无限循环。

单元测试如下:

@Mock
    private CompletableFuture<Void> ans;

@Test
    public void testDoParallelThings() throws Exception {

        PowerMockito.mockStatic(CompletableFuture.class);
        PowerMockito.when(CompletableFuture.allOf(any())).thenReturn(ans);
        when(ans.get()).thenReturn(null);

        Dummy dummy = dummyService. doParallelThings(mockMap);
        assertNotNull(dummy);
    }
Run Code Online (Sandbox Code Playgroud)

我还在@RunWith(PowerMockRunner.class) @PrepareForTest({CompletableFuture.class})测试类上面添加了。

我缺少什么?

java mockito powermockito

3
推荐指数
1
解决办法
4245
查看次数