简体   繁体   English

在WSDL优先方法中,如何使用某些(例如:验证)方法编写DTO? 只是不要写“贫血领域模型”

[英]How in WSDL-first approach write DTO with some (for example: validation) method? Just not to write “anemic domain model”

I am using WSDL-first. 我先使用WSDL。 I have WSDL and generate Java code using Maven plugin 'cxf-codegen-plugin'. 我有WSDL,并使用Maven插件“ cxf-codegen-plugin”生成Java代码。 Using Code-first one can write DTO for example: 例如,使用Code-first可以编写DTO:

public class ServiceSearchCriteria {
    private String phoneNumber;
    private String businessId;

    public boolean validateSearchCriteria() {
        if ((phoneNumber != null) || (businessId != null)) {
            return true;
        }
        return false;
    }
    //... setters/getters etc.
}

So using Code-First (Java-First) it is easy to write DTO with validation method. 因此,使用Code-First(Java-First)可以很容易地使用验证方法编写DTO。 Client can check if search criteria are good fulfilled. 客户可以检查搜索条件是否满足要求。 This class would be returned by WebService class annotiated with @WebService. 此类将由带@WebService注释的WebService类返回。 And this will work. 这将起作用。

But how to write such DTO (with some method) using WSDL-First approach? 但是如何使用WSDL-First方法编写这种DTO(使用某种方法)?

I very like WSDL-First approach (it has many advantages but this is not place to write about them) but I would like to add method... just not to write "anemic domain model" and allowing client to check search criteria fulfilled before sending to server. 我非常喜欢WSDL-First方法(它有很多优点,但是这里没有写这些优点),但是我想添加方法...只是不编写“贫血领域模型”,并且允许客户端检查之前满足的搜索条件发送到服务器。

You seem to be mixing various concepts. 您似乎混合了各种概念。 It's cool you don't want to have an anemic domain model but that has nothing to do with your DTOs which in turn has nothing to do with how the classes from WSDL look like. 不想拥有贫乏的领域模型很酷,但这与您的DTO无关,而DTO又与WSDL中的类的外观无关。

A DTO has state but no behavior. DTO有状态但没有行为。 Hence, they have only getters/setters but contain no logic (eg validation). 因此,它们仅具有getter / setter,但不包含逻辑(例如,验证)。

The objects in the domain model have state and behavior (unless they're anemic of course). 域模型中的对象具有状态行为(除非它们当然是贫血的)。

So, if there's a need for DTOs, which depends on your architecture, you'd be converting business objects from the domain model to DTOs and vice versa. 因此,如果需要DTO(取决于您的体系结构),则需要将业务对象从域模型转换为DTO,反之亦然。 If you consider the classes generated from your WSDL DTOs which would be ok then you need to convert those to your business objects. 如果考虑从WSDL DTO生成的类,这是可以的,那么您需要将其转换为业务对象。 "Converting" in this respect means transferring their state. 在这方面,“转换”意味着转移其状态。

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

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