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
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;
}