Mapper method com.xxxxx has an unsupported return type: class com.xxx

写了半天报了这个错误,Mapper method com.xxxxx has an unsupported return type: class com.xxx
具体的:
org.apache.ibatis.binding.BindingException: Mapper method ‘com.cxj.dao.NewDao.dynamicTrimTest1’ has an unsupported return type: class com.cxj.pojo.NewsEntity
at org.apache.ibatis.binding.MapperMethod.rowCountResult(MapperMethod.java:109)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy5.dynamicTrimTest1(Unknown Source)
at com.cxj.test.TestSQL.testtrim2(TestSQL.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
原因是类型不配,用的是update SQL语句,他的返回值只能是int类型,不能是其他的,检查dao层语句是否为int,再看xml文件的parameterTYpe是否为integer,然后是测试语句的调用处为int。
详细代码:
dao层:

public **int** dynamicTrimTest1(NewsEntity newsEntity );

xml文件在这里插入代码片

<update id="dynamicTrimTest1" parameterType="**Integer**">
		update tb_news
		<trim prefix="set" suffixOverrides="," suffix =" where id = #{Id} ">
		    <if test="title!=null and title.length()>0">
		        title=#{title}, 
		    </if>
		    <if test="author!= null and atuhor.length()>0">
		        author=#{author}, 
		    </if>
		</trim>
</update>

test语句:

@Test
	public void testtrim2() {
		SqlSession session=MyBatisUtils.getSession();
		NewDao newDao=session.getMapper(NewDao.class);
		NewsEntity newsEntity =new NewsEntity();
		newsEntity.setTitle("very帅");
		newsEntity.setId(2);
		**int** list=newDao.dynamicTrimTest1(newsEntity);;
		System.out.println("更新成功"+list+"条");
		//打开事务
		session.commit();
		//关闭事务
		session.close();
	}

java类:

public class NewsEntity {
	private Integer Id;

	private String author;//作者

	private String content;//内容

	private String title;//标题

	private String owner;//所有权

	public Integer getId() {
		return Id;
	}

	public void setId(Integer id) {
		Id = id;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	@Override
	public String toString() {
		return "NewsEntity [Id=" + Id + ", author=" + author + ", content=" + content + ", title=" + title + ", owner="
				+ owner + "]";
	}
}

希望以上的经验可以帮助大家。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.apache.ibatis.binding.BindingException是MyBatis框架中的一个异常类,用于表示绑定错误的异常情况。在你提供的异常信息中,出现了"Invalid bound statement (not found)"的错误,表示找不到有效的绑定语句。 在MyBatis中,绑定语句是指将SQL语句与Mapper接口中的方法进行绑定,以便在执行数据库操作时使用。绑定语句通常定义在Mapper XML文件中或者使用注解方式进行定义。 出现"Invalid bound statement (not found)"错误的原因可能有以下几种: 1. 绑定语句的ID错误:可能是由于绑定语句的ID在Mapper XML文件中不存在或者注解方式定义的方法名与绑定语句ID不匹配导致的。 2. Mapper接口未正确绑定:可能是由于Mapper接口未正确与Mapper XML文件进行绑定或者未使用@Mapper注解进行标识导致的。 3. Mapper XML文件未正确配置:可能是由于Mapper XML文件中未正确配置绑定语句或者未正确引入Mapper接口导致的。 为了解决这个问题,你可以检查以下几个方面: 1. 检查绑定语句的ID是否正确,并确保在Mapper XML文件中存在对应的绑定语句。 2. 检查Mapper接口是否正确与Mapper XML文件进行绑定,可以使用@Mapper注解或者在配置文件中进行配置。 3. 检查Mapper XML文件中是否正确配置了绑定语句,并且引入了正确的Mapper接口。 如果以上检查都没有问题,还可以尝试重新编译和部署项目,确保所有的配置和代码都正确。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值