📄 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 + -