dto

Java Converting Classes

天大地大妈咪最大 提交于 2019-12-06 12:58:08
I have a class like: Student -name -surname -address -number and I have a DTO for it like: StudentDTO -name -surname -number I will send my student class to another class just with name, surname and number fields(I mean not with all fields) and I decided to name it as DTO (I am not using serializing or etc. just I send this class's object as parameter to any other class's methods). However lets assume that I have a line of code like that: getAllStudents(); and it returns: List<Student> but I want to assign it to a variable that: List<StudentDTO> How can I convert them easily? PS: I can't

netcore 2.2 使用 AutoMapper 实现实体之间映射

…衆ロ難τιáo~ 提交于 2019-12-06 11:02:09
一、什么是AutoMapper? AutoMapper是一个简单的对象映射框架(OOM),将一个对象映射到另一个对象。 二、AutoMapper的好处 以前的时候我们将DTO对象转换为Model对象时,我们必须将每一个属性都手动映射 实体类 /// <summary> /// 用户表 /// </summary> [Table("tb_User")] public class TbUser { /// <summary> /// 用户Id /// </summary> [Key] [Column("userId")] [StringLength(32)] public string UserId { get; set; } /// <summary> /// 用户名 /// </summary> [Column("userName")] [StringLength(20)] public string UserName { get; set; } /// <summary> /// 邮箱 /// </summary> [Column("email")] [StringLength(30)] public string Email { get; set; } /// <summary> /// 添加时间 /// </summary> [Column("addTime")]

How to effectively use DTO objects (Data Transfer Objects)?

浪子不回头ぞ 提交于 2019-12-06 10:13:35
问题 What is the best way to implement DTOs? My understanding is that they are one way to transfer data between objects. For example, in an ASP.Net app, you might use a DTO to send data from the code-behind to the business logic layer component. What about other options, like just sending the data as method parameters? (Would this be easiest in asces wher there is less data to send?) What about a static class that just holds data, that can be referenced by other objects (a kind of global asembly

Validating data in the service layer against DTOs, Entity Models, or something else?

核能气质少年 提交于 2019-12-06 09:24:41
I'm working on an ASP.NET MVC project. In the project I have a service layer that accepts DTOs for CRUD operations. When I need to validate business logic, should the validator accept DTOs, Entity Models, or something else entirely? For example: public class ProductService: IProductService { public ValidationResult CreateProduct(ProductDTO productDto) { //call productValidator.Validate(productDto) on the DTO here? Product productEntityModel = mapper.Map<Product>(productDto); //or, call productValidator.Validate(productEntityModel) on the Entity model here? if(validationResult.Valid) {

HTML5 DataTransfer detection error in Chrome

情到浓时终转凉″ 提交于 2019-12-06 09:14:45
Trying to detect if files property is supported in DataTransfer Object using Javascript. The following code causes an "Uncaught ReferenceError: DataTransfer is not defined" in Chrome, but IE, Firefox and Safari are all fine. My code is: if ("files" in DataTransfer.prototype) { alert("supported"); } Any idea why or an alternative way to determine if the files property is supported? Thanks Chrome doesn't have a DataTransfer object. It has the Clipboard object. 来源: https://stackoverflow.com/questions/3828183/html5-datatransfer-detection-error-in-chrome

因在缓存对象中增加字段,而导致Redis中取出缓存转化成Java对象时出现反序列化失败的问题

三世轮回 提交于 2019-12-06 07:04:34
背景描述 因为业务需求的需要,我们需要在原来项目中的一个DTO类中新增两个字段(我们项目使用的是dubbo架构,这个DTO在A项目/服务的domain包中,会被其他的项目如B、C、D引用到)。但是这个DTO对象已经在Redis缓存中存在了, 如果我们直接向类中增加字段而不做任何处理的话,那么查询操作查出来的缓存对象就会报反序列化失败的错误,从而影响正常的业务流程 ,那么来看一下我的解决方案吧。 升级缓存版本号 我们的正式环境和预发布环境是共用Redis和Mysql。如果修改了DTO且没有加@JsonIgnoreProperties(ignoreUnknown = true)这个注解。 那么DTO所在的A项目发到预发布之后,会启动一个后台定时任务把最新的DTO对象刷新到缓存中去,但是除了这个工程以外的其他依赖服务如果没有发的话,那么他们jar包里面的domain还是旧的DTO。 那么这个时候取出来的缓存(最新的DTO的缓存)就会有反序列化的错误,发包的延迟和预发布验证的时间都会导致线上反序列化失败,从而阻塞业务。 解决方案就是升级缓存的版本号(修改原来缓存DTO的Redis的Key值) 缓存key升级版本号,在其他未更新的应用中的缓存key已经在跑的jar包里面,他们的key是旧的,比如v1,那么v1对应的DTO就是旧的DTO。

Data Transfer Object, Business Object, Domain Object or something else?

两盒软妹~` 提交于 2019-12-06 05:28:22
In database I have table: Notes and table Comments. In my solution I have 3 projects: DAL, BLL and Web. I need to show a user notes with comments which aren't set as spam so I have created in DAL project that class: public class NotesWithComments { public Notes Note { get; set; } public IEnumerable<Comments> Comments { get; set; } } I use above class in each project: DAL, BLL and Web. Is this class Data Transfer Object, Business Object, Domain Object or what? In a repository class I have that query: public class NotesRepository { DatabaseContext context; public NotesRepository(DatabaseContext

NHibernate, DTOs and NonUniqueObjectException

纵然是瞬间 提交于 2019-12-06 04:56:14
We're using the DTO pattern to marshal our domain objects from the service layer into our repository, and then down to the database via NHibernate. I've run into an issue whereby I pull a DTO out of the repository (e.g. CustomerDTO) and then convert it into the domain object (Customer) in my service layer. I then try and save a new object back (e.g. SalesOrder) which contains the same Customer object. This is in turn converted to a SalesOrderDTO (and CustomerDTO) for pushing into the repository. NHibernate does not like this- it complains that the CustomerDTO is a duplicate record. I'm

Spring中常见的设计模式——原型模式

家住魔仙堡 提交于 2019-12-06 04:27:15
1、原型模式应用场景   当遇到大量耗费劳动力的 get,set赋值场景时,如下: public class SetGetParam { public void setParam(UserDto userDto) { User user = new User(); user.setAge(userDto.getAge()); //...     userDao.addUser(user); } }   原型模式(Prototype pattern)是指原型实例指定创建对象的种类,并且通过复制这些原型创建新的对象。原型模式主要适用于以下:   (1)类初始化消耗资源较多;   (2)使用new 生成一个对象需要非常繁琐的过程(数据准备访问权限等);   (3)构造函数比较复杂;   (4)在循环体中产生大量对象;   在spring中用到的原型模式有:scope="prototype" ,还有常用的JSON.parseObject()也是一种原型模式 2、浅克隆   创建具体需要克隆的类: @Data public class User { private String name; private Integer age; private List<String> hobbies; public UserDto clone() { UserDto dto = new UserDto(

【java编程】vo、po、dto、bo、pojo、entity、mode如何区分

心不动则不痛 提交于 2019-12-05 23:40:49
Java Bean:一种可重用组件,即“一次编写,任何地方执行,任何地方重用”。满足三个条件 类必须是具体的和公共的 具有无参构造器 提供一致性设计模式的公共方法将内部域或暴露成员属性 VO value object :值对象 通常用于业务层之间的数据传递,由new创建,由GC回收 和PO一样也是仅仅包含数据而已,但应是抽象出的业务对象,可以和表对应,也可以不是 PO persistant object :持久层对象 是ORM(Objevt Relational Mapping)框架中Entity,PO属性和数据库中表的字段形成一一对应关系 VO和PO,都是属性加上属性的get和set方法;表面看没什么不同,但代表的含义是完全不同的 DTO data transfer object :数据传输对象 是一种设计模式之间传输数据的软件应用系统,数据传输目标往往是数据访问对象从数据库中检索数据 数据传输对象与数据交互对象或数据访问对象之间的差异是一个以不具任何行为除了存储和检索的数据(访问和存取器) 简而言之,就是接口之间传递的数据封装 表里面有十几个字段:id,name,gender(M/F),age…… 页面需要展示三个字段:name,gender(男/女),age DTO由此产生,一是能提高数据传输的速度(减少了传输字段),二能隐藏后端表结构 BO business object