SpringBoot實現(xiàn)登錄注冊常見問題解決方案
一、用戶名密碼都正確的情況下被登錄攔截器攔截
控制臺報錯: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.
這個異常是在mapper文件的<select>標簽中沒有指定 resultType 或者 resultMap,也就是說沒有指定返回值類型或者返回值類型的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>標簽中沒有指定 resultType,而是指定的parameterType(參數(shù)類型)
解決:將parameterType修改為resultType
登錄成功:
二、頁面沒有顯示傳遞的消息
這是LoginController的實現(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","密碼錯誤"); return "redirect:/index"; } }else { model.addAttribute("msg","用戶名不存在,請注冊"); return "redirect:/index"; } }
我輸入錯誤的信息,而點擊登錄之后應(yīng)該會反饋給頁面
解決:這其實是一個非常低級的錯誤,因為我設(shè)置了重定向redirect:/index,所以重新定回這個頁面當然就沒有反饋信息了,去掉多余的redirect:/就可以了
三、添加(注冊)成功卻跳轉(zhuǎn)到空白頁
點擊添加,出現(xiàn)空白頁
但是查看自己的數(shù)據(jù)庫發(fā)現(xiàn)注冊是成功的
控制臺報錯: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)出錯原因在于EmpeeMapper文件的insertEmpee方法,而且是返回值類型的錯誤
檢查EmpeeMapper:
我使用的是Empee類型的返回值類型,而我的Controller文件中并沒有寫他的返回值
解決方法:把EmpeeMapper文件的insertEmpee方法修改為void類型
添加成功并且成功跳轉(zhuǎn)
我還在網(wǎng)上看見另一種解決方法,是修改為int類型,經(jīng)過驗證確實可行
由于之后沒有進行其他操作,因此不清楚這樣做會對之后的操作是否有影響,總之還是一步一個腳印的改下去吧
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Spring MVC+mybatis實現(xiàn)注冊登錄功能
- IDEA實現(xiàn) springmvc的簡單注冊登錄功能的示例代碼
- springboot實現(xiàn)注冊加密與登錄解密功能(demo)
- Spring shiro + bootstrap + jquery.validate 實現(xiàn)登錄、注冊功能
- Spring boot+mybatis+thymeleaf 實現(xiàn)登錄注冊增刪改查功能的示例代碼
- springboot+VUE實現(xiàn)登錄注冊
- SpringBoot+Mybatis實現(xiàn)登錄注冊的示例代碼
- Spring MVC登錄注冊以及轉(zhuǎn)換json數(shù)據(jù)
- Android使用OKhttp3實現(xiàn)登錄注冊功能+springboot搭建后端的詳細過程
- 基于Spring5實現(xiàn)登錄注冊功能
相關(guān)文章
Python3中的列表,元組,字典,字符串相關(guān)知識小結(jié)
這篇文章主要介紹了Python3中的列表,元組,字典,字符串相關(guān)知識小結(jié),小編覺得挺不錯的,分享給大家,需要的朋友可以參考下。2017-11-11關(guān)于Python中flask-httpauth庫用法詳解
這篇文章主要介紹了關(guān)于Python中flask-httpauth庫用法詳解,Flask-HTTPAuth是一個?Flask?擴展,它簡化了?HTTP?身份驗證與?Flask?路由的使用,需要的朋友可以參考下2023-04-04pandas的相關(guān)系數(shù)與協(xié)方差實例
今天小編就為大家分享一篇pandas的相關(guān)系數(shù)與協(xié)方差實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12