How to create a simple Model for Rest

Benjo 1 Reputation point
2021-05-31T10:12:20.043+00:00

package mypackage.model;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.File;

public class Model {
private static Model instance;
private Employees employees;
private final String XML_PATH="data.xml";

public static  Model getInstance(){  
    if(instance==null){  
        instance=new Model();  
    }  
    return instance;  
}  
private Model(){  
    JAXBContext jaxbContext = null;  
    try {  
        jaxbContext = JAXBContext.newInstance(Employees.class);  
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();  
        employees = (Employees) jaxbUnmarshaller.unmarshal(new File(XML_PATH));  

    } catch (JAXBException e) {  
        e.printStackTrace();  
    }  
}  
public Employees getEmployees(){  
    return employees;  
}  
public void save(){  
    JAXBContext jaxbContext = null;  
    try {  
        jaxbContext = JAXBContext.newInstance(Employees.class);  
        Marshaller marshaller = jaxbContext.createMarshaller();  
        marshaller.marshal(employees, new File(XML_PATH));  
    } catch (JAXBException e) {  
        e.printStackTrace();  
    }  
}  

}

And heer something for C#:

100999-gridview.jpg

101055-unbenannt.jpg

Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.