paip.提升效率---request自动绑定domain object
#.keyword,subtitle关键字,子标题
-------------------------
复制request属性到个域对象
#pseudo code伪码 处理流程
--------------------------
首先,html设置控件id,name..为自动绑定准备...
form action到个一个mvc url,自动request obj
忽视大小写,map操作 reqeuest map
BeanUtils使用自动绑定到个域物体..
作者 老哇的爪子 Attilax 艾龙, EMAIL:
[email protected]
来源: http://blog.csdn.net/attilax
#actual code 实际代码如下
----------------
public void saveVistInvtSet(HttpServletRequest request) {
// todox Apache的BeanUtils的使用入门 enhance effice
Map parameterMap = request.getParameterMap();
Map mp=listUtil.caseIngor(parameterMap);
TProbeInvite o = new TProbeInvite();
try {
BeanUtils.copyProperties(o, mp);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
core.log(jsonUtil.toString(o));
// //String name = req.getParameter("name");
// core.log("--get param name:"+name);
// o.setName(name);
TProbeInviteDAO d = new TProbeInviteDAO();
Session session = d.getSession();
Transaction tx = session.beginTransaction();
d.save(o);
tx.commit();
}
/**
* ]o4f notice:the map val obj is a objArr..maybe for checkbox
* @param parameterMap
* @return
*/
public static Map caseIngor(Map<String,Object> parameterMap) {
Map m=new HashMap();
for (String key : parameterMap.keySet()) {
Object obj = parameterMap.get(key);
core.log("key:"+key);
core.log("objtype:"+ obj.getClass().getName() );
String[] a=( String[])obj;
if(a.length>0)
{
// obj.
m.put(key,a[0]);
m.put(key.toLowerCase(),a[0]);
// m.put(key, obj.toString());
// m.put(key.toLowerCase(), obj.toString());
// 设置参数
// PropertyUtils.setProperty(user2, key, ConvertUtils.convert(parameterMap.get(key), type));
} }
return m;
}