mapper

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.gong.mybatis.dao.EmployeeMapper.getEmpById

核能气质少年 提交于 2020-01-18 16:36:45
在mybatis全局配置文件中利用mappers中的mapper中的class属性配置sqll映射文件时出现该问题:以EmployeeMapper.java和EmployeeMapper.xml为例 在使用class配置sql映射文件时: 需注意三点: 1、EmployeeMapper.java和EmployeeMapper.xml需在同一个包下,且类名和xml文件名要相同; 2、在Mybatis全局配置文件中注册映射文件时要正确: <mappers> <mapper class="com.gong.mybatis.dao.EmployeeMapper" /> </mappers> 3、在EnployeeMapper.xml中: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.gong.mybatis.dao.EmployeeMapper"> <select id="getEmpById" resultType="com.gong.mybatis.bean.Employee"> select

MybatisPlus中调用Oracle存储过程

安稳与你 提交于 2020-01-18 03:25:24
起因 由于需要将新数据同步到另外的数据库,所以需要使用 dblink 进行操作,但是 dblink不支持写入操作 ,因此需要调用写好的存储过程才能实现将新数据插入新数据的同时插入旧数据库。 准备工作 预先准备好新旧两个数据库 旧的数据库 create table OLD_USER ( USER_ID NUMBER ( 6 ) not null primary key , LOGIN_NAME VARCHAR2 ( 100 ) not null , REAL_NAME VARCHAR2 ( 300 ) , PASSWORD CHAR ( 64 ) ) 新的数据库 create table NEW_USER ( ID NUMBER(11) not null primary key, CREATE_TIME TIMESTAMP(6), UPDATE_TIME TIMESTAMP(6), DELETED NUMBER(1), ACCOUNT VARCHAR2(255), USERNAME VARCHAR2(255), PASSWORD VARCHAR2(255) ) 对应的实体为: package com . donlex . demo . entity ; import com . baomidou . mybatisplus . annotation . FieldFill ;

.NetCore学习笔记:四、AutoMapper对象映射

拟墨画扇 提交于 2020-01-17 15:23:17
什么是AutoMapper? AutoMapper是一个简单的小型库,用于解决一个看似复杂的问题 - 摆脱将一个对象映射到另一个对象的代码。这种类型的代码是相当沉闷和无聊的写,所以为什么不发明一个工具来为我们做? 我们来看看在.netcore3.1中怎样使用AutoMapper9.0。 1 public class BasicProfile : Profile, IProfile 2 { 3 public BasicProfile() 4 { 5 CreateMap<TestDto, Test>(); 6 CreateMap<Test, TestDto>(); 7 } 8 } Profile提供了一个命名的映射类,所有继承自Profile类的子类都是一个映射集合。这里我创建了一个BasicProfile继承Profile类。 CreateMap创建映射规则。 IProfile创建影射类的约束,表示继承自该接口的类为映射集合。 由于AutoMapper9.0中取消了自动创建影射规则的方法这里我们需要自己写一个: 1 public static class ServiceCollectionExtensions 2 { 3 /// <summary> 4 /// 自动创建映射 5 /// </summary> 6 /// <param name="services"></param>

手写mybatis框架笔记

落花浮王杯 提交于 2020-01-17 12:34:32
MyBatis 手写MyBatis流程 架构流程图 封装数据 封装到Configuration中 1、封装全局配置文件,包含数据库连接信息和mappers信息 2、封装*mapper.xml映射文件 封装操作:Builder类 Builder类用来操作配置文件(全局配置文件和mapper映射文件),将配置数据封装到类中。 XmlConfigBuilder 提供parse方法将dataSource信息封装到Configuration XmlMapperBuilder 提供parse方法将mapper.xml信息封装到Configuration XmlStatementBuilder 提供parse方法封装MappedStatement信息 (此处应用了创建者模式) XmlScriptBuilder 提供parse方法封装SqlNode信息 数据封装类: Configuration 封装DataSource和MappedStatement 注意:在Configuration中还提供了创建四大组件的功能!!! DataSource 封装了连接数据库所需的四大属性:数据库驱动、url、username、passwrod MappedStatement 每一个CRUD标签都对应一个MappedStatement,其中包含了标签类型(StatementType)、参数类型

【Mybatis Plus基础使用】Mapper.java传递多个参数

与世无争的帅哥 提交于 2020-01-17 09:47:07
根据实际情况总结了以下几种多参数传递的方法: 顺序传参法。不推荐使用,参数顺序易出错 Java Bean传参 Map传参 @Param 注解传参 顺序传参法 根据Mapper.java中参数的顺序进行相应的调用 Mapper.java List<PlatformUser> selectUserPage(String creator, String userId); Mapper.xml <select id="selectUserPage" resultType="com.act.platform.entity.PlatformUser"> select * from platform_user a where a.creator = #{0} and a.user_id = #{1} </select> Java Bean传参 可在Mapper.xml中通过#{}直接调用Java Bean中属性进行参数传递 Mapper.java List<PlatformUser> selectUserPage(PlatformUser user); Mapper.xml <select id="selectUserPage" resultType="com.act.platform.entity.PlatformUser" parameterType="com.act.platform

Cannot find class [org.mybatis.spring.mapper.MapperFactoryScannerConfigurer]

谁都会走 提交于 2020-01-17 05:59:24
出现如下错误: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.mybatis.spring.mapper.MapperScannerConfigurer] for bean with name ‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’ defined in class path resource [applicationContext-mybatis.xml]; nested exception is java.lang.ClassNotFoundException: org.mybatis.spring.mapper.MapperScannerConfigurer 网上的解答一般都是: mybatis-spring1.x.x-jar中不存在org.mybatis.spring.mapper.MapperScannerConfigurer这个类,需要重新下载jar包(如果你真的没有的话,可以重新下载) 然而如果你跟我一样,这些jar包都有了,还报错,那你可能遇到了和我一样的问题,就是你mapper包中某个mapper java文件中没有添加namespace,所以扫描包不知道扫描哪一个

【笔记】框架之MyBatis

为君一笑 提交于 2020-01-17 00:10:30
简介: MyBatis是一个优秀的持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动、创建connection、创建statement、手动设置参数、结果集检索等jdbc繁杂的过程代码。 Mybatis对JDBC访问数据库的过程进行了封装,简化了JDBC代码,解决JDBC将结果集封装为Java对象的麻烦。 PS:由于<>会 被编辑器识别为标签,所以本文用()代替<> 使用: 1.导入依赖 (dependency) (groupId)org.mybatis(/groupId) (artifactId)mybatis(/artifactId) (version)3.2.8(/version) (/dependency) 2.设置配置文件 2.1 mapper.xml //文件名可以随意,但后面会引用 (mapper namespace=“EmpMapper”) (!-- 在mapper标签内部可以配置很多字标签:select/insert/delete/update等 --) (select id=“findAll” resultType=“com.cy.pojo.Emp”)(!–resultType指定结果集用什么类型来封装 --) select * from emp (/select) (/mapper) 2.2

mybatis-generator-plugin

喜夏-厌秋 提交于 2020-01-16 02:10:26
1.背景 这篇文章刚开始想着哪个分类呢?mybatis、idea或是maven呢,最后还是选择了mybatis。最初使用这个逆向工具是在eclipse上,使用的是eclispe上mbg插件执行配置generatorConfig.xml文件;现在idea作为主力开发工具,而网上基本上都是介绍使用maven的mbg插件,而不是idea的插件执行generatorConfig.xml。本篇文章也是重复验证一下idea中maven使用mybatis-generator插件,至于idea的插件,最后试一下(其实另一篇文章已经介绍了一种easycode插件)。 2.工程结构 3.配置文件 generatorConfig.xml, 该文件是逆向工程核心文件,该实验中需要配置在pom.xml文件中; <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <classPathEntry location="

MybatisPlusException: Error: Cannot execute table Method, ClassGenricType not found

北城余情 提交于 2020-01-15 18:53:22
错误介绍: 使用mp的IService CRUD接口报错如下: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Cannot execute table Method, ClassGenricType not found 项目背景: 项目集成Mybatis-plus(以下简称mp)之后,想要批量插入数据,又不想自己写sql循环插入,也不想用mp的Mapper CRUD 接口,因为该接口只支持单条数据插入,循环插入的话感觉不好。查看官方文档,发现 Service CRUD 接口 支持批量数据插入: 官方方法: // 插入一条记录(选择字段,策略插入) boolean save(T entity); // 插入(批量) boolean saveBatch(Collection<T> entityList); // 插入(批量) boolean saveBatch(Collection<T> entityList, int batchSize); 于是单独写了类实现 IService 接口,但是类里面需要实现基类里面的所有方法(试了一下,不能正常保存,明显思路不对了) 网上搜了一圈之后发现:下面的类实现了 IService com.baomidou.mybatisplus.extension

【Mybatis】使用@Mapper和使用@Repository的区别

不羁的心 提交于 2020-01-15 06:46:16
大家在编写mybatis的接口类时, 可以使用@Mapper, 也可使用@Repository。 两者的差别是: 如果使用@Repository, 你还得在启动类上添加@MapperScan注解。 而使用@Mapper,则不需要添加@MapperScan注解。 个人喜欢使用@Mapper。 来源: CSDN 作者: 中年油腻男人的转型之路 链接: https://blog.csdn.net/hui85206/article/details/103843378