weixin_43429839
聆听你的心
2019-09-19 15:23

java.lang.ClassCastException: com.easy.demo.entity.User cannot be cast to java.lang.String

  • java
  • intellij-idea
@RequestMapping(value={"/login"}, method=RequestMethod.GET)
        public boolean login(HttpServletRequest request,
                             @Param(value = "number")String number,
                             @Param(value = "password")String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {

            number = request.getParameter("number");
            password = request.getParameter("password");
            // 获取加密后的密码 password
            password = MD5Util.getEncryptedPwd(password);
            // 获取数据库对应账户密码, findPasswordByAccount 查询数S据库账号的密码
            // userService 业务实现内部调用userDao 去执行select 语句,可以吧
            String encryptPassword = userMapper.findPasswordByNumber(number);
            System.out.println(encryptPassword);
            // 比对数据库中的密码 encryptPassword
            if (password.equals(encryptPassword)) {
                return true;
            } else {
                return false;
            }
        }

下面是有关方法的片段

//userMapper的
      User login(String number,String password);
      String findPasswordByNumber(String number);
//userService
      void login(String number,String password);
      String findPasswordByNumber(String number);
//userServiceImpl
      @Override
    public void login(String number,String password){

        userMapper.login(number,password);
    }
    @Override
    public String findPasswordByNumber(String number){
        String password = userMapper.findPasswordByNumber(number);
        return password;
    }
//userMapper.xml
   <select id="login" resultMap="result">
      SELECT * FROM user where number=#{number} and password=#{password}
    </select>

    <select id="findPasswordByNumber" resultMap="result">
      SELECT password FROM user where number=#{number}
   </select>

如题出现的异常报错要怎么解决?想了半天也没弄懂,求大佬解答一下!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答