2016-06-21 3 views
0

많은 엔티티 (javax.persistence.Entity) 개체가있는 기존 시스템이 있습니다. 이 엔티티 각각은 다른 엔티티와 일대 다의 관계를가집니다.엔티티 개체를 XML로 변환하는 방법

내 요구 사항은 REST API로 이러한 엔티티를 노출하는 것입니다. resteasy (현재 제품은 jboss-7에서 실행 됨)를 사용할 계획입니다. 내 질문은, 이것을 설계하는 가장 좋은 방법은 무엇입니까?

처음에는 JAXB annotated DTO 객체를 사용하고 getter/setter를 사용하여 모든 엔티티를 변환하려고 생각했습니다. 다른 대안이 있습니까?

답변

0
Create One class like this 

    public class Employee 
    { 
     public int employee_code {set; get; } 
     public string first_name {set; get; } 
     public string middle_name {set; get; } 
     public string last_name {set; get; } 
     public string designation {set; get; } 
     public string department {set; get; } 
     public string present_address {set; get; } 
     public string permament_address {set; get; } 
     public DateTime DOB {set; get; } 
     public Double Gross_Salary {set; get; } 
    } 

now create a method for xml creation using this namespace 
    using System.Xml.Serialization; 

public string CreateXML(Object YourClassObject){  
     XmlDocument xmlDoc =new XmlDocument(); //Represents an XML document, 
       // Initializes a new instance of the XmlDocument class.   
     XmlSerializer xmlSerializer = new    XmlSerializer(YourClassObject.GetType());    
    // Creates a stream whose backing store is memory. 
     using (MemoryStream xmlStream =new MemoryStream()) 
     { 
     xmlSerializer.Serialize(xmlStream, YourClassObject); 
     xmlStream.Position = 0; 
     //Loads the XML document from the specified string. 
     xmlDoc.Load(xmlStream); 
     return xmlDoc.InnerXml; 
     } 
} 

now call this method 
string strView =CreateXML(YourClassObject); 
+0

이것은 너무 많은 작업입니다! @http : //codereview.stackexchange.com/questions/74201/javaee-7-with-jpa-hibernate-and-jax-rs-resteasy가 있지만이 경우에는 모든 엔티티를 만져야합니다. – dgm

관련 문제