项目控制层是用webwork做的,页面的表单自然就跟实体bean绑定了。在jsp中, <form action="saveAutoTable.action?tableName=table1" method="post">传一个表名在action中,jsp中的表单数据 在action中 得到该表名参数 String table_Name = httpRequest.getParameter("tableName"); System.out.println("com.hch.hcdoc.model.persist.auto.po."+table_Name);//table1 然后调用插入方法,autoTableService.save (table_Name);//此处应该为pojo实体类,而现在接受到的是个字符串 请问在调用save方法之前怎么将接受到的字符类型table_Name转换成pojo实体类。?????? 注明:表名和实体类名一致。 自定义表单中所有生成的动态表的curd操作分别只用一个方法进行,在自定义表单提交的时候传递表名进行区分,表名和实体类名一致。
使用apache的BeanUtils工具包吧, 提供一个接口BeanUtils.copyProperties(srcObj, targetObj)..
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addAuto.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<form action="saveAutoTable.action?tableName=table1" method="post">
<table cellspacing="0" bordercolordark="#ffffff" cellpadding="0" width="100%" bordercolorlight="#bebebe" border="1">
<tbody>
<tr>
<td align="center" width="80">ID</td>
<td align="left"><input maxlength="10" name="table1.id" type="text" value="444" /></td>
</tr>
<tr>
<td align="center" width="80">请假人</td>
<td align="left"><input maxlength="10" name="table1.column1" type="text" /></td>
</tr>
<tr>
<td align="center" width="80">请假时间</td>
<td align="left"><input maxlength="10" name="table1.column2" type="text" /></td>
</tr>
<tr>
<td align="center" width="80">请假天数</td>
<td align="left"><input maxlength="10" name="table1.column3" type="text" /></td>
</tr>
<tr>
<td align="center" width="80">审批人</td>
<td align="left"><input maxlength="10" name="table1.column4" type="text" /></td>
</tr>
<tr>
<td align="center" width="80"><input type="submit" value="ok" /></td>
<td align="left"></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
在webwork的action中public String save(){
ActionContext ctx = ActionContext.getContext();
HttpServletRequest httpRequest = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
String table_Name = httpRequest.getParameter("tableName"); String str = "com.hch.hcdoc.model.persist.auto.po."+table_Name;
Object d = (Object) ("com.hch.hcdoc.model.persist.auto.po."+table_Name);
// autoTableService.save((Object)"com.hch.hcdoc.model.persist.auto.po."+table_Name);
try {
Object t = Class.forName(str).newInstance();
autoTableService.save(t);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
autoTableService.save(d);
return SUCCESS;
}
急求该类的插入方法?????????????