dto

java里面Dto对象跟VO的区别

时光毁灭记忆、已成空白 提交于 2019-11-27 13:09:09
原文地址: https://ask.csdn.net/questions/692933?sort=id javaBean 是一种JAVA语言写成的可重用组件。为写成JavaBean,类必须是具体的和公共的,并且具有无参数的构造器。JavaBean 通过提供符合一致性设计模式的公共方法将内部域暴露成员属性。众所周知,属性名称符合这种模式,其他Java 类可以通过自身机制发现和操作这些JavaBean 的属性。 VO即value object值对象 主要体现在视图的对象,对于一个WEB页面将整个页面的属性封装成一个对象。然后用一个VO对象在控制层与视图层进行传输交换。 DTO (经过处理后的PO,可能增加或者减少PO的属性): Data Transfer Object数据传输对象 主要用于远程调用等需要大量传输对象的地方。 比如我们一张表有100个字段,那么对应的PO就有100个属性。 但是我们界面上只要显示10个字段, 客户端用WEB service来获取数据,没有必要把整个PO对象传递到客户端, 这时我们就可以用只有这10个属性的DTO来传递结果到客户端,这样也不会暴露服务端表结构.到达客户端以后,如果用这个对象来对应界面显示,那此时它的身份就转为VO。 POJO(POJO是一种概念或者接口,身份及作用随环境变化而变化) : POJO有一些private的参数作为对象的属性

【AutoMapper官方文档】DTO与Domin Model相互转换(中)

百般思念 提交于 2019-11-27 10:22:45
写在前面   AutoMapper目录: 【AutoMapper官方文档】DTO与Domin Model相互转换(上) 【AutoMapper官方文档】DTO与Domin Model相互转换(中) 【AutoMapper官方文档】DTO与Domin Model相互转换(下) 未完待续。。。   本篇目录: Custom Type Converters-自定义类型转换器 Custom Value Resolvers-自定义值解析器 Null Substitution-空值替换 Containers-IoC容器 后记   随着AutoMapper的学习深入,发现 AutoMapper在对象转换方面(Object-Object Mapping)还蛮强大的,当时使用AutoMapper的场景是DTO与Domin Model相互转换,所以文章的标题就是这个(标题有误),其实AutoMapper不止在这方面的转换,应该是涵盖所有对象(Object)之间的转换,上篇主要讲AutoMapper的基本转换使用,本篇可以定义为AutoMapper的灵活配置篇。    插一句 :有时候学习一门技术,还没有学很深入,发现还有比其更好的,然后就去学习另外一门技术,可能到头来什么也没学会、学精,前两天看一篇 C#程序员-你为何不受大公司青睐 ,其实不是C#不好,而是你没有学好,就像前几年讨论C

【AutoMapper官方文档】DTO与Domin Model相互转换(下)

╄→гoц情女王★ 提交于 2019-11-27 10:22:28
写在前面   AutoMapper目录: 【AutoMapper官方文档】DTO与Domin Model相互转换(上) 【AutoMapper官方文档】DTO与Domin Model相互转换(中) 【AutoMapper官方文档】DTO与Domin Model相互转换(下) 未完待续。。。   本篇目录: Mapping Inheritance-映射继承 Queryable Extensions (LINQ)-扩展查询表达式 Configuration-配置 Conditional Mapping-条件映射 AutoMapper版本变化点 类型映射优先级 后记   关于AutoMapper写到这基本的东西都差不多了,上一篇定义为灵活配置篇,本篇可以定义为扩展应用篇,加一些补充,关于 AutoMapper的项目应用,网上找了几篇英文文章,虽然看不懂,但是代码是相通的,感觉很不错,主要是EntityFramework中运用 AutoMapper,数据访问中使用 AutoMapper,有支持的,也有反对的,也有提出建议的,自己也正在摸索,希望有机会写篇文章和大家分享下。   插一句:写这些东西,看的人真的很少,还不如像前几天大家写篇水文,来讨论下C#的好坏增加点人气,呵呵,但是如果是这种思想来编程真是不可饶恕,写这种文章的目的不一定是分享给别人,也是对自己学习的另一种修炼

【AutoMapper官方文档】DTO与Domin Model相互转换(上)

删除回忆录丶 提交于 2019-11-27 10:21:07
写在前面   AutoMapper目录: 【AutoMapper官方文档】DTO与Domin Model相互转换(上) 【AutoMapper官方文档】DTO与Domin Model相互转换(中) 【AutoMapper官方文档】DTO与Domin Model相互转换(下) 未完待续。。。   本篇目录: Flattening-复杂到简单 Projection-简单到复杂 Configuration Validation-配置验证 Lists and Array-集合和数组 Nested mappings-嵌套映射 后记   上一篇《 【道德经】漫谈实体、对象、DTO及AutoMapper的使用 》,因为内容写的有点跑偏,关于AutoMapper的使用最后只是简单写了下,很明显这种简单的使用方式不能满足项目中复杂的需要,网上找了下 AutoMapper相关文档,但差不多都是像我一样简单的概述下,看来懒的不只有我一个,哈哈。在 AutoMapper 官方文档 中找到其使用的详细说明,天书一样的英文,然后就找相关中文文档,最后还是没找到,这边没办法,只能自己动手,丰衣足食了。英语牛逼的可以直接略过,查看英文文档,本篇也不算是翻译,因为本人英语 实在拿不出手,只是按照示例加上自己的一些理解,做个学习笔记,不对的地方还请指正。    注:虽然上一篇写跑偏了,但是本人真的很喜欢道德经

Mapping Validation Attributes From Domain Entity to DTO

萝らか妹 提交于 2019-11-27 10:20:24
问题 I have a standard Domain Layer entity: public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set;} } which has some kind of validation attributes applied: public class Product { public int Id { get; set; } [NotEmpty, NotShorterThan10Characters, NotLongerThan100Characters] public string Name { get; set; } [NotLessThan0] public decimal Price { get; set;} } As you can see, I have made up these attributes completely. Which validation

Query result in JSON format (key value pair) on using @Query annotation in Spring Boot, Hibernate

旧巷老猫 提交于 2019-11-27 07:25:43
问题 My Controller @GetMapping(value="/getAllDetails") public List<PriceListEntity> getAllDetails() { return MyRepository.getAllDetails(); } My Repository @Repository public interface MyRepository extends CrudRepository<TestNativeQ, String> { @Query( value="SELECT qplt.name price_list_name, qplab.status_code, qplab.start_date, (SELECT charge_definition_code FROM oalfsaas_repl.QP_CHARGE_DEFINITIONS_B WHERE charge_definition_id=qplab.charge_definition_id ) chargedefinitioncode " + "FROM

Should the repository layer return data-transfer-objects (DTO)?

半城伤御伤魂 提交于 2019-11-27 06:55:00
I have a repository layer that is responsible for my data-access, which is called by a service layer. The service layer returns DTOs which are serialized and sent over the wire. More often than not, services do little more than access a repository and return whatever the repository returns. But for that to work, the repository has to return an instance of that DTO. Otherwise, you would first have to map the data layer object that the repository returns to a DTO in the service layer and return that. That just seems wasteful. On top of that, if creation of the DTOs happens in the service layer,

【转】C#中的Explicit和Implicit

橙三吉。 提交于 2019-11-27 04:43:17
今天在Review一个老项目的时候,看到一段奇怪的代码。 1 2 3 4 5 if (dto.Payment == null ) continue ; var entity = entries.FirstOrDefault(e => e.LedgerEntryID == dto.LedgerEntryID); dto.Payment = entity?.Payment;   其中dto.Payment是一个 PaymentDTO 类的实例,entity?.Payment是一个 Payment 类的实例, PaymentDTO 类和 Payment 类没有子父关系,所以不存在子类和父类之间的隐式转换。 奇怪的是Visual Studio的编译器没有提示任何编译错误。 打开PaymentDTO类的定义之后,发现了以下方法签名。 public static implicit operator PaymentDTO(Payment payment) 从方法签名上看,这就是重写PaymentDTO类型的操作符,但并不是我以前常用的+,-,*,/, ==等。 查询MSDN之后,才了解到implicit和explicit是一对转换操作符。 Implicit和Explicit Implicit Implicit关键字用于声明隐式的用户定义类型转换运算符。它可以实现2个不同类的隐式转换

DTOs vs Serializing Persisted Entities

筅森魡賤 提交于 2019-11-27 04:36:05
问题 I'm curious to know what the community feels on this subject. I've recently come into the question with a NHibernate/WCF scenario(entities persisted at the service layer) and realized I may be going the wrong direction here. My question is plainly, when using a persistent object graph(NHibernate, LINQ to SQL, etc) behind a web service(WCF in this scenario), do you prefer to send those entities over the wire? Or would you create a set of lighter DTO's(sans cyclic references) across? 回答1: DTOs.

How to work with DTO in Spring Data REST projects?

可紊 提交于 2019-11-27 04:07:58
Spring Data REST automates exposing only domain object. But most often we have to deal with Data Transfer Objects. So how to do this in SDR way? An approach of how to work with DTO in Spring Data REST projects The working example is here Entities Entities must implement the Identifiable interface. For example: @Entity public class Category implements Identifiable<Integer> { @Id @GeneratedValue private final Integer id; private final String name; @OneToMany private final Set<Product> products = new HashSet<>(); // skipped } @Entity public class Product implements Identifiable<Integer> { @Id