| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1769 人关注过本帖
标题:Java web ssm框架登录时为什么po为空
只看楼主 加入收藏
Alikce
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-6-11
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:4 
Java web ssm框架登录时为什么po为空
程序代码:
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:/index.jsp"; 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的主页


[此贴子已经被作者于2017-4-12 21:24编辑过]

搜索更多相关主题的帖子: Java 
2017-04-12 21:23
孤独与烈酒
Rank: 5Rank: 5
来 自:山西省运城市
等 级:贵宾
威 望:16
帖 子:47
专家分:310
注 册:2016-9-26
收藏
得分:7 
后台报错吗,看看你的sql语句有没有问题呢
2017-04-13 08:57
Alikce
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-6-11
收藏
得分:0 
不报错 但是po显示为空 if判断时会跳转到重新登录 service.impl层 return mapper.selectDeptList(vo);返回的是空类型

[此贴子已经被作者于2017-4-13 13:56编辑过]

2017-04-13 13:55
Alikce
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-6-11
收藏
得分:0 
po的类属性要与mapper.xml文件中的resultMap设置一致 po中的类与类之间最好不要有联系 userinfoPO中没有存储dept的属性 。Select查询输出的应该是id,name,pass,BIRTHDAY而实际select输出的是id,name,pass,BIRTHDAY和deptid,dmane,loc使得定义的UserinfoPO类溢出而无法注入,再就测试SQL语句是否出错。
2017-04-15 20:40
漫步云端24
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:47
专家分:347
注 册:2017-4-24
收藏
得分:0 
2017-04-24 13:29
快速回复:Java web ssm框架登录时为什么po为空
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021688 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved