?? suserinfodao.java
字號:
package com.zhou.services;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import com.zhou.dao.IRoleDAO;
import com.zhou.dao.IUserinfoDAO;
import com.zhou.dao.RoleDAO;
import com.zhou.dao.UserinfoDAO;
import com.zhou.po.Userinfo;
import com.zhou.struts.form.UserinfoForm;
public class SUserinfoDAO implements ISUserinfoDAO {
UserinfoDAO iUserinfoDAO;
public SUserinfoDAO() {
iUserinfoDAO = new UserinfoDAO();
}
/*
* (non-Javadoc)
*
* @see com.zhou.services.ISUserinfoDAO#save(com.zhou.po.Userinfo)
*/
public Userinfo ConverterUserinfoForm(ActionForm form) {
Userinfo entity = new Userinfo();
try {
BeanUtils.copyProperties(entity, form);
} catch (IllegalAccessException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
return entity;
}
public void save(UserinfoForm userinfoForm) throws Exception {
Userinfo u = this.ConverterUserinfoForm(userinfoForm);
RoleDAO iRoleDAO = new RoleDAO();
try {
System.out.print(userinfoForm.getRid());
u.setRole(iRoleDAO.findById(userinfoForm.getRid().longValue()));
} catch (Exception e) {
throw new java.lang.Exception("轉換異常。。");
}
if (iUserinfoDAO.findByUsername(userinfoForm.getUsername()).size() == 0) {
iUserinfoDAO.save(u);
} else {
throw new java.lang.Exception("重復的用戶名");
}
}
public List read() throws Exception {
return iUserinfoDAO.findByAll();
}
public void delete(Integer id) throws Exception {
iUserinfoDAO.delete(iUserinfoDAO.findById(id.longValue()));
}
public UserinfoForm login(String username,String userpwd) throws Exception {
List list = iUserinfoDAO.login(username, userpwd);
if (iUserinfoDAO.login(username, userpwd).size()==0) {
throw new java.lang.Exception("登錄失敗...");
}
else{
UserinfoForm u = new UserinfoForm();
u.setUserid(new Integer(((Userinfo)list.get(0)).getUserid().toString()));
u.setRid(new Integer(((Userinfo)list.get(0)).getRole().getRid().toString()));
return u;
}
}
public Userinfo findById(java.lang.Long id){
return iUserinfoDAO.findById(id);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -