springboot整合mybatis出现问题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42424720/article/details/84095908

1.调用以下sql时报错:There is no getter for property named ‘*’ in ‘class java.lang.String’
以上图片为改正后,原错误为
<if test="orgCode != null">
orgCode为传进来的参数名称,发生错误原因见收藏

2.一个insert标签执行多条insert语句

allowMultiQueries=true

在配置文件datasource下面的url后面加上该条属性,作用是允许一次执行多条更新

3.insert标签返回生成的主键
1)
<insert id="insert" parameterType="Activity" keyProperty="id" keyColumn="ID" useGeneratedKeys="true">
通过这种方法生成的主键,需要在方法中通过插入对象的get方法来获取
mapper方法指挥返回影响的行数
2)

<insert id="insertSelective" parameterType="xxxx" >
    <selectKey resultType="java.lang.Integer" keyProperty="ID" order="AFTER" >
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into XXXX

这种方法的返回值会直接返回主键,暂时没有试过//todo

展开阅读全文

整合spring和mybatis出现问题

05-26

整合之后,用junit测试报错rn[code=text]org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': rnInjection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: rnCould not autowire field: private com.thfund.dao.UserMapper com.thfund.service.impl.UserServiceImpl.userMapper; rnnested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type rn[com.thfund.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.rnDependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rnRelated cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\workspace\trunk\myweb\build\classes\com\thfund\dao\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirectorrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)rn at com.thfund.service.impl.UserServiceImplTest.tearDownAfterClass(UserServiceImplTest.java:21)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)rn at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)rn at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:309)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)[/code]rn求大侠指教 论坛

springboot整合mybatis 启动报错

08-07

[code=text]rnjava.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()rn at java.lang.reflect.Method.getDefaultValue(Method.java:612) ~[na:1.8.0_131]rn at sun.reflect.annotation.AnnotationType.(AnnotationType.java:132) ~[na:1.8.0_131]rn at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85) ~[na:1.8.0_131]rn at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:266) ~[na:1.8.0_131]rn at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_131]rn at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_131]rn at java.lang.Class.createAnnotationData(Class.java:3521) ~[na:1.8.0_131]rn at java.lang.Class.annotationData(Class.java:3510) ~[na:1.8.0_131]rn at java.lang.Class.getAnnotations(Class.java:3446) ~[na:1.8.0_131]rn at org.springframework.core.type.StandardAnnotationMetadata.(StandardAnnotationMetadata.java:70) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]rn at org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition.(AnnotatedGenericBeanDefinition.java:58) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]rn at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.doRegisterBean(AnnotatedBeanDefinitionReader.java:216) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]rn at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:145) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]rn at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:135) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]rn at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:158) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:135) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:127) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.SpringApplication.load(SpringApplication.java:704) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:393) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.SpringApplication.run(SpringApplication.java:328) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]rn at com.example.TestDemoApplication.main(TestDemoApplication.java:12) [classes/:na]rn[/code]rnspringboot版本 2.0.4.RELEASE mybatis版本 3.4.6 mybatis-spring版本 1.3.2 论坛

没有更多推荐了,返回首页