/**
*
*/
package com.autobuild.base.bean.install;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author zym
* @date 2014-8-31
*/
@SuppressWarnings("unchecked")
public class BeanUtils {
//需要修改的部分基本路径
private static final String ROOT_ADDRESS = "com/autobuild/base/";
private static final String ROOT_PACKAGE = "com.autobuild.base.";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://127.0.0.1:3306/xire";
private static final String USERNAME = "root";
private static final String PASSWORD = "1234";
private static final String HIBERNATEDIALECT = "org.hibernate.dialect.MySQLDialect";
//公共部分
private static final String RT_1 = "\r\n";
private static final String RT_2 = RT_1+RT_1;
private static final String RT_3 = "\t";
private static final String BLANK_1 =" ";
private static final String BLANK_4 =" ";
private static final String BLANK_8 =BLANK_4 + BLANK_4;
//注释部分
private static final String ANNOTATION_AUTHOR_PARAMTER = "@author ";
private static final String ANNOTATION_AUTHOR_NAME = "zym";
private static final String ANNOTATION_AUTHOR = ANNOTATION_AUTHOR_PARAMTER + ANNOTATION_AUTHOR_NAME;
private static final String ANNOTATION_DATE = "@date ";
private static final String ANNOTATION = "/**"+RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_AUTHOR +RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_DATE +getDate()+RT_1+BLANK_1+"*/"+RT_1;
//文件 地址
//private static final String BEAN_PATH = "com/autobuild/base/bean";
private static final String DAO_PATH = ROOT_ADDRESS+"dao";
private static final String DAO_IMPL_PATH = ROOT_ADDRESS+"dao/impl";
private static final String SERVICE_PATH = ROOT_ADDRESS+"service";
private static final String SERVICE_IMPL_PATH = ROOT_ADDRESS+"service/impl";
//包名
private static final String BEAN_URL = ROOT_PACKAGE+"bean";
private static final String DAO_URL = ROOT_PACKAGE+"dao";
private static final String DAO_IMPL_URL = ROOT_PACKAGE+"dao.impl";
private static final String SERVICE_URL = ROOT_PACKAGE+"service";
private static final String SERVICE_IMPL_URL = ROOT_PACKAGE+"service.impl";
//基本类名称
private static final String BASE_DAO_NAME = DAO_URL + ".BaseDao";
private static final String ABSTRACT_BASE_DAO_IMPL_NAME = DAO_IMPL_URL + ".AbstractBaseDaoImpl";
private static final String BASE_SERVICE_NAME = SERVICE_URL + ".BaseService";
private static final String ABSTRACT_BASE_SERVICE_IMPL_NAME = SERVICE_IMPL_URL + ".AbstractBaseServiceImpl";
/**
* 创建bean的Dao<br>
*
* @param c
* @throws Exception
*/
public void createBeanDao(Class c) throws Exception {
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_PATH
+ "/" + getLastChar(cName) + "Dao.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Dao extends "+BASE_DAO_NAME+" <" + cName + "> {"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的Dao的实现类
* @param c
* @throws Exception
*/
public void createBeanDaoImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_IMPL_PATH
+ "/" + getLastChar(cName) + "DaoImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_IMPL_URL+";"+RT_2+ANNOTATION+"public class " +
getLastChar(cName) + "DaoImpl extends "+ABSTRACT_BASE_DAO_IMPL_NAME+"<" +
cName + "> implements "+DAO_URL+"."+getLastChar(cName)+"Dao{"+RT_2+"//本类继承了常用的公共方法,如需额外方法可自己在本类中进行定义!"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service
* @param c
* @throws Exception
*/
public void createBeanService(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_PATH
+ "/" + getLastChar(cName) + "Service.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Service extends "+BASE_SERVICE_NAME+"<"+ cName +">{"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service的实现类
* @param c
* @throws Exception
*/
public void createBeanServiceImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_IMPL_PATH
+ "/" +getLastChar(cName)+"ServiceImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_IMPL_URL+";"+RT_2+ANNOTATION+"public class "
+ getLastChar(cName) + "ServiceImpl extends "+ABSTRACT_BASE_SERVICE_IMPL_NAME+"<"+ cName
+ "> implements "+SERVICE_URL+"."+getLastChar(cName)+"Service{"+RT_2+BLANK_4
+"private "+DAO_URL+"."+getLastChar(cName)+"Dao "+getLowercaseChar(getLastChar(cName))
+"Dao;"+RT_2+BLANK_4+"public void set"+getLastChar(cName)+"Dao("+DAO_URL+"."+getLastChar(cName)+"Dao "
+getLowercaseChar(getLastChar(cName))+"Dao){"+RT_1+BLANK_8+"this."+getLowercaseChar(getLastChar(cName))+"Dao = "
+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+BLANK_4+"@Override"+RT_1+BLANK_4
+"public "+DAO_URL+"."+"BaseDao<"+BEAN_URL+"."+getLastChar(cName)+"> getBaseDao(){"+RT_1+BLANK_8
+"return "+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的action类
* @param c
* @throws Exception
*/
public void createBeanAction(Class c) throws Exception{
String cName = c.getName();
String lastCharClassName=getLastChar(cName);
String fileName = System.getProperty("user.dir") + "/src/" + ROOT_ADDRESS
+ "action/"+lastCharClassName+"Action.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+ROOT_PACKAGE+"action;"+RT_2
+"import java.util.List;"+RT_1
+"import java.util.Map;"+RT_1
+"import net.sf.json.JSONArray;"+RT_1
+"import com.opensymphony.xwork2.ActionContext;"+RT_1
+"import com.opensymphony.xwork2.ActionSupport;"+RT_1
+"import "+ROOT_PACKAGE+"service."+getLastChar(cName)+"Service;"+RT_2
+ANNOTATION+"public class "
+ lastCharClassName + "Action extends ActionSupport{"+RT_2
+RT_3+"private"+BLANK_1+""+getLastChar(cName)+"Service"+BLANK_1+getLowercaseChar(lastCharClassName)+"service;"+RT_2
+RT_3+"public"+BLANK_1+" "+getLastChar(cName)+"Service"+" get"+getLastChar(cName)+"service() {"+RT_2
+RT_3+RT_3+"return"+BLANK_1+" "+getLowercaseChar(lastCharClassName)+"service;"+RT_2
+RT_3+"}"+RT_2
+RT_3+"public"+BLANK_1+"void"+BLANK_1+"set"+getLastChar(cName)+"service"+"("+getLastChar(cName)+"Service "+getLowercaseChar(lastCharClassName)+"service){ "+RT_2
+RT_3+RT_3+"this."+getLowercaseChar(lastCharClassName)+"service = "+getLowercaseChar(lastCharClassName)+"service;"+RT_2
+RT_3+"}"+RT_2
+RT_3+"public String execute(){"+RT_2
+RT_3+RT_3+"try {"+RT_2
+RT_3+RT_3+RT_3+"Map request = (Map) ActionContext.getContext().get(\"request\");"+RT_2
+RT_3+RT_3+RT_3+"request.put(\"list\", \"放结果集\");"+RT_2
+RT_3+RT_3+RT_3+"} catch (Exception e) {"+RT_2
+RT_3+RT_3+RT_3+"e.printStackTrace();"+R
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本工程是基于ssh框架的后台自动生成工具,该工具可以生成dao,daoImpl,service,serviceImpl,Action,applicationContext.xml,struts.xml,web.xml文件,可以使开发人员尽量少的进行编写重复代码以及避免一些错误。
资源推荐
资源详情
资源评论
收起资源包目录
java web ssh框架 后台系统自动生成工具 (208个子文件)
BeanUtils.class 15KB
XrProductBasic.class 13KB
JsonLibUtils.class 6KB
PubFun.class 5KB
AbstractBaseDaoImpl.class 3KB
AppendFile.class 3KB
AbstractBaseServiceImpl.class 3KB
FDate.class 2KB
XrProductBasicAction.class 2KB
PubListDate$1.class 2KB
AbstractBaseDaoImpl$2.class 2KB
XmlJSON.class 2KB
AbstractBaseDaoImpl$1.class 1KB
BeanUtilGO.class 1KB
JsonLibUtils$1.class 1KB
PubListDate.class 1KB
XrProductBasicServiceImpl.class 1KB
BaseService.class 603B
BaseDao.class 591B
XrProductBasicDaoImpl.class 579B
XrProductBasicService.class 319B
XrProductBasicDao.class 291B
Base.class 285B
.classpath 11KB
org.eclipse.wst.jsdt.ui.superType.container 49B
readme.doc 169KB
spring.jar 2.57MB
hibernate3.jar 1.87MB
aspectjweaver.jar 1.8MB
jasperreports-1.3.4.jar 1.61MB
axis.jar 1.53MB
xwork-core-2.1.6.jar 1.49MB
oracle.jar 1.47MB
itext-1.3.jar 1.09MB
SwetakeQRCode.jar 1014KB
xerces-2.6.2.jar 987KB
db-ojb-1.0.4.jar 917KB
xfire-all-1.2.6.jar 883KB
jasperreports-1.0.2.jar 829KB
freemarker-2.3.8.jar 784KB
poi-2.5.1.jar 783KB
freemarker.jar 767KB
struts2-core-2.1.8.1.jar 738KB
jxl.jar 597KB
c3p0-0.9.1.2.jar 596KB
commons-collections-3.2.1.jar 562KB
commons-collections-3.1.jar 546KB
struts.jar 537KB
mysql-connector-java-5.0.3-bin.jar 482KB
c3p0-0.9.0.jar 476KB
javassist.jar 460KB
antlr-2.7.6.jar 433KB
antlr-2.7.5H3.jar 423KB
xfire-core-1.2.6.jar 414KB
jboss-archive-browsing.jar 404KB
velocity-1.5.jar 383KB
spring-beans.jar 381KB
mail-1.4.jar 380KB
log4j-1.2.14.jar 359KB
jmxri.jar 357KB
spring-orm.jar 356KB
velocity-1.4.jar 353KB
antlr.jar 350KB
log4j-1.2.12.jar 350KB
log4j-1.2.9.jar 344KB
log4j-1.2.11.jar 342KB
quartz-1.5.0.jar 324KB
cglib-nodep-2.1_3.jar 317KB
cglib-nodep-2.1_2.jar 317KB
dom4j-1.6.1.jar 307KB
dom4j-1.6.jar 306KB
spring-aop.jar 301KB
commons-httpclient-3.1.jar 298KB
ibatis-sqlmap-2.jar 284KB
spring-webmvc.jar 279KB
commons-lang-2.6.jar 278KB
cglib-2.1.3.jar 276KB
hibernate-annotations.jar 273KB
commons-httpclient.jar 273KB
commons-beanutils-1.8.3.jar 227KB
spring-jdbc.jar 222KB
jaxen-1.1-beta-7.jar 222KB
xml-apis.jar 215KB
ehcache-1.2.3.jar 203KB
commons-lang.jar 203KB
jmxremote_optional.jar 202KB
commons-beanutils.jar 184KB
spring-core.jar 178KB
sitemesh-2.3.jar 178KB
commons-net-1.4.1.jar 177KB
xbean-spring-2.8.jar 175KB
jmxremote.jar 172KB
commons-collections-2.1.1.jar 171KB
commons-digester.jar 164KB
ognl-2.6.11.jar 164KB
spring-context.jar 157KB
jdom.jar 150KB
spring-web.jar 149KB
xfire-aegis-1.2.6.jar 128KB
spring-dao.jar 127KB
共 208 条
- 1
- 2
- 3
我是鳄鱼头领
- 粉丝: 32
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- PMSM Electrical Parameters Measurement by: Viktor Bobek
- 计算机语言学中JavaScript课件
- 钱浩栋国奖经验分享等7个文件.zip
- 单片机装置中步进电机伺服系统的缺陷及其优化设计
- C#ASP.NET+SQL2008通用权限管理系统源码数据库 SQL2008源码类型 WebForm
- 2024中国数据安全企业全景图和典型数据安全产品案例集
- 前端开发vue777777
- 课程设计-基于MATLAB的数字仪表图像识别系统+项目源码+文档说明+课题介绍+GUI界面
- 课程设计-基于MATLAB光流法OCR的手写数字识别系统+项目源码+文档说明+课题介绍+GUI界面
- 课程设计-基于MATLAB的肤色的人数统计系统+项目源码+文档说明+课题介绍+GUI界面
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页