dto

Should I have different DTOs for Create and Update? (CRUD) [closed]

情到浓时终转凉″ 提交于 2019-12-08 08:12:24
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I'm designing a Web API with the usual CRUD operations on a Person entity. The problem is that I don't know how to design the DTOs. The entity is as follows: public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } } I

JPA将查询结果转换为DTO对象

℡╲_俬逩灬. 提交于 2019-12-08 05:20:50
前言 JPA支持使用@Query自定义查询,查询的结果需要字节用DTO对象接收,如果使用HQL的查询语句,可以将直接将DTO对象的构造方法传入hql中,直接转为DTO对象;而如果使用native sql查询的方式,只能将返回结果用Object[]对象接收,然后DTO设置对象的构造来接收Object[]里面的参数完成DTO对象的转换。 例子 mysql数据库表 用户表 CREATE TABLE `pos_user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `user_pwd` varchar(255) DEFAULT NULL, `user_type` int(11) DEFAULT NULL, `parent_id` bigint(20) DEFAULT NULL, `user_status` int(11) DEFAULT NULL, `distributor_id` bigint(20) DEFAULT NULL, `creator_identity_type` int(2) DEFAULT NULL, `creator_id` bigint(20) DEFAULT NULL,

hibernate查询返回DTO对象,DTO封装了多个pojo对象的属性

不羁岁月 提交于 2019-12-08 05:19:39
DTO- 数据传输对象; pojo- 最纯粹的 java 对象与数据库中表的字段一一对应。 简单讲: DTO 起到业务数据的传递作用,数据转换成 JAVA 对象。 1. 查询语句 public void testSqlOneToMany(){ String hql= "select f.id, f.machinenum,f.types_id,t.id as typeId,t.name from gjp_fault f,gjp_type t where f.types_id = t.id" ; SQLQuery query = getSession().createSQLQuery(hql); List<ManyToVo> list = query.setResultTransformer(Transformers. aliasToBean (ManyToVo. class )).list(); System. out .println(list.size()); } 2. 数据封装成对象( DTO ) package bh.test.vo; import java.math.BigDecimal; public class ManyToVo { private BigDecimal ID ; private String MACHINENUM ; //machinenum;

Spring Data JPA 映射VO/DTO对象

我的未来我决定 提交于 2019-12-08 05:19:01
简介 在项目开发中,时常需要根据业务需求来映射VO/DTO对象(这两个概念理解感觉很模糊- 。- ),本文将简单介绍以Spring Data JPA的方式处理实体类映射 HQL方式 public interface MusicTypeRepository extends JpaRepository < MusicType , Integer > { @Query ( "select new cn.srblog.springbootcurd.vo.StudentTypeInfoVo(count(s.id),m.name) " + "FROM MusicType m left JOIN Student s on s.musicTypeId = m.id group by m.id " ) List < StudentTypeInfoVo > getTypeInfo ( ) ; } 填写实体类路径,构造参数顺序要一致,字段名一律为实体类中的属性 如果配置了实体类属性的映射关系,则 on s.musicTypeId = m.id 语句可以省略 VO实体类 @Value public class StudentTypeInfoVo { private Long count ; private String name ; } 使用 Lombok 的 @Value 注解 默认生成带参构造方法

Should AutoMapper also be used as a Re-Shape mapping tool

泪湿孤枕 提交于 2019-12-08 05:06:37
问题 I know AutoMapper is just to map properties between 2 objects. Automapper is not for reshaping data this must be programmed in my opinion. I have a PeriodDTO.IEnumerable<Period> which needs to be reshaped into a PeriodListViewModel.List<CellViewModel> . Each CellViewModel holds a List<RowViewModel> This is no 1 to 1 mapping not and I guess maybe this should not be mapped - because its not possible - public class PeriodRequest { public IEnumerable<Period> Periods { get; set; } public

ViewModel location when doing CQRS

前提是你 提交于 2019-12-08 03:13:50
问题 Suppose you have a layered project divided into the Presentation Layer, the Business Layer and the Data Access Layer. If you were using CQRS, you would be doing queries directly from the Data Access Layer into the Presentation Layer and bypassing the Business Layer. In that case, if you are using ViewModels in your presentation layer, then your Data Access Layer would need reference to the Presentation Layer to return data in terms of the ViewModels in the presentation layer. Wouldn't that be

HTML5 DataTransfer detection error in Chrome

倖福魔咒の 提交于 2019-12-08 02:48:12
问题 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 回答1: Chrome doesn't have a DataTransfer object. It has the Clipboard object. 来源: https://stackoverflow.com

Java Converting Classes

橙三吉。 提交于 2019-12-08 02:20:23
问题 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

Update of large entity through service

笑着哭i 提交于 2019-12-07 22:49:54
问题 We're building an n-tier system based on WCF (but not Entity Framework) and we've run into a discussion of the best way to implement updates of large entities. We've created DTOs and map data from our domain model into theese when data is sent to the client. The client then makes some changes and sends them back using the same DTO, in our current implementation. Some of our entities might have 80-100 properties, but perhaps the client only makes changes to one or a few of them. It seems

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

倾然丶 夕夏残阳落幕 提交于 2019-12-07 18:58:17
问题 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