首页 新闻 会员 周边 捐助

SSM框架中为什么登录时po 为空???

0
[已关闭问题] 关闭于 2017-04-15 20:42

controll

@Controller

public class SystemHandler {

@Autowired

private UserinfoService us;

public UserinfoService getUs() { return us; }

public void setUs(UserinfoService us) { this.us = us; }

@RequestMapping(value="/login.action")

public String login(LoginVO vo, HttpSession session) throws Exception{ UserinfoPO po=us.validateLogin(vo);

if(po != null){

session.setAttribute("online", po);

return "redirect:/main.jsp";

}else{

System.out.println("显示内容");

System.out.println(vo.getUname());

System.out.println(po);

 

return "redirect:/main.jsp"; }

}

}

service

public interface UserinfoService {

public UserinfoPO validateLogin(LoginVO vo) throws Exception;

public List getDeptList(DeptListVO vo) throws Exception;

public int getDeptListCount(DeptListVO vo) throws Exception;

public DeptPO getDeptDetaiByID(int deptid) throws Exception;

}

service.impl

@Service

public class UserinfoServiceImpl implements UserinfoService{

@Autowired

private UserInfoMapper mapper;

public UserInfoMapper getMapper() {

return mapper;

} public void setMapper(UserInfoMapper mapper) {

this.mapper = mapper;

} @Override

public UserinfoPO validateLogin(LoginVO vo) throws Exception {

// TODO Auto-generated method stub System.out.println(vo.getUname()+'\n'+vo.getUpass());

return mapper.selectUserinfoByNameAndPass(vo);

}

@Override

public List getDeptList(DeptListVO vo) throws Exception {

// TODO Auto-generated method stub vo.setStart(PageUtil.getStartIndex(vo.getPagenum())); vo.setEnd(PageUtil.getEndIndex(vo.getPagenum()));

return mapper.selectDeptList(vo);

} @Override

public DeptPO getDeptDetaiByID(int deptid) throws Exception {

// TODO Auto-generated method stub return mapper.selectDeptDetailByID(deptid);

}

@Override

public int getDeptListCount(DeptListVO vo) throws Exception {

// TODO Auto-generated method stub return mapper.selectDeptListCount(vo); }

}

mapper

ublic interface UserInfoMapper {

public UserinfoPO selectUserinfoByNameAndPass(LoginVO vo) throws Exception; public int selectDeptListCount(DeptListVO vo) throws Exception;

public List selectDeptList(DeptListVO vo) throws Exception;

public DeptPO selectDeptDetailByID(int deptid) throws Exception;

}

po

public class UserinfoPO {

private String userid; private String username;

private String userpass; private Date BIRTHDAY;

private DeptPO dept;

public String getUserid() { return userid; }

public void setUserid(String userid) {

this.userid = userid; }

public String getUsername() { return username; }

public void setUsername(String username) { this.username = username; } public String getUserpass() { return userpass; }

public void setUserpass(String userpass) { this.userpass = userpass; }

public Date getBIRTHDAY() { return BIRTHDAY; }

public void setBIRTHDAY(Date bIRTHDAY) { BIRTHDAY = bIRTHDAY; }

public DeptPO getDept() { return dept; }

public void setDept(DeptPO dept) { this.dept = dept; }

@Override

public String toString() { return "UserinfoPO [userid=" + userid + ", username=" + username + ", userpass=" + userpass + ", BIRTHDAY=" + BIRTHDAY + ", dept=" + dept + "]"; } }

vo

public class LoginVO { private String uname; private String upass;

public String getUname() { return uname; }

public void setUname(String uname) { this.uname = uname; }

public String getUpass() { return upass; } public void setUpass(String upass) { this.upass = upass; } }

day789的主页 day789 | 菜鸟二级 | 园豆:204
提问于:2017-04-12 21:08
< >
分享
所有回答(1)
0

po的类属性要与mapper.xml文件中的resultMap设置一致 po中的类与类之间最好不要有联系 userinfoPO中没有存储dept的属性 。Select查询输出的应该是id,name,pass,BIRTHDAY而实际select输出的是id,name,pass,BIRTHDAY和deptid,dmane,loc使得定义的UserinfoPO类溢出而无法注入,再就测试SQL语句是否出错。

day789 | 园豆:204 (菜鸟二级) | 2017-04-15 20:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册