question

Benjo-1938 avatar image
0 Votes"
Benjo-1938 Suspended asked DanielZhang-MSFT commented

How to create a simple Model for Rest

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


dotnet-csharp
gridview.jpg (17.6 KiB)
unbenannt.jpg (30.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Benjo-1938,
For the c# part of the code, what problems did you encounter? Please explain in detail.
Best Regards,
Daniel Zhang

0 Votes 0 ·

0 Answers