dubbo 参数验证

该博客介绍了如何在 Dubbo 服务接口中进行参数验证。通过定义注解 @Update, @Cancel 和 @Registry,并结合 @NotNull 和 @Size 注解,针对不同服务方法设置不同的验证规则。例如,'fwsxmbh' 在更新和取消操作中不能为空,'fwbbh' 在注册服务时不能为空,而 'fwsxmbm' 在注册和更新操作中不能为空。服务提供者配置了验证功能,以确保调用时参数的正确性。" 134608611,5613065,Web端高风险漏洞防护实战,"['前端', '安全', '网络']
摘要由CSDN通过智能技术生成

 

要和方法名一致,首字母大写

public interface FdsFwxmglService {
    @interface Update {}
    @interface Cancel {}
    @interface Registry {}

    Result registry(@NotNull FdsFwxmglBean fdsFwxmglBean)throws Exception;

    Result update(@NotNull FdsFwxmglBean fdsFwxmglBean)throws Exception;

    Result cancel(@NotNull FdsFwxmglBean fdsFwxmglBean)throws Exception;

    PageBean<FdsFwxmglBean> queryByPage(PageParams page, @NotNull FdsFwxmglBean fdsFwxmglBean) throws Exception;

}
 

 

 


@Data
public class FdsFwxmglBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @Size(max = 50)
    @NotNull(groups = {FdsFwxmglService.Update.class,FdsFwxmglService.Cancel.class},message = "服务项目编号不能为空")
    private String fwxmbh;

    @Size(max = 50)
    @NotNull(groups = {FdsFwxmglService.Registry.class},message = "服务包编号不能为空")
    private String fwbbh;

    @Size(max = 50)
    @NotNull(groups = {FdsFwxmglService.Registry.class,FdsFwxmglService.Update.class},message = "服务项目编码不能为空")
    private String fwxmbm;

}

服务提供添加验证

    <bean id="fdsFwxmglService" class="com.hyjk.backend.fds.service.FdsFwxmglServiceImpl" />
    <dubbo:service interface="com.hyjk.share.fds.service.FdsFwxmglService" ref="fdsFwxmglService" timeout="5000" validation="true" />
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值