Java JPA实体的DTO生成器
谁能告诉我JPA实体是否有DTO生成器?Java JPA实体的DTO生成器,java,hibernate,jpa,Java,Hibernate,Jpa,谁能告诉我JPA实体是否有DTO生成器? 谢谢您的帮助。如果您使用的是eclipse,那么Hibernate工具可能应该这样做:我已经开发了一个apt库。 提供给实体 @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class Employee { @Id private String number; private String name; private String
谢谢您的帮助。如果您使用的是eclipse,那么Hibernate工具可能应该这样做:我已经开发了一个apt库。 提供给实体
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Employee {
@Id
private String number;
private String name;
private String sex;
private String nation;
@Temporal(TemporalType.DATE)
private Date birthDay;
@Temporal(TemporalType.DATE)
private Date enrollmentDay;
@ManyToOne
private Department department;
@ManyToOne
private Company company;
}
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Department {
@Id
private String number;
@ManyToOne
private Company company;
@OneToMany(mappedBy = "department")
private List<Employee> employees;
}
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Company {
@Id
private String code;
private String name;
private Double money;
private Address address;
@OneToMany(mappedBy = "company")
private List<Department> departments;
@OneToMany(mappedBy = "company")
private List<Employee> employees;
}
@实体
@吸气剂
@塞特
@诺尔格构装师
@AllArgsConstructor
公营雇员{
@身份证
私有字符串编号;
私有字符串名称;
私密性;
私有制国家;
@时态(TemporalType.DATE)
私人约会生日;
@时态(TemporalType.DATE)
私人日期登记日;
@许多酮
私人部门,;
@许多酮
私营公司;
}
@实体
@吸气剂
@塞特
@诺尔格构装师
@AllArgsConstructor
公共课系{
@身份证
私有字符串编号;
@许多酮
私营公司;
@OneToMany(mappedBy=“部门”)
私人名单雇员;
}
@实体
@吸气剂
@塞特
@诺尔格构装师
@AllArgsConstructor
公营公司{
@身份证
私有字符串码;
私有字符串名称;
私人双重货币;
私人地址;
@OneToMany(mappedBy=“公司”)
私人名单部门;
@OneToMany(mappedBy=“公司”)
私人名单雇员;
}
还有一些配置类
@ViewPropertiesIncludePattern(".*")
@ViewGenNameMapper("${name}Info")
@AddJpaSupport
public class BaseDtoConfiguration {
}
@ViewOf(Employee.class)
@RemoveViewProperty({EmployeeMeta.company, EmployeeMeta.department})
public class EmployeeInfoConfiguration extends BaseDtoConfiguration {
}
@ViewOf(value = Employee.class, genName = "EmployeeDetail")
public class EmployeeDetailConfiguration extends BaseDtoConfiguration {
@MapViewProperty(name = "departmentInfo", map = "department")
private DepartmentInfo departmentInfo;
@MapViewProperty(name = "companyInfo", map = "company")
private CompanyInfo companyInfo;
}
@ViewOf(Department.class)
@RemoveViewProperty(DepartmentMeta.company)
public class DepartmentInfoConfiguration extends BaseDtoConfiguration {
@OverrideViewProperty(DepartmentMeta.employees)
private List<EmployeeInfo> employees;
}
@ViewOf(Company.class)
@RemoveViewProperty({CompanyMeta.departments, CompanyMeta.employees})
public class CompanyInfoConfiguration extends BaseDtoConfiguration {
@OverrideViewProperty(CompanyMeta.money)
@NullNumberAsZero
private double money;
}
@ViewPropertiesIncludePattern(“.*”)
@ViewGenNameMapper(“${name}Info”)
@AddJpaSupport
基于公共类的配置{
}
@ViewOf(Employee.class)
@RemoveViewProperty({EmployeeMeta.company,EmployeeMeta.department})
公共类EmployeeInfoConfiguration扩展了BaseDtoConfiguration{
}
@ViewOf(value=Employee.class,genName=“EmployeeDetail”)
公共类EmployeeDetailConfiguration扩展了BaseDtoConfiguration{
@MapViewProperty(name=“departmentInfo”,map=“department”)
私人部门信息部门信息;
@MapViewProperty(name=“companyInfo”,map=“company”)
私人公司信息公司信息;
}
@ViewOf(系级)
@RemoveViewProperty(DepartmentMeta.company)
公共类DepartmentInfoConfiguration扩展了BaseDtoConfiguration{
@覆盖视图属性(部门元员工)
私人名单雇员;
}
@ViewOf(公司级)
@RemoveViewProperty({CompanyMeta.departments,CompanyMeta.employees})
公共类CompanyInfo配置扩展了BaseDtoConfiguration{
@覆盖的EWProperty(CompanyData.money)
@空数零
私人双重货币;
}
将为您生成DTO
@GeneratedView(targetClass = Employee.class, configClass = EmployeeInfoConfiguration.class)
public class EmployeeInfo {
private String number;
private String name;
private String sex;
private String nation;
private Date birthDay;
private Date enrollmentDay;
public EmployeeInfo() { }
public EmployeeInfo(
String number,
String name,
String sex,
String nation,
Date birthDay,
Date enrollmentDay
) { ... }
public EmployeeInfo(EmployeeInfo source) { ... }
public EmployeeInfo(Employee source) { ... }
public static EmployeeInfo read(Employee source) {
if (source == null) {
return null;
}
return new EmployeeInfo(source);
}
/**
* getter methods and other methods...
**/
}
@GeneratedView(targetClass = Employee.class, configClass = EmployeeDetailConfiguration.class)
public class EmployeeDetail {
private String number;
private String name;
private String sex;
private String nation;
private Date birthDay;
private Date enrollmentDay;
private DepartmentInfo departmentInfo;
private CompanyInfo companyInfo;
// other constructors
public EmployeeDetail(Employee source) {
if (source == null) {
throw new NullPointerException("The input source argument of the read constructor of class io.github.vipcxj.beanknfie.jpa.examples.models.EmployeeDetail should not be null.");
}
DepartmentInfo p0 = DepartmentInfo.read(source.getDepartment());
CompanyInfo p1 = CompanyInfo.read(source.getCompany());
this.number = source.getNumber();
this.name = source.getName();
this.sex = source.getSex();
this.nation = source.getNation();
this.birthDay = source.getBirthDay();
this.enrollmentDay = source.getEnrollmentDay();
this.departmentInfo = p0;
this.companyInfo = p1;
}
public static EmployeeDetail read(Employee source) {
if (source == null) {
return null;
}
return new EmployeeDetail(source);
}
public EmployeeDetail (
String number,
String name,
String sex,
String nation,
Date birthDay,
Date enrollmentDay,
Department department,
String companyCode,
String companyName,
Double companyMoney,
Address companyAddress
) {
DepartmentInfo viewVar0 = DepartmentInfo.read(department);
CompanyInfo viewVar1 = new CompanyInfo(companyCode, companyName, new io.github.vipcxj.beanknife.runtime.converters.NullDoubleAsZeroConverter().convert(companyMoney), companyAddress);
this.number = number;
this.name = name;
this.sex = sex;
this.nation = nation;
this.birthDay = birthDay;
this.enrollmentDay = enrollmentDay;
this.departmentInfo = viewVar0;
this.companyInfo = viewVar1;
}
public static <T> Selection<EmployeeDetail> toJpaSelection(CriteriaBuilder cb, From<T, Employee> from) {
return cb.construct(
EmployeeDetail.class,
from.get("number"),
from.get("name"),
from.get("sex"),
from.get("nation"),
from.get("birthDay"),
from.get("enrollmentDay"),
from.get("department"),
from.get("company").get("code"),
from.get("company").get("name"),
from.get("company").get("money"),
from.get("company").get("address")
);
}
}
@GeneratedView(targetClass = Department.class, configClass = DepartmentInfoConfiguration.class)
public class DepartmentInfo {
private String number;
private List<EmployeeInfo> employees;
// other constructors
public DepartmentInfo(Department source) {
if (source == null) {
throw new NullPointerException("The input source argument of the read constructor of class io.github.vipcxj.beanknfie.jpa.examples.models.DepartmentInfo should not be null.");
}
List<EmployeeInfo> p0 = new ArrayList<>();
for (Employee el0 : source.getEmployees()) {
EmployeeInfo result0 = EmployeeInfo.read(el0);
p0.add(result0);
}
this.number = source.getNumber();
this.employees = p0;
}
public static DepartmentInfo read(Department source) {
if (source == null) {
return null;
}
return new DepartmentInfo(source);
}
// other methods and getters
public DepartmentInfo (Department source, int preventConflictArg) {
List<EmployeeInfo> viewVar0 = EmployeeInfo.read(source.getEmployees());
this.number = source.getNumber();
this.employees = viewVar0;
}
public static <T> Selection<DepartmentInfo> toJpaSelection(CriteriaBuilder cb, From<T, Department> from) {
return cb.construct(
DepartmentInfo.class,
from,
cb.literal(0)
);
}
}
@GeneratedView(targetClass = Company.class, configClass = CompanyInfoConfiguration.class)
public class CompanyInfo {
private String code;
private String name;
private double money;
private Address address;
// other constructors
public CompanyInfo(Company source) {
if (source == null) {
throw new NullPointerException("The input source argument of the read constructor of class io.github.vipcxj.beanknfie.jpa.examples.models.CompanyInfo should not be null.");
}
this.code = source.getCode();
this.name = source.getName();
this.money = new NullDoubleAsZeroConverter().convert(source.getMoney());
this.address = source.getAddress();
}
public static CompanyInfo read(Company source) {
if (source == null) {
return null;
}
return new CompanyInfo(source);
}
// other read methods
public CompanyInfo (String code, String name, Double money, Address address) {
this.code = code;
this.name = name;
this.money = new NullDoubleAsZeroConverter().convert(money);
this.address = address;
}
public static <T> Selection<CompanyInfo> toJpaSelection(CriteriaBuilder cb, From<T, Company> from) {
return cb.construct(
CompanyInfo.class,
from.get("code"),
from.get("name"),
from.get("money"),
from.get("address")
);
}
}
@GeneratedView(targetClass=Employee.class,configClass=EmployeeInfoConfiguration.class)
公共类EmployeeInfo{
私有字符串编号;
私有字符串名称;
私密性;
私有制国家;
私人约会生日;
私人日期登记日;
公共雇员信息(){}
公共雇员信息(
字符串编号,
字符串名,
弦乐性,
弦国,
生日,
注册日期
) { ... }
公共EmployeeInfo(EmployeeInfo源){…}
公共雇员信息(雇员来源){…}
公共静态EmployeeInfo读取(员工来源){
if(source==null){
返回null;
}
返回新员工信息(来源);
}
/**
*getter方法和其他方法。。。
**/
}
@GeneratedView(targetClass=Employee.class,configClass=EmployeeDetailConfiguration.class)
公共类EmployeeDetail{
私有字符串编号;
私有字符串名称;
私密性;
私有制国家;
私人约会生日;
私人日期登记日;
私人部门信息部门信息;
私人公司信息公司信息;
//其他施工人员
公共EmployeeDetail(员工来源){
if(source==null){
抛出新的NullPointerException(“io.github.vipcxj.beanknfie.jpa.examples.models.EmployeeDetail类的读取构造函数的输入源参数不应为null”);
}
DepartmentInfo p0=DepartmentInfo.read(source.getDepartment());
CompanyInfo p1=CompanyInfo.read(source.getCompany());
this.number=source.getNumber();
this.name=source.getName();
this.sex=source.getSex();
this.nation=source.getNation();
this.birthDay=source.getBirthDay();
this.enrollmentDay=source.getEnrollmentDay();
this.departmentInfo=p0;
this.companyInfo=p1;
}
公共静态EmployeeDetail读取(员工源){
if(source==null){
返回null;
}
返回新员工详细信息(来源);
}
公共雇员详情(
字符串编号,
字符串名,
弦乐性,
弦国,
生日,
注册日期,
部门,,
字符串公司代码,
字符串companyName,
双公司货币,
地址公司地址
) {
DepartmentInfo viewVar0=DepartmentInfo.read(department);
CompanyInfo viewVar1=新CompanyInfo(companyCode,companyName,new io.github.vipcxj.beanknife.runtime.converters.NullDoubleAsZeroConverter().convert(companyMoney),companyAddress);
这个数字=数字;
this.name=名称;
这个。性=性;
这个国家=国家;
这个生日=生日;
this.enrollmentDay=enrollmentDay;
this.departmentInfo=viewVar0;
this.companyInfo=viewVar1;
}
公共静态选择到JPASELECTION(CriteriaBuilder cb,来自){
返回cb.construct(
EmployeeDetail.class,
from.get(“number”),
from.get(“name”),
从。获取(“性”),
从。获取(“国家”),
from.get(“生日”),
from.get(“注册日”),
从.get(“部门”),
from.get(“公司”).get(“代码”),
from.get(“公司”).get(“名称”),
从。获取(“公司”)。获取(“金钱”),
from.get(“公司”).get(“地址”)