Java creates mapping files based on entity classes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.