SpringBoot實(shí)現(xiàn)登錄注冊(cè)常見問題解決方案
一、用戶名密碼都正確的情況下被登錄攔截器攔截

控制臺(tái)報(bào)錯(cuò):org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.spbt.mapper.EmpeeMapper.selectName'. It's likely that neither a Result Type nor a Result Map was specified.
這個(gè)異常是在mapper文件的<select>標(biāo)簽中沒有指定 resultType 或者 resultMap,也就是說(shuō)沒有指定返回值類型或者返回值類型的map集合
所以檢查自己的mapper文件:
<?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.spbt.mapper.EmpeeMapper">
<select id="selectName" parameterType="String">
select username from empee where username=#{username}
</select>
<select id="selectPwdByName" parameterType="String">
select password from empee where username=#{username}
</select>
</mapper>
可以發(fā)現(xiàn)我的<select>標(biāo)簽中沒有指定 resultType,而是指定的parameterType(參數(shù)類型)
解決:將parameterType修改為resultType
登錄成功:

二、頁(yè)面沒有顯示傳遞的消息

這是LoginController的實(shí)現(xiàn)登錄代碼
RequestMapping("/empee/login")
public String login(@RequestParam("username") String username,
@RequestParam("password") String password,
Model model, HttpSession session){
if (empeeMapper.selectName(username)!=null){
//用戶名存在
if (empeeMapper.selectPwdByName(username).equals(password)){
//密碼也正確
session.setAttribute("loginEmpee",username);
return "redirect:/main.html";
}else {
model.addAttribute("msg","密碼錯(cuò)誤");
return "redirect:/index";
}
}else {
model.addAttribute("msg","用戶名不存在,請(qǐng)注冊(cè)");
return "redirect:/index";
}
}
我輸入錯(cuò)誤的信息,而點(diǎn)擊登錄之后應(yīng)該會(huì)反饋給頁(yè)面
解決:這其實(shí)是一個(gè)非常低級(jí)的錯(cuò)誤,因?yàn)槲以O(shè)置了重定向redirect:/index,所以重新定回這個(gè)頁(yè)面當(dāng)然就沒有反饋信息了,去掉多余的redirect:/就可以了
三、添加(注冊(cè))成功卻跳轉(zhuǎn)到空白頁(yè)

點(diǎn)擊添加,出現(xiàn)空白頁(yè)

但是查看自己的數(shù)據(jù)庫(kù)發(fā)現(xiàn)注冊(cè)是成功的

控制臺(tái)報(bào)錯(cuò):org.apache.ibatis.binding.BindingException: Mapper method 'com.spbt.mapper.EmpeeMapper.insertEmpee' has an unsupported return type: class com.spbt.pojo.Empee
可以發(fā)現(xiàn)出錯(cuò)原因在于EmpeeMapper文件的insertEmpee方法,而且是返回值類型的錯(cuò)誤
檢查EmpeeMapper:

我使用的是Empee類型的返回值類型,而我的Controller文件中并沒有寫他的返回值

解決方法:把EmpeeMapper文件的insertEmpee方法修改為void類型

添加成功并且成功跳轉(zhuǎn)

我還在網(wǎng)上看見另一種解決方法,是修改為int類型,經(jīng)過(guò)驗(yàn)證確實(shí)可行
由于之后沒有進(jìn)行其他操作,因此不清楚這樣做會(huì)對(duì)之后的操作是否有影響,總之還是一步一個(gè)腳印的改下去吧
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Spring MVC+mybatis實(shí)現(xiàn)注冊(cè)登錄功能
- IDEA實(shí)現(xiàn) springmvc的簡(jiǎn)單注冊(cè)登錄功能的示例代碼
- springboot實(shí)現(xiàn)注冊(cè)加密與登錄解密功能(demo)
- Spring shiro + bootstrap + jquery.validate 實(shí)現(xiàn)登錄、注冊(cè)功能
- Spring boot+mybatis+thymeleaf 實(shí)現(xiàn)登錄注冊(cè)增刪改查功能的示例代碼
- springboot+VUE實(shí)現(xiàn)登錄注冊(cè)
- SpringBoot+Mybatis實(shí)現(xiàn)登錄注冊(cè)的示例代碼
- Spring MVC登錄注冊(cè)以及轉(zhuǎn)換json數(shù)據(jù)
- Android使用OKhttp3實(shí)現(xiàn)登錄注冊(cè)功能+springboot搭建后端的詳細(xì)過(guò)程
- 基于Spring5實(shí)現(xiàn)登錄注冊(cè)功能
相關(guān)文章
Python3中的列表,元組,字典,字符串相關(guān)知識(shí)小結(jié)
這篇文章主要介紹了Python3中的列表,元組,字典,字符串相關(guān)知識(shí)小結(jié),小編覺得挺不錯(cuò)的,分享給大家,需要的朋友可以參考下。2017-11-11
詳解Python在七牛云平臺(tái)的應(yīng)用(一)
這篇文章主要介紹了詳解Python在七牛云平臺(tái)的應(yīng)用(一),涉及Python通過(guò)官方庫(kù)對(duì)空間的操作,上傳的步驟,操作方法等相關(guān)內(nèi)容,以及完整的操作代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12
Python實(shí)現(xiàn)的計(jì)算器功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)的計(jì)算器功能,涉及Python四則運(yùn)算、取反、百分比等相關(guān)數(shù)學(xué)運(yùn)算操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-04-04
關(guān)于Python中flask-httpauth庫(kù)用法詳解
這篇文章主要介紹了關(guān)于Python中flask-httpauth庫(kù)用法詳解,Flask-HTTPAuth是一個(gè)?Flask?擴(kuò)展,它簡(jiǎn)化了?HTTP?身份驗(yàn)證與?Flask?路由的使用,需要的朋友可以參考下2023-04-04
python 進(jìn)程的幾種創(chuàng)建方式詳解
這篇文章主要介紹了python 進(jìn)程的幾種創(chuàng)建方式詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟
這篇文章主要介紹了python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-03-03
pandas的相關(guān)系數(shù)與協(xié)方差實(shí)例
今天小編就為大家分享一篇pandas的相關(guān)系數(shù)與協(xié)方差實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12

