问题描述
ssh整合好了,数据库表只有三个字段id(主键)、name、password;这是数据库表的映射类packagecom.cc.pojo;publicclassPeople{privateintid;privateStringname;privateStringpassword;publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}}-----------------------------------------------------------这是LoginAction(留意login方法输出的id)packagecom.cc.action;importjavax.servlet.http.HttpSession;importorg.apache.struts2.ServletActionContext;importcom.cc.pojo.People;importcom.cc.service.IUservice;importcom.opensymphony.xwork2.ActionContext;importcom.opensymphony.xwork2.ActionSupport;publicclassLoginActionextendsActionSupport{privateIUserviceuserService;privatePeoplepeople=null;publicIUservicegetUserService(){returnuserService;}publicvoidsetUserService(IUserviceuserService){this.userService=userService;}publicPeoplegetPeople(){returnpeople;}publicvoidsetPeople(Peoplepeople){this.people=people;}publicStringlogin(){System.out.println(people.getId()+people.getName());if(userService.login(people)){HttpSessionsession=ServletActionContext.getRequest().getSession();session.setAttribute("people",people);returnSUCCESS;}else{returnERROR;}}}--------------------------------------这是登录的表单<body><formaction="login"method="post">用户名:<inputtype="text"name="people.name"/><br/>密码:<inputtype="password"name="people.password"/><br/><inputtype="submit"value="登录"/><inputtype="reset"value="重置"/></form></body>我的数据库表有几条记录,id都不同但是无论用那条记录登录进去,控制台输出的people.getId都是0所以我登录后很难进行更新用户信息求高手解答!
解决方案
解决方案二:
你又没有查询数据库,id当然为0了!表单传过来name和password,然后再查表判断是否正确!所以你得先查表啊
解决方案三:
people是空对象吧没有主键
解决方案四:
根据name和password去数据库查一下people对象,然后输出id
解决方案五:
people的id你跟本没取,但是people的name和password应该是有值的,就是你在登陆页面输入的值
解决方案六:
肯定打出来是0啊。你这样的话只是收集到了name和password,要先根据这两个条件去数据库里面穿查出对应的数据,再用对象接收,然后通过那个对象才能拿到id!