关于org.mybatis.spring.MyBatisSystemException:Parameter 'userId' not found. 错误调试

 

我一个项目用到了ssm框架。然后数据库生成字段之后,写好实体类


private static final long serialVersionUID = 1826023156097338963L;
	private String userId; //用户ID
	private String id;	//帖子ID
	private String ggTitle; // 公告标题
	private String ggBody; //公告内容
	private String ggIconCls; // 公告样式
	private String createTime; //创建时间
	private String corpName; //部门名称
	private String state; //状态
	private String remark; // 审核备注
	private String typeId; //类型ID
	private String Pthird; //扩展备用
	public Announcement() {
	}
	public Announcement(String userId, String id, String ggTitle,
			String ggBody, String ggIconCls, String createTime,
			String corpName, String state, String remark, String typeId,
			String pthird) {
		super();
		this.userId = userId;
		this.id = id;
		this.ggTitle = ggTitle;
		this.ggBody = ggBody;
		this.ggIconCls = ggIconCls;
		this.createTime = createTime;
		this.corpName = corpName;
		this.state = state;
		this.remark = remark;
		this.typeId = typeId;
		Pthird = pthird;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getGgTitle() {
		return ggTitle;
	}
	public void setGgTitle(String ggTitle) {
		this.ggTitle = ggTitle;
	}
	public String getGgBody() {
		return ggBody;
	}
	public void setGgBody(String ggBody) {
		this.ggBody = ggBody;
	}
	public String getGgIconCls() {
		return ggIconCls;
	}
	public void setGgIconCls(String ggIconCls) {
		this.ggIconCls = ggIconCls;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	public String getCorpName() {
		return corpName;
	}
	public void setCorpName(String corpName) {
		this.corpName = corpName;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getTypeId() {
		return typeId;
	}
	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}
	public String getPthird() {
		return Pthird;
	}
	public void setPthird(String pthird) {
		Pthird = pthird;
	}
	@Override
	public String toString() {
		return "Announcement [userId=" + userId + ", id=" + id + ", ggTitle="
				+ ggTitle + ", ggBody=" + ggBody + ", ggIconCls=" + ggIconCls
				+ ", createTime=" + createTime + ", corpName=" + corpName
				+ ", state=" + state + ", remark=" + remark + ", typeId="
				+ typeId + ", Pthird=" + Pthird + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Announcement other = (Announcement) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
写好mapper 文件映射,写好
<mapper namespace="com.tgb.mapper.information.AnnouncementMapper">
	
	 <!-- mybsits_config中配置的alias类别名,也可直接配置resultType为类路径 -->  
	<insert id="saveTitle" parameterType="Announcement">
		insert into SYS_Information(UserID,ID,Title,CreateTime)values(#{userId},#{id},#{ggTitle},#{createTime});
	
	</insert>
</mapper>
做类型测试一直报错
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/config/spring-common.xml")
public class InformationTest {
	@Autowired
	private AnnouncementMapper announcementMapper;
	@Test
	public void testSave(){
		announcementMapper.saveTitle(CommonUtil.getUUID(),CommonUtil.getUUID(),"今晚打老虎","2016-12-14");
	}
}

 之后钻研书籍,终于才发现原来多数据时候必须要用注解@param

void saveTitle(@Param("userId")String userId,@Param("id")String id,@Param("ggTitle")String ggTitle,@Param("createTime")String createTime);
加入之后错误消失,以此作为笔记。




  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中的异常信息提到了一个MyBatis系统异常,具体错误信息是org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'certno' in 'class java.lang.String'。而引用中的异常信息是org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='name', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.base/java.lang.String cannot be cast to java.base/java.lang.Integer。最后引用中的异常信息是Could not set parameters for mapping: ParameterMapping{property='cardFee', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null。 根据这些异常信息,可以推测引起这个MyBatis系统异常的原因可能是参数类型不匹配。根据引用和引用的内容,可能是某个属性的类型不正确,比如在引用中的'certno'属性应该是一个字符串类型,但是被错误地当作了一个整数类型来处理。类似地,在引用中的'name'属性也出现了类似的问题,被错误地当成了整数类型处理。引用中的异常信息没有提供具体的属性名,但是也可以推测是同样的类型匹配问题。 为了解决这个问题,需要检查MyBatis的配置文件,确保映射的属性类型与数据库中的数据类型一致。另外,还需要检查代码中的参数传递,确保参数类型正确。如果仍然无法解决问题,可以考虑使用不同的JdbcType或尝试其他配置属性来解决问题。 总结起来,这个MyBatis系统异常是由于参数类型不匹配导致的,可以通过检查配置文件和代码中的参数类型来解决。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [解决Mybatis系统异常org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis....](https://blog.csdn.net/qq_35759451/article/details/109575752)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException](https://blog.csdn.net/qq_43593107/article/details/121136995)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [【异常及源码分析】org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis....](https://blog.csdn.net/weixin_30515513/article/details/97497743)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值