springboot mybatis使用注解形式报错Could not set parameters for mapping: ParameterMapping{property='xxx'

本文介绍了在使用MyBatis框架时遇到的关于参数设置的问题,特别是当传入null值时引发的异常,并提供了解决方案,包括如何正确地使用jdbcType属性以及@Param注解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果你使用的是xml文件配置mapper,并且传入了null值,则也会引发这个错误:

Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='dictionaryFilename', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: 无效的列索引

解决方法:根据网上资料说,是加上jdbcType,如

#{dictionaryFilename,jdbcType = VARCHAR}

但是注解形式不是这个问题,因为#起的是一个占位符作用,而在java中字符串中$才能起到占位符作用,所以我们要将#变为$。

变为

这样解决了。

另外如果你要传入多个参数的时候,要么使用map传入,要么加上@Param注解

参考博客:https://blog.youkuaiyun.com/csdn_am/article/details/79854107

public String login(String username, String password, String code, String uuid) { // 验证码校验 // validateCaptcha(username, code, uuid); // 登录前置校验 loginPreCheck(username, password); // 用户验证 Authentication authentication = null; try { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); AuthenticationContextHolder.setContext(authenticationToken); // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername authentication = authenticationManager.authenticate(authenticationToken); } catch (Exception e) { if (e instanceof BadCredentialsException) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } else { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); throw new ServiceException(e.getMessage()); } } finally { AuthenticationContextHolder.clearContext(); } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); recordLoginInfo(loginUser.getUserId()); // 生成token return tokenService.createToken(loginUser); }在ruoyi-vue中属性e的值为org.springframework.security.authentication.InternalAuthenticationServiceException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Long, jdbcType=null, numericScale=null, resultMapId='null', jdbcTy
03-21
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值