易居完成注册页和个人中心页

接上一篇博客
代码有改动和增加的我都贴在下面了
UserController 中代码

package com.yiju.controller;

import com.yiju.bean.UserInfo;
import com.yiju.service.IUserService;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@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,
                         HttpSession session){
        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 {
            session.setAttribute("user",user);
            jsonObject.put("result","2");
        }
        return jsonObject.toString();
    }

    @RequestMapping("signup.do")
    @ResponseBody
    public String signup(@Param(value = "phone") String phone,
                         @Param(value = "password") String password){
        JSONObject jsonObject=new JSONObject();
        UserInfo user=userService.findUserByPhone(phone);
        if (user==null){
            userService.add(phone,password);
            jsonObject.put("result","0");
        }else {

            jsonObject.put("result","1");
        }
        return jsonObject.toString();
    }
}

IUserDao 中代码

package com.yiju.dao;
import com.yiju.bean.UserInfo;
import org.apache.ibatis.annotations.Param;

public interface IUserDao {
    UserInfo findUserByPhone(String phone);
    void signup(@Param("phone") String phone, @Param("password") String password);
}

IUserService 中代码

package com.yiju.service;

import com.yiju.bean.UserInfo;

public interface IUserService {
    UserInfo findUserByPhone(String phone);
    void add(String phone, String password);
}

UserService 中代码

package com.yiju.service.Impl;

import com.yiju.bean.UserInfo;
import com.yiju.dao.IUserDao;
import com.yiju.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService implements IUserService {

    @Autowired
    private IUserDao userDao;

    @Override
    public UserInfo findUserByPhone(String phone) {
        return userDao.findUserByPhone(phone);
    }

    @Override
    public void add(String phone, String password) {
        userDao.signup(phone,password);
    }
}

basehead.jsp中代码

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>页头</title>
    <!--    下面是几个导入的包-->
    <link type="text/css" href="${pageContext.request.contextPath}/css/css.css" rel="stylesheet" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/js.js"></script>
</head>
<body>

<!--头部最上方的框-->
<div class="header">
    <div class="width1190">
        <div class="fl" style="font-size: 14px">您好,欢迎来到<a href="${pageContext.request.contextPath}/index.jsp">易居住房信息平台!</a></div>
        <div class="fr">
            <a href="${pageContext.request.contextPath}/pages/login.jsp" style="font-size: 14px" target="_blank"><strong>登录</strong></a> |
            <a href="${pageContext.request.contextPath}/pages/signup.jsp" style="font-size: 14px" target="_blank"><strong>注册</strong></a>
            <a  style="font-size: 14px">欢迎使用</a> |
            <a href="pages/personal.jsp" style="font-size: 14px" target="_blank"><strong>个人中心</strong></a> |
            <a href="#" style="font-size: 14px"><strong>退出</strong></a> |
            <a href="javascript:;" onclick="" style="font-size: 14px">加入收藏</a> |
            <a href="javas
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值