wl_management/src/test/java/com/lz/mysql/MysqlUtilTable2Mapper.java
2020-08-10 17:17:56 +08:00

94 lines
2.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.lz.mysql;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MysqlUtilTable2Mapper {
public static String TAB = " ";
public static void printDao(TablesBean tableBean) {
String realName = MysqlMain.pre + tableBean.getSpaceName();
String fileName = MysqlMain.save_path + "/" + realName + "Mapper.java";
try {
String content = "package com.admin.mapper;\n";
content += "/**\n";
content += "* <p>\n";
content += "* " + tableBean.getComment() + " 服务类\n";
content += "* </p>\n";
content += "*\n";
content += "* @author quyixiao\n";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
content += "* @since " + format.format(new Date()) + "\n";
content += "*/\n";
content += "import org.apache.ibatis.annotations.Mapper;\n";
content += "import org.apache.ibatis.annotations.Param;\n";
content += "@Mapper\n";
content += "public interface " + realName + "Mapper extends BaseMapper<" + realName + "> {";
content += "\n";
content += "\n";
content += "\n";
content += TAB + realName + " select" + realName + "ById(@Param(\"id\")Long id);";
content += "\n";
content += "\n";
content += "\n";
content += TAB + "Long insert" + realName + "(" + realName + " " + tableBean.getJavaName() + ");";
content += "\n";
content += "\n";
content += "\n";
content += TAB + "int update" + realName + "ById(" + realName + " " + tableBean.getJavaName() + ");";
content += "\n";
content += "\n";
content += "\n";
content += TAB + "int updateCover" + realName + "ById(" + realName + " " + tableBean.getJavaName() + ");";
content += "\n";
content += "\n";
content += "\n";
content += TAB + "int delete" + tableBean.getSpaceName() + "ById(@Param(\"id\")Long id);";
content += "\n";
content += "\n";
content += "\n";
content += "}";
FileOutputStream fos = new FileOutputStream(fileName);
Writer out = new OutputStreamWriter(fos, "UTF-8");
out.write(content);
out.close();
fos.close();
System.out.println("===" + realName + "Mapper.java" + "生成");
// 打开一个写文件器构造函数中的第二个参数true表示以追加形式写文件
// FileWriter writer = new FileWriter(fileName, false);
// writer.write(content);
// writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}