租房项目 用户认证 编辑资料

UserController代码

package com.yiju.controller;

import com.yiju.bean.UserAuth;
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 org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    public 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";
        }else {
            return "failure";
        }
    }
    @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("singup.do")
    @ResponseBody
    public String singup(@Param(value="phone")String phone,
                         @Param(value="password")String password){
        JSONObject jsonObject=new JSONObject();
     UserInfo user=userService.findByPhone(phone);
        if (user==null){
            userService.add(phone,password);
            jsonObject.put("result","0");
        }else {
            jsonObject.put("result","1");
        }
        /*if("123".equals(phone)&&"123".equals(password)){
            jsonObject.put("result","1");
        }else {
            jsonObject.put("result","2");
        }*/
        return jsonObject.toString();
    }






    @RequestMapping("saveEdit.do")
    @ResponseBody
    public String saveEdit(UserInfo userInfo,HttpSession session){
        JSONObject jsonObject=new JSONObject();
        UserInfo userInfo1=(UserInfo) session.getAttribute("user");

        userInfo1.setTruename(userInfo.getTruename());
        userInfo1.setNickname(userInfo.getNickname());
        userInfo1.setGender(userInfo.getGender());
        userInfo1.setCity(userInfo.getCity());
        userService.updateUserInfo(userInfo1);
        session.setAttribute("user",userInfo1);
        return jsonObject.toString();
    }



    @RequestMapping("verify.do")
    public ModelAndView verify(HttpSession session){

        UserInfo user=(UserInfo) session.getAttribute("user");
        UserAuth userAuth=userService.findUserAuth(user.getUserId());
        session.setAttribute("userAuth",userAuth);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("verify");
        return modelAndView;
    }


    @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.findByPhone(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");
        }
        /*if("123".equals(phone)&&"123".equals(password)){
            jsonObject.put("result","1");
        }else {
            jsonObject.put("result","2");
        }*/
        return jsonObject.toString();
    }



}


personalEdit代码

<%@ page import="com.yiju.bean.UserInfo" %><%--
  Created by IntelliJ IDEA.
  User: 36353
  Date: 2019-07-04
  Time: 14:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<html>
<head>
    <title>个人中心</title>
    <%--导入CSS文件--%>
    <link type="text/css" href="../css/css.css" rel="stylesheet"/>
    <%--<link rel="stylesheet" type="text/css" href="../css/city-select.css">--%>

    <script src="../js/jquery-2.1.1.min.js"></script>

</head>
<body>
<%--加入头部--%>
<jsp:include page="../pages/basehead.jsp"></jsp:include>

<!--Logo栏和手机号栏-->
<div class="logo-phone">
    <div class="width1190">

        <table align="center" width="100%">
            <tr>
                <td>
                    <h1 class="logo"><a href="../index.jsp"><img src="../images/logo.png" width="163" height="59"/></a>
                    </h1>
                </td>
                <td align="center">
                    <div class="phones"><strong>000-00000000</strong></div>
                    <div class="clears"></div>
                </td>

            </tr>
        </table>
    </div><!--width1190/-->
</div><!--logo-phone/-->
<!--Logo栏和手机号栏-->

<hr width="1190px">
<br>

<%--个人信息--%>

<!--个人信息-->


<div class="content">
    <div class="width1080">
        <%--左侧导航栏--%>
        <div class="vip-left">
            <div class="vipNav">
                <h3 class="vipTitle">账户中心</h3>
                <dl>
                    <dt class="vipIcon3">账户设置</dt>
                    <dd>
                        <a href="/user/personal.do" class="vipNavCur">我的资料</a>
                        <a href="/user/verify.do">实名认证</a>
                        <a href="/user/psdSet.do">账户密码设置</a>
                    </dd>
                    <dt class="vipIcon1">我的易居</dt>
                    <dd>
                        <a href="/user/favorite.do">我的收藏房源</a>
                    </dd>
                </dl>
            </div><!--vipNav/-->
        </div><!--vip-left/-->


        <div class="vip-right">
            <h3 class="vipright-title">编辑资料</h3>
            <table class="grinfo">
                <tbody>
                <% UserInfo userInfos = (UserInfo) request.getSession().getAttribute("user"); %>
                <tr>
                    <th><span class="red">*</span>手机号码:</th>
                    <td width="600px">
                        <input class="inp inw" type="text" id="phone" value="<%=userInfos.getPhone()%>" maxlength="14"
                               disabled="disabled">
                    </td>
                </tr>
                <tr>
                    <th><span class="red">*</span>真实姓名:</th>
                    <td>
                        <input class="inp inw" type="text" id="name" name="truename"
                               value="<% if(userInfos.getTruename()!=null) out.print(userInfos.getTruename()); %>"
                               maxlength="14">
                    </td>
                </tr>
                <tr>
                    <th><span class="red">*</span>昵  称:</th>
                    <td>
                        <input class="inp inw" type="text" id="title" name="nickname"
                               value="<% if(userInfos.getNickname()!=null) out.print(userInfos.getNickname());%>"
                               maxlength="14">
                    </td>
                </tr>
                <tr>
                    <th height="40px"><span class="red">*</span>性  别:</th>
                    <td height="40px">
                        <input type="radio" value="0" id="rbSex1"
                               name="sex" <%if(userInfos.getGender()==0) out.print("checked");%>>
                        <label for="rbSex1">男        </label>
                        <input type="radio" value="1" id="rbSex2"
                               name="sex" <%if(userInfos.getGender()==1) out.print("checked");%>>
                        <label for="rbSex2">女</label>
                        <span id="Sex_Tip"></span>
                    </td>
                </tr>
                <tr>
                    <th><span class="red">*</span>城  市:</th>
                    <td>
                        <input class="inp inw" type="text" name="city" id="city"
                               value="<% if(userInfos.getCity()!=null) out.print(userInfos.getCity());%>">
                    </td>
                </tr>
                <tr>
                    <th>&nbsp;</th>
                    <td colspan="2">
                        <label class="butt" id="butt">
                            <input type="button" class="member_mod_buttom" id="member_mod_buttom"
                                   name="member_mod_buttom" value="保存修改"/>
                            <a>  </a>
                            <input type="button" class="member_mod_buttom2"
                                   onclick="window.location.href='personal.jsp'" name="" value="取消修改"/>
                        </label>
                    </td>
                </tr>
                </tbody>
            </table>
        </div><!--vip-right/-->
        <div class="clearfix"></div>
    </div><!--width1190/-->
</div><!--content/-->
<!--End  个人信息填写栏>-->

<div>
    <br>
    <br>
    <br>
    <br>
</div>

<script src="../js/city/jquery1.8.1.js" type="text/javascript"></script>
<%--<script type="text/javascript" src="../js/city/citydata.min.js"></script>--%>
<%--<script type="text/javascript" src="../js/city/citySelect-1.0.3.js"></script>--%>
<script type="text/javascript">
    $(function () {
        $(".member_mod_buttom").on("click",function () {
            var truename=$("input[name=truename]").val();
            var nickname=$("input[name=nickname]").val();
            var gender;
            if($("#rbSex1").is(":checked")){
                gender=0;
            }
            if($("#rbSex2").is(":checked")){
                gender=1;
            }
            var city=$("input[name=city]").val();
            alert(truename+"----"+nickname+"---"+gender+"----"+city);
            if (truename==""){
                alert("请输入姓名!");
                return;
            }
            if(nickname==""){
                alert("请输入昵称!");
                return;
            }
            if (city==""){
                alert("请输入城市!");
                return;
            }
            $.ajax({
                url:"${pageContext.request.contextPath}/user/saveEdit.do",
                aync:true,
                type:"post",
                dataType:"json",
                data:{
                    truename:truename,
                    nickname:nickname,
                    gender:gender,
                    city:city
                },
                success:function (data) {
                    window.location.href="personal.jsp";
                }
            });
        });
    })
</script>


<!--这是页脚-->
<jsp:include page="../pages/basefoot.jsp"></jsp:include>


</body>
</html>

UserInfoMapper代码

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yiju.dao.IUserDao">
    <select id="findUserByPhone" parameterType="String" resultType="com.yiju.bean.UserInfo">
        select * from tb_user where phone=#{phone}
    </select>


    <insert id="singup" parameterType="String">
        insert into tb_user (phone,password) values (#{phone},#{password})
    </insert>


    <update id="updateUserInfo" parameterType="com.yiju.bean.UserInfo">
        update tb_user set truename=#{truename},nickname=#{nickname},gender=#{gender},city=#{city}
        where user_id=#{userId}
    </update>

    <select id="findUserAuthByUserId" parameterType="int">
        select * from tb_user_auth where user_Id=#{userId}
    </select>




</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值