易居主页点击登录跳转登录页面
UserController 中代码修改为
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("login.do")
@ResponseBody
public String login(@Param(value = "username") String username,
@Param(value = "password") String password){
if ("123".equals(username)&&"123".equals(password)){
return "success";
}
return "fail";
}
@RequestMapping("login1.do")
@ResponseBody
public String login1(@Param(value = "username") String username,
@Param(value = "password") String password){
JSONObject jsonObject=new JSONObject();
if ("123".equals(username)&&"123".equals(password)){
jsonObject.put("result","1");
}else {
jsonObject.put("result","2");
}
return jsonObject.toString();
}
@RequestMapping("login2.do")
@ResponseBody
public String login2(@Param(value = "phone") String phone,
@Param(value = "password") String password){
JSONObject jsonObject=new JSONObject();
UserInfo user=userService.findUserByPhone(phone);
if (user==null){
jsonObject.put("result","0");
}else if (!password.equals(user.getPassword())){
jsonObject.put("result","1");
}else {
jsonObject.put("result","2");
}
return jsonObject.toString();
}
}
新建接口IUserDao 接口中添加方法findUserByPhone
public interface IUserDao {
UserInfo findUserByPhone(String phone);
}
Service新建接口IUserService 接口中也添加方法findUserByPhone
public interface IUserService {
UserInfo findUserByPhone(String phone);
}
UserService中代码
@Service
public class UserService implements IUserService {
@Autowired
private IUserDao userDao;
@Override
public UserInfo findUserByPhone(String phone) {
return userDao.findUserByPhone(phone);
}
}
UserInfo中代码
package com.yiju.bean;
public class UserInfo {
public UserInfo() {
}
public UserInfo(int userId, String nickname, String truename, int gender, String city, long createTime) {
this.userId = userId;
this.nickname = nickname;
this.truename = truename;
this.gender = gender;
this.city = city;
this.createTime = createTime;
}
private int userId; //用户id
private String phone; //用户手机号,用于登录
private String password; //密码
private String email; //邮箱
private String nickname; //昵称
private String truename; //真实姓名
private int gender; //性别 0:男 1:女
private String province; //省份
private String city; //城市
private int isDelete; //是否删除 0:未删除 1:已删除
private long createTime; //创建时间
private long updateTime; //更新时间
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getTruename() {
return truename;
}
public void setTruename(String truename) {
this.truename = truename;
}
public int getGender() {
return gender;
}
public void setGender(int gender) {
this.gender = gender;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "UserInfo{" +
"userId=" + userId +
", phone='" + phone + '\'' +
", password='" + password + '\'' +
", email='" + email + '\'' +
", nickname='" + nickname + '\'' +
", truename='" + truename + '\'' +
", gender=" + gender +
", province='" + province + '\'' +
", city='" + city + '\'' +
", isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
UserController 中代码
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("log