我有一个具有许多实体(javax.persistence.Entity)对象的遗留系统。这些实体中的每一个都与其他实体具有一对多的关系。
我的要求是通过REST API公开这些实体。我计划使用resteasy (当前产品运行在jboss-7上)。我的问题是,最好的设计方法是什么?
最初,我考虑使用带JAXB注释的DTO对象,并使用getter/setter转换所有实体。还有没有别的选择?
发布于 2016-06-21 19:23:09
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);https://stackoverflow.com/questions/37942897
复制相似问题