Import Java.io.file;import java.io.fileoutputstream;import java.io.ioexception;import Java.lang.reflect.Field; Import Java.util.list;import java.util.set;import com.mohe.model.entity.teach;/** * Generate mapping files based on entity class * * @author DXM * */PUBL IC class Objecttomapping {/** * Converts an entity class to a mapping file * * @param CLS * Entity class * @param the root directory where file * map files are stored * @para M ID * PRIMARY KEY field name * @param identity * Primary key is automatically represented column * @return * @throws IOException */public Static Boolean Convert (Class cls, file file, String ID, Boolean identity) throws IOException {if (null = = CLS | | File = NULL) {return FA LSE;} if (!file.exists ()) {file.mkdirs ();} File = new file (File.getabsolutepath () + "\ \" + cls.getsimplename () + ". Hbm.xml"), if (File.exists ()) {File.delete ();} String str = ""; FileOutputStream fs = new FileOutputStream (file), Fs.write ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "? >\n". GetBytes ("UTF-8")); Fs.write ("<! DOCTYPE hibernate-mapping public\n ". GetBytes (" UTF-8 "); Fs.write (" \ "-//hibernate/hibErnate Mapping DTD 3.0//en\ "\ n". GetBytes ("UTF-8"); Fs.write ("\" http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd\ ">\n". GetBytes ("UTF-8")); str = "
Java creates mapping files based on entity classes