public void createIDaoUtils() {
try {
String content = parseIDao();
String path = System.getProperty("user.dir") + "/src/main/java/" + I_mapper.replaceAll("\\.", "/");
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
String resPath = path + "/I" + initcap(tableNames.substring(2, tableNames.length())) + "Mapper.java";
FileUtils.writeStringToFile(new File(resPath), content);
System.out.println("建立dao接口类成功");
} catch (Exception e) {
e.printStackTrace();
}
}
private String parseIDao() {
StringBuffer sb = new StringBuffer();
sb.append("package " + I_mapper + ";\r\n\r\n");
sb.append("import com.unionbon.youlb.http.mapper.IBaseMapper;\r\n");
sb.append("import com.unionbon.youlb.http.domain."+initcap(tableNames.substring(2))+";\r\n\r\n");
//添加注解
sb.append("/**\r\n");
sb.append(" *\r\n");
sb.append(" * @author " + authors + "\r\n");
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
String date = sf.format(new Date());
sb.append(" * @time " + date + "\r\n");
sb.append(" * @desc \r\n");
sb.append(" */\r\n");
//类主体
String idType = "";
for (int i = 0; i < all_colnames.length; i++) {
String allColname = all_colnames[i];
if (allColname.equals("id")) {
idType = sqlType2JavaType(col_types[i]);
break;
}
}
sb.append("public interface I" + initcap(tableNames.substring(2)) + "Mapper extends IBaseMapper<"+initcap(tableNames.substring(2))+", "+idType+">{\r\n\r\n");
sb.append("}\r\n");
return sb.toString();
}
public void createDaoImplUtils() {
try {
String content = parseDaoImpl();
String path = System.getProperty("user.dir") + "/src/main/java/" + mapper_impl.replaceAll("\\.", "/");
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
String resPath = path + "/" + initcap(tableNames.substring(2, tableNames.length())) + "MapperImpl.java";
FileUtils.writeStringToFile(new File(resPath), content);
System.out.println("建立dao实现类成功");
} catch (Exception e) {
e.printStackTrace();
}
}
private String parseDaoImpl() {
StringBuffer sb = new StringBuffer();
sb.append("package " + mapper_impl + ";\r\n\r\n");
sb.append("import com.unionbon.youlb.http.mapper.impl.BaseMapperImpl;\r\n");
sb.append("import com.unionbon.youlb.http.mapper.I"+initcap(tableNames.substring(2))+"Mapper;\r\n");
sb.append("import com.unionbon.youlb.http.domain."+initcap(tableNames.substring(2))+";\r\n\r\n");
//添加注解
sb.append("/**\r\n");
sb.append(" *\r\n");
sb.append(" * @author " + authors + "\r\n");
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
String date = sf.format(new Date());
sb.append(" * @time " + date + "\r\n");
sb.append(" * @desc \r\n");
sb.append(" */\r\n");
//类主体
String idType = "";
for (int i = 0; i < all_colnames.length; i++) {
String allColname = all_colnames[i];
if (allColname.equals("id")) {
idType = sqlType2JavaType(col_types[i]);
break;
}
}
sb.append("public class " + initcap(tableNames.substring(2)) + "MapperImpl extends BaseMapperImpl<"+initcap(tableNames.substring(2))+", "+idType+"> implements I"+initcap(tableNames.substring(2))+"Mapper{\r\n\r\n");
sb.append("}\r\n");
return sb.toString();
}