ayziba-&& 2024-07-02 09:44 采纳率: 30%
浏览 13

sprinfboot报错解决

2024-07-02 09:40:00.476 ERROR 16436 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.mapper.UserInfoMapper.userLogin] with root cause
soringboot报以上错误怎么解决登录登不上去
下面是主要代码

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <style>
        body {
            background-size: 100%;
        }

        /*#login {*/
        /*    width: 260px; !*最大框的宽度*!*/
        /*    height: 400px;*/
        /*    border-radius: 25px;*/
        /*    left: 40%;*/
        /*    top: 240px;*/
        /*    padding: 0 50px;*/
        /*    position: relative;*/
        /*    text-align: center;*/
        /*    !*background-color: #282c34;   !*整个背景颜色*!*/
        /*    opacity: 0.9;*/
        /*}*/

        .header {
            width: 560px;
            height: 80px;
            /*background: #282c34;*/
            /*border-radius: 15px;*/
            font-size: xxx-large;
            font-family: '华文宋体', sans-serif;
            font-weight: bolder;
            color: black;
            /*align-items: center; !* 垂直居中 *!*/
            margin-left: 40px;
        }

        .loginput {
            width: 100%; /* 使其充满父容器 */
            margin: 30px 0; /* 使用上下边距 */
            display: flex; /* 使用Flex布局 */
            align-items: center; /* 垂直居中 */
            justify-content: space-between; /* 水平两端对齐 */
        }

        .loginput1 {
            width: 200px; /*字与输入框之间的距离*/
            height: 80px;
            margin-top: -10px;

        }

        .log_left {
            width: 20%;   /*文字和框之间的距离*/
            text-align: center; /* 文本右对齐 */
            margin-right: 25px; /* 添加右边距 */
            margin-left: 55px;
        }

        .log_right {
            width: 100%;
            text-align: left; /* 文本左对齐 */
        }

        .text_style {
            font-size: x-large;
            font-family: '华文仿宋', sans-serif; /* 确保字体名称正确 */
            line-height: normal; /* 使用正常行高 */
            font-weight: bolder;
            color: black; /* 使用color代替flood-color */
            margin: 0px; /* 移除不必要的边距 */
        }

        span {
            margin-left: -75px;
        }

        input {
            width: 50px;
            height: 25px;
            position: relative;
            outline: none;
            border: none;
            box-sizing: border-box;
            padding-left: 5px;
            background-color: white; /*方框的背景色*/
            color: black;
            caret-color: black;
        }

        .input_box {
            width: 310px;
            height: 50px;
            font-size: 20px;
            margin-top: 0; /* 移除顶部边距 */
            border: 2px solid #ccc; /* 添加边框 */
            border-radius: 20px;
            padding: 10px; /* 添加内边距 */
            box-sizing: border-box; /* 包含边框和内边距在宽度内 */
        }

        .bottom_button {
            width: 50px;
            height: 35px;
            margin: 10px 0px 0px 210px;
            font-weight: bolder;
            font-family: Verdana;
            border-radius: 10px;
        }
        .bottom_button1 {
            width: 50px;
            height: 35px;
            margin: 10px 240px 0px 0px;
            font-weight: bolder;
            font-family: Verdana;
            border-radius: 10px;
        }
        .btn {
            width: 80px;
            height: 45px;
            margin: 80px 0px 0px 220px;
            /*margin-left: 180px;*/
            /*margin-bottom: 20px;*/
            font-size: x-large;
            font-weight: bolder;
            /*font-family: Verdana;*/
            border-radius: 15px;
            color: black;
            background-color: #FFF;
            align-items: center; /* 垂直居中 */
        }

        .container {
            height: 30px;
            width: 250px;
            text-align: center;
            position: absolute;
            left: 49%;
            top: 55%;
            transform: translate(-50%, -50%);
        }
        #login_block {
            width: 560px;
            margin: 215px auto 0px auto;
            /*background: #282c34;*/
            text-align: center;
            border-radius: 15px;
            /*opacity: 0.6;*/  /*透明度*/
        }
        .header_text {
            align-items: center; /* 垂直居中 */
            text-align: center;
            line-height: 80px;
            font-size: xxx-large;
            font-family: '华文宋体', sans-serif;
            font-weight: bolder;
            color: black;
            /*margin: 30px auto 20px 30px;*/
        }
        .checked_text {
            text-align: center;
            margin: -180px 150px 180px 0px;  /*上右下左*/
        }
        .job {
            width: 40px;
            height: 20px;
            font-family: Verdana;
            font-weight: bolder;
            font-size: x-large;
            flood-color: white;
            /*margin-left: 10px;*/
            margin: -160px 10px 0px 5px;
        }
        /* 复选框容器样式 */
        .checkbox-container {
            display: flex; /* 使复选框和标签在同一行显示 */
            align-items: center; /* 垂直居中 */
            justify-content: space-between; /* 水平间距平均分布 */
            padding: 100px; /* 添加一些内边距 */
            margin-top: 20px;
            /*margin-left: 50px;*/
            /*margin-right: 20px;*/
        }
        .check_text {
            text-align: center;
            margin: -160px 15px 0px 5px;  /*上右下左*/
        }
        .bottom_text{
            height: 30px;
            width: 250px;
            text-align: center;
            position: absolute;
            left: 49%;
            top: 85%;
            transform: translate(-50%, -50%);
        }

    </style>
</head>
<body background="..\static\img\register.jpg">
<div id="login_block">
        <div class="header">
            <span class="header_text" th:text="#{login.tip}"> 用户登录</span>
        </div>
        <form action="/gologin" method="post">

        <div class="loginput">
            <div class="log_left">
                <span class="text_style" th:text="#{login.username}">用户名</span>
            </div>
            <div class="log_right">
                <input class="input_box" type="text" name="name" id="name1">
            </div>
        </div>

        <div class="loginput">
            <div class="log_left">
                <span class="text_style" th:text="#{login.password}">&nbsp;&nbsp;</span>
            </div>
            <div class="log_right">
                <input class="input_box" type="password" name="password" id="pwd1">
            </div>
        </div>
        <div class="loginput">
            <button type="submit" class="btn" value="登录" th:text="#{login.button}"></button>
        </div>
<!--            <div class="container">-->
<!--                <p th:text="#{login.ts}">没有账号?<a href="register" th:text="#{login.register}">请注册</a></p>-->
<!--            </div>-->
    </form>

<!--        <div class="loginput" style="text-align: center;font-size: x-large;font-weight: bolder;margin: 40px 10px 0px auto">-->
<!--            <span th:text="${currentYear}">2019</span>-<span th:text="${currentYear}+1">2020</span>-->
<!--            <span th:text="${#locale.country}">中国</span>-->
<!--            <span>CopyRight</span>-->
<!--            <span th:text="${author}">ayziba</span>-->
<!--        </div>-->
    <div class="loginput" style="text-align: center;margin: 0;">
        <a class="bottom_button" th:href="@{/login(l='zh_CN')}">中文</a>
        <a class="bottom_button1" th:href="@{/login(l='en_US')}">English</a>
    </div>
<!--    <div class="container">-->
<!--        <p th:text="#{login.ts}">没有账号?<a href="register" th:text="#{login.register}">请注册</a></p>-->
<!--    </div>-->
</div>
</body>
</html>

package com.example.controller;

import com.example.model.UserInfo;
import com.example.model.UserInformation;
import com.example.service.UserInfoService;
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 org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Calendar;

@Controller
public class LoginController {
    @Autowired
    UserInfoService userInfoService;

    public Model getCopyRight(Model model) {
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        model.addAttribute("author", "阿依则巴");
        return model;
    }

    @GetMapping("/index")
    public String index(Model model) {
        getCopyRight(model);
        return "index";
    }
    @GetMapping("/error")
    public String error() {
        return "error";
    }
    //@RequestParam:根据表单中的name 属性值获取form表单中的用户输入数据

    @PostMapping("/gologin")
    public String gologin(@RequestParam("name") String username, @RequestParam("password") String password, Model model, HttpSession session) {
        getCopyRight(model);
//        if(username.equals("ziba") && userpass.equals("123"))
//        {
//            session.setAttribute("currentUser",username);
//            return "index";
//        }
//        else
//        {
//            return "error";
//        }
        System.out.println("username:" + username + "\npassword:" + password);
        getCopyRight(model);
        if (userInfoService.user_login_Service(username, password) != null) {
            System.out.println(userInfoService.user_login_Service(username, password));
            session.setAttribute("currentUser", username);
            return "index";
        } else {
            //return username+ "登录失败“
            return "login_fail";
        }
    }
    @ResponseBody  //后台的数据传入到前端
    @PostMapping("/goregister")      //RequestParam接受数据
    public int goregister(UserInformation user, @RequestParam("username") String username, @RequestParam("password") String password,
                          @RequestParam("sex") String sex,@RequestParam("height") String height,@RequestParam("weight") String weight,
                          @RequestParam("age") String age,@RequestParam("phone") String phone,@RequestParam("id_number") String id_number) {
        //控制台上打印数据
        System.out.println("username:" + username + "\n password:" + password + "\n sex:" + sex);
//        return "username: "+username+"\n"+"password: "+password+"\n"+"sex: "+sex+"\n"+"province: "+province+"\n"+"hobby: "+hobby;
        if (userInfoService.find_userinfo_by_name_Service(username).isEmpty()) {
            user.setUsername(username);
            user.setPassword(password);
            user.setSex(sex);
            user.setHeight(height);
            user.setWeight(weight);
            user.setAge(age);
            user.setPhone(phone);
            user.setId_number(id_number);
            userInfoService.user_register_Service(user);
            return 1;
        } else {
            System.out.println("该用户已存在!");
            return 0;
        }
    }


}



package com.example.controller;

import com.example.model.UserInformation;
import com.example.service.UserInfoService;
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.PathVariable;


import java.util.Calendar;
import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserInfoService userInfoService;
    public Model getCopyRight(Model model) {
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        model.addAttribute("author", "阿依则巴");
        return model;
    }
    @GetMapping("/login")
    public String login(Model model) {
        getCopyRight(model);
        return "login";
    }
    @GetMapping("/register")
    public String register(Model model) {
        getCopyRight(model);
        return "register";
    }
    @GetMapping("/publicPage")
    public String publicpage(Model model) {
        getCopyRight(model);
        return "publicPage";
    }
    @GetMapping("/users")
    public String editUserInfo(Model model) {
        List<UserInformation> userInfoList = userInfoService.findUserInfoList_Service();
        model.addAttribute("Result", userInfoList);
        getCopyRight(model);
        return "users";
    }
    @GetMapping("/deleteuserinfo/{id}")
    public String deleteUserInfo(@PathVariable int id, Model model) {
        userInfoService.delete_user_by_id_Service(id);
        getCopyRight(model);
        return "redirect:/edit_user";
        /* redirect是会先跳转到后面写的controller,然后继续找到这个controller对应的RequestMapping的参数,随后再去跳转页面。*/
    }
    @GetMapping("/updateuserinfo/{id}")
    public String updateUserInfo(@PathVariable int id, Model model) {
        UserInformation user = userInfoService.find_userinfo_by_Id_Service(id);
        System.out.println("###########" + user.toString());
        model.addAttribute("user", user);
        getCopyRight(model);
        return "update_user";
    }

}

package com.example.mapper;


import com.example.model.UserInformation;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

@Mapper          //表示该类是一个MyBatis
//
public interface UserInfoMapper {
    List<UserInformation> findUserInfoList();

    UserInformation userLogin(String username, String password);

    List<UserInformation> findUserInfoByName(String username);

    int userInfoRegister(UserInformation user);

    int deleteUserInfoById(int id);

    UserInformation findUserInfoById(int id);

    int updateUserInfoById(UserInformation user);


}



package com.example.service;

import com.example.model.UserInfo;
import com.example.model.UserInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.mapper.UserInfoMapper;

import javax.transaction.Transactional;
import java.util.List;

//service是对mapper的封装
//@Service 注解是一种用于表经济服务层 Bean 的注解,将一个类声明为业务逻辑组件,并将其对象存入Spring容器中
@Service
@Transactional
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired     //=new
    private UserInfoMapper userInfoMapper;

    @Override    //重写方法
    public List<UserInformation> findUserInfoList_Service() {
        return userInfoMapper.findUserInfoList();
    }

    @Override
    public UserInformation user_login_Service(String username, String password) {
        return userInfoMapper.userLogin(username, password);
    }

    @Override
    public List<UserInformation> find_userinfo_by_name_Service(String username) {
        return userInfoMapper.findUserInfoByName(username);
    }

    @Override
    public int user_register_Service(UserInformation user) {
        return userInfoMapper.userInfoRegister(user);
    }

    @Override
    public int delete_user_by_id_Service(int id) {
        return userInfoMapper.deleteUserInfoById(id);
    }

    @Override
    public UserInformation find_userinfo_by_Id_Service(int id) {
        return userInfoMapper.findUserInfoById(id);
    }

    @Override
    public int update_user_by_id_Service(UserInformation user) {
//        System.out.println("1:" + user.toString());
        return userInfoMapper.updateUserInfoById(user);
    }
}


<?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.example.mapper.UserInfoMapper">
    <select id="findUserInfoList" resultType="com.example.model.UserInformation">
        select * from usertable
    </select>

    <select id="userLogin" resultType="UserInformation">
        select * from usertable where username = #{username} and password = #{password}
    </select>

    <select id="findUserInfoByName" resultType="UserInformation">
        select * from usertable where username = #{username}
    </select>

    <insert id="userInfoRegister" parameterType="UserInformation" useGeneratedKeys="true" keyProperty="id">
        insert into usertable(username,password,sex,height,weight,age,phone,id_number) values(#{username}, #{password},#{sex},
                                                                             #{height},#{weight},#{age},#{phone},#{id_number})
    </insert>

    <delete id="deleteUserInfoById" parameterType="UserInformation">
        delete from usertable where id = #{id}
    </delete>

    <select id="findUserInfoById" resultType="UserInformation">
        select * from usertable where id = #{id}
    </select>

    <update id="updateUserInfoById" parameterType="UserInformation">
        update usertable
        set username = #{username},
            password = #{password},
            sex = #{sex},
            height = #{height},
            weight = #{weight},
            age = #{age},
            phone = #{phone},
            id_number = #{id_number}
        where id = #{id}
    </update>


package com.example.model;

public class UserInformation {
    private Integer id;
    private String username;
    private String password;
    private String sex;
    private String height;
    private String weight;
    private String age;
    private String phone;
    private String id_number;

    public Integer getId() {
        return id;
    }

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

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getAge() {
        return age;
    }

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

    public String getPhone() {
        return phone;
    }

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

    public String getId_number() {
        return id_number;
    }

    public void setId_number(String id_number) {
        this.id_number = id_number;
    }

    @Override
    public String toString() {
        return "UserInformation{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", sex='" + sex + '\'' +
                ", height='" + height + '\'' +
                ", weight='" + weight + '\'' +
                ", age='" + age + '\'' +
                ", phone='" + phone + '\'' +
                ", id_number='" + id_number + '\'' +
                '}';
    }
}


  • 写回答

4条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-07-02 09:44
    关注

    引自免费微信小程序:皆我百晓生

    根据错误信息 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.mapper.UserInfoMapper.userLogin,这个问题是由于MyBatis没有找到你指定的userLogin映射语句。这个问题通常由以下几个原因引起:

    1. Mapper文件的位置:确保你的UserInfoMapper.xml文件在正确的位置,通常应该放在resources目录下,并且这个目录要被Spring扫描到。如果文件位置不正确,Spring无法加载到MyBatis的映射文件。
    2. 命名空间检查:在UserInfoMapper.xml中,<mapper>标签的namespace属性应该和你的接口com.example.mapper.UserInfoMapper完全一致。包括大小写和拼写。
    3. 映射语句的ID:在UserInfoMapper.xml中定义的<select><insert><update><delete>等标签的id属性,需要和你在接口(例如UserInfoMapper)中的方法名完全匹配。在你的错误信息中,MyBatis没有找到userLogin这个映射语句。确保你在接口中有对应的方法定义,并且在映射文件中的id也是正确的。
    4. 项目构建问题:如果你使用的是Maven或Gradle等构建工具,确保你的项目已经被正确构建,并且所有的资源文件(包括MyBatis的映射文件)都被正确地打包到了你的应用当中。

    检查以上几点,应该可以解决你的问题。如果问题依然存在,你可能需要提供更多的信息,比如你的项目结构、构建配置等,以便进一步分析问题原因。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 7月2日

悬赏问题

  • ¥15 校内二手商品转让网站
  • ¥20 高德地图聚合图层MarkerCluster聚合多个点,但是ClusterData只有其中部分数据,原因应该是有经纬度重合的地方点,现在我想让ClusterData显示所有点的信息,如何实现?
  • ¥100 求Web版SPC控制图程序包调式
  • ¥20 指导如何跑通以下两个Github代码
  • ¥15 大家知道这个后备文件怎么删吗,为啥这些文件我只看到一份,没有后备呀
  • ¥15 C++为什么这个代码没报错运行不出来啊
  • ¥15 一道ban了很多东西的pyjail题
  • ¥15 关于#r语言#的问题:如何将生成的四幅图排在一起,且对变量的赋值进行更改,让组合的图漂亮、美观@(相关搜索:森林图)
  • ¥15 C++识别堆叠物体异常
  • ¥15 微软硬件驱动认证账号申请