手机登入注册为什么出现这个错误?

版权声明:本文为博主原创文章,未经博主允许不得转载。如有问题,欢迎指正。 https://blog.csdn.net/qq_30225725/article/details/87278524

在这里插入图片描述
一点击登入 出现这个错误

在这里插入图片描述

我想要把页面输入的手机号 存到数据库中login_phone
数据库

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `login_phone` int(11) NOT NULL COMMENT '手机登录',
  `username` varchar(0) DEFAULT NULL COMMENT '用户名',
  `phone` int(11) DEFAULT NULL COMMENT '联系电话',
  `profession` varchar(20) DEFAULT NULL COMMENT '职业身份',
  `age` int(11) DEFAULT NULL COMMENT '年龄',
  `salary_type` varchar(0) DEFAULT NULL COMMENT '工资形式',
  `salary` varchar(0) DEFAULT NULL COMMENT '工资',
  `company_type` varchar(0) DEFAULT NULL COMMENT '公司类型',
  `slow` int(11) DEFAULT NULL COMMENT '流水',
  `work_time` int(11) DEFAULT NULL COMMENT '工龄',
  `credit_status` varchar(0) DEFAULT NULL COMMENT '信用状态',
  `commit_protect` varchar(0) DEFAULT NULL COMMENT '社保',
  `community_time` varchar(0) DEFAULT NULL COMMENT '社保缴纳时间',
  `gongjijin` varchar(0) DEFAULT NULL COMMENT '住房公积金',
  `gjjtime` varchar(0) DEFAULT NULL COMMENT '公积金时间',
  `house_type` varchar(0) DEFAULT NULL COMMENT '房产类型',
  `house_age` int(11) DEFAULT NULL COMMENT '房龄',
  `house_price` int(11) DEFAULT NULL COMMENT '房产估值',
  `house_card` tinyint(1) DEFAULT NULL COMMENT '房产证能否提供',
  `car` tinyint(1) DEFAULT NULL COMMENT '名下有车否',
  `car_price` int(11) DEFAULT NULL COMMENT '车辆估值',
  `Column_26` char(10) DEFAULT NULL,
  `Column_27` char(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='贷款用户表';


对应的Dao层是

package com.firstblood.financial.model;

public class User {
    private Integer id;

    private Integer loginPhone;

    private String username;

    private Integer phone;

    private String profession;

    private Integer age;

    private String salaryType;

    private String salary;

    private String companyType;

    private Integer slow;

    private Integer workTime;

    private String creditStatus;

    private String commitProtect;

    private String communityTime;

    private String gongjijin;

    private String gjjtime;

    private String houseType;

    private Integer houseAge;

    private Integer housePrice;

    private Boolean houseCard;

    private Boolean car;

    private Integer carPrice;

    private String column26;

    private String column27;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getLoginPhone() {
        return loginPhone;
    }

    public void setLoginPhone(Integer loginPhone) {
        this.loginPhone = loginPhone;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public Integer getPhone() {
        return phone;
    }

    public void setPhone(Integer phone) {
        this.phone = phone;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession == null ? null : profession.trim();
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSalaryType() {
        return salaryType;
    }

    public void setSalaryType(String salaryType) {
        this.salaryType = salaryType == null ? null : salaryType.trim();
    }

    public String getSalary() {
        return salary;
    }

    public void setSalary(String salary) {
        this.salary = salary == null ? null : salary.trim();
    }

    public String getCompanyType() {
        return companyType;
    }

    public void setCompanyType(String companyType) {
        this.companyType = companyType == null ? null : companyType.trim();
    }

    public Integer getSlow() {
        return slow;
    }

    public void setSlow(Integer slow) {
        this.slow = slow;
    }

    public Integer getWorkTime() {
        return workTime;
    }

    public void setWorkTime(Integer workTime) {
        this.workTime = workTime;
    }

    public String getCreditStatus() {
        return creditStatus;
    }

    public void setCreditStatus(String creditStatus) {
        this.creditStatus = creditStatus == null ? null : creditStatus.trim();
    }

    public String getCommitProtect() {
        return commitProtect;
    }

    public void setCommitProtect(String commitProtect) {
        this.commitProtect = commitProtect == null ? null : commitProtect.trim();
    }

    public String getCommunityTime() {
        return communityTime;
    }

    public void setCommunityTime(String communityTime) {
        this.communityTime = communityTime == null ? null : communityTime.trim();
    }

    public String getGongjijin() {
        return gongjijin;
    }

    public void setGongjijin(String gongjijin) {
        this.gongjijin = gongjijin == null ? null : gongjijin.trim();
    }

    public String getGjjtime() {
        return gjjtime;
    }

    public void setGjjtime(String gjjtime) {
        this.gjjtime = gjjtime == null ? null : gjjtime.trim();
    }

    public String getHouseType() {
        return houseType;
    }

    public void setHouseType(String houseType) {
        this.houseType = houseType == null ? null : houseType.trim();
    }

    public Integer getHouseAge() {
        return houseAge;
    }

    public void setHouseAge(Integer houseAge) {
        this.houseAge = houseAge;
    }

    public Integer getHousePrice() {
        return housePrice;
    }

    public void setHousePrice(Integer housePrice) {
        this.housePrice = housePrice;
    }

    public Boolean getHouseCard() {
        return houseCard;
    }

    public void setHouseCard(Boolean houseCard) {
        this.houseCard = houseCard;
    }

    public Boolean getCar() {
        return car;
    }

    public void setCar(Boolean car) {
        this.car = car;
    }

    public Integer getCarPrice() {
        return carPrice;
    }

    public void setCarPrice(Integer carPrice) {
        this.carPrice = carPrice;
    }

    public String getColumn26() {
        return column26;
    }

    public void setColumn26(String column26) {
        this.column26 = column26 == null ? null : column26.trim();
    }

    public String getColumn27() {
        return column27;
    }

    public void setColumn27(String column27) {
        this.column27 = column27 == null ? null : column27.trim();
    }
}

页面

 <form id="FormContact" method="post" action="/admin/register">
                                <!-- 联系方式 -->
                                <div class="form-wrap contact-info" id="FormWrapContact">
                                    <div class="field-wrap" data-field="mobile" style="position:relative;z-index:100;">
                                        <label class="short">手机号:</label>
                                        <span class="field">
                     					    <span class="ui-text">
                                                            <input name="mobile" value="" type="mobile" placeholder="请输入您的手机号码" data-format="number" />
                     					    </span>
                     					    <span class="error"></span>
                     					</span>
                                    </div>
                                    <div class="field-wrap" data-field="mobile" style="position:relative;z-index:100;">
                                        <label class="short">验证码:</label>
                                        <span class="field">
                                                                 <input class="ui-text short" type="text" name="verify_code" maxlength="4" >
                                                                 <span class="error" style="display: inline;"></span>
                                                             </span>
                                        <span class="field vcode" data-type="vcode">
                                                                 <img  width="120" id="verify_code_img" height="32" src="/getImg" onclick="javascript:changeImg()">
                                                                 <a href="#" class="doc-color-link desc" onclick="javascript:changeImg()" >看不清,换一个?</a>
                                                             </span>
                                    </div>

                                    <div class="field-wrap" data-field="mobile" style="position:relative;z-index:100;">
                                        <label class="short">短信验证码:</label>
                                        <span class="field">
                                                                 <span class="get-mvcode">
                                                                     <input class="ui-text short" type="text" name="sms_vcode" length="6" data-format="number" maxlength="6" />
                                                                     <input id="sendSms" class="ui-btn gray" type="button" name="getMvcode" value="点击获取" />
                                                                 </span>
                                                                                                                                 <div class="error"></div>
                                                                                                                                 <span class="info" style="display:none;">
                                                                 请将收到短信中的6位数字填入框内
                                                                 </span>
                     					</span>
                                    </div>
                                    <div class="field-wrap" style="z-index:8;">
                                        <label class="short"></label>
                                        <span class="field">
                     						<input class="ui-btn green long" name="contactPost" type="button" value="登录" />
                     					</span>
                                        <div style="padding-top: 37.5px;text-align: left;margin-left: 102.6px;">
                                            <span class="info" style="margin-top:5px;margin-left:-3px;"><span class="doc-color-micro"><input style="margin-right: 5px;position:relative;top:-2px;" type="checkbox" checked disabled />同意<a class="doc-color-micro" style="margin-left: 5px;text-decoration: underline;" href="http://www.rong360.com/static/main/protocal/networkUser.html" target="_blank">360服务条款</a></span></span>
                                        </div>
                                    </div>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="wrap-sider">
        </div>
    </div>
</div>

然后写一个注册的 AdminUserController

package com.firstblood.financial.controller;

import com.firstblood.financial.model.User;
import com.firstblood.financial.serive.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.HashMap;
import java.util.Map;


@Controller
public class AdminUserController {
    @Autowired
    private AdminUserService adminUserService;


    /**
     * 登入跳转
     *
     * @param model
     * @return
     */
    @GetMapping("/admin/login")
    public String loginGet(Model model) {
        return "login_yh";
    }


    /**
     * @param mobile
     * @return
     */
    @PostMapping("/admin/register")
    public String register(int mobile) {
        Boolean num =  adminUserService.findUserByAccount(mobile);
        if (num == false) {
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("mobile", "用户名已被注册");
            return "login_jl";
        } else {
            User user = new User();
            user.setLoginPhone(mobile);


            int flag = adminUserService.insertUserByAccount(mobile);

            if (flag == 1) {
                return "hostpage";
            } else {
                return "login_jl";
            }
        }
    }
}

在service 中写sql

package com.firstblood.financial.serive;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AdminUserService {
    @Select("SELECT * FROM `user` where login_phone = #{login_phone};")
    Boolean findUserByAccount(int mobile);

    @Insert("INSERT INTO `user` (`id`, `login_phone`) VALUES (null, #{login_phone};")
    int insertUserByAccount(int mobile);

}

猜你喜欢

转载自blog.csdn.net/qq_30225725/article/details/87278524
今日推荐