本记录适用初次接触mybatis,大神忽略。。。

 整体上分两个部分:

  1、使用mybatis genertor自动生成代码

  2、mapper的扫描

1、使用mybatis genertor自动生成代码

  一、在pom中添加依赖

<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.6</version>
</dependency>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
generatorConfig.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="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/lilacfover?serverTimezone=UTC" userId="root" password="Crte@123">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.lilacfover.mybatisgenertor.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 targetProject也可以配置为src/main/java-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.lilacfover.mybatisgenertor.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table tableName="admin_user" domainObjectName="Admin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration> 到此配置完成点击自动生成

最后生成情况如下图:

然后直接使用即可,我这里在controler简单调用了一下:

2、mapper扫描。

  如果不在maven中配置数据源  那么在application.properties只能扫描到resources下的xml  配置为:mybatis.mapper-locations= classpath:mapper/*.xml

  但是我们将mapper放在java下这种方式不能扫描到,需要在maven中配置数据源如下:

<resources>

    <resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources> 然后在配置中配置xml扫描路径为:mybatis.mapper-locations= classpath:com/lilacfover/mybatisgenertor/mapper/*.xml 另外还要在mapper中添加@mapper注解 本次说明的地方大部分是我在使用中遇见的一些问题,希望对初次使用的有所帮助

记录一次mybatis genertor使用以及mapper扫描遇见的问题的更多相关文章

  1. Mybatis:通过MapperScannerConfigurer进行mapper扫描

    在applicationContext.xml里配置的

  2. Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring

    Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring 非原创[只为记录],原博文地址:https://www.cnblogs.com/ ...

  3. mybatis由浅入深day01_5.3 Mapper动态代理方法

    5.3 Mapper动态代理方法(程序员只需要写mapper接口(相当于dao接口)) 5.3.1 实现原理(mapper代理开发规范) 程序员还需要编写mapper.xml映射文件 程序员编写map ...

  4. Java框架之MyBatis 06-全局配置-mapper映射-分步查询

    MyBatis MyBatis是Apache的一个开源项目iBatis, iBatis一词来源于“internet”和“abatis”的组合,是一个基于Java的持久层框架. iBatis  提供的持 ...

  5. (转)Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring

    Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring Mybatis在与Spring集成的时候可以配置MapperFactoryBea ...

  6. MyBatis入门程序之Mapper代理方式

    Mapper代理的开发方式,程序员只需要编写mapper接口(相当于dao接口)即可,MyBatis会自动为mapper接口生成动态代理实现类. 一.开发规范 1.mapper接口的全限定名要和map ...

  7. mybatis开发Dao的Mapper动态代理方式

    1. 开发规范Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体跟Dao原始方法中接口实现类的方法相 ...

  8. [springboot 开发单体web shop] 2. Mybatis Generator 生成common mapper

    Mybatis Generator tool 在我们开启一个新项目的研发后,通常要编写很多的entity/pojo/dto/mapper/dao..., 大多研发兄弟们都会抱怨,为什么我要重复写CRU ...

  9. Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring - 大新博客 - 推酷 - 360安全浏览器 7.1

    Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring - 大新博客 时间 2014-02-11 21:08:00  博客园-所有随笔区 ...

随机推荐

  1. 2018-8-10-win10-uwp-读取保存WriteableBitmap-、BitmapImage

    title author date CreateTime categories win10 uwp 读取保存WriteableBitmap .BitmapImage lindexi 2018-08-1 ...

  2. H3C 帧中继数据链路标识

  3. Linux 查看kafka版本

    find /opt -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*'

  4. CCPC2018 桂林 G "Greatest Common Divisor"(数学)

    UPC备战省赛组队训练赛第十七场 with zyd,mxl G: Greatest Common Divisor 题目描述 There is an array of length n, contain ...

  5. while循环&CPU占用率高问题深入分析与解决方案

    直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方.使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果, ...

  6. 程序员必备神器(FastStoneCapture)

    工欲善其事,必先利其器. 作为程序员,如果我们不知道如何制作动态图或者快捷录屏.录视频等,会给人一种身怀不技的感觉:好!屁话少说,接下来我会废话连篇的介绍一款神器--------那就是FastSton ...

  7. Java动态编译优化——提升编译速度(N倍)

    一.前言 最近一直在研究Java8 的动态编译, 并且也被ZipFileIndex$Entry 内存泄漏所困扰,在无意中,看到一个第三方插件的动态编译.并且编译速度是原来的2-3倍.原本打算直接用这个 ...

  8. H3C系统调试的操作

  9. ZR7.26

    7.26 A 并查集维护,时间复杂度我写的貌似不大对,先鸽一鸽 B 敦爷:\(w\)是这个区间的最大值当且仅当他是这个区间内最大的 我们发现结合昨天课件内的并查集 发现我们每次不断合并的本质是把所有\ ...

  10. Boring Class HDU - 5324 (CDQ分治)

    Mr. Zstu and Mr. Hdu are taking a boring class , Mr. Zstu comes up with a problem to kill time, Mr. ...