mybatis自动生成mapping文件
来源:互联网 发布:比特币软件 编辑:程序博客网 时间:2024/05/21 19:28
老的经典框架像ssh ssm ssmm,数据传输层用hibernate和mabatis的属于比较流行的,hibernate的映射文件有几种生成方式,这里主要结束mabatis映射文件的生成方式:
1、环境
数据库:MariaDB(就是mysql)
开发工具:springsts-3.9.0(版本启动需要jdk1.8,如果环境变量不是1.8,自己设置一下init文件的虚拟机环境,设置成1.8)
2、只结束两种简单的方式
(1)、下载mybatis-generator-core-1.3.2.jar和mysql-connector-java-5.1.35.jar放到一个文件中,新建一个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="E:\software\SSMM\CmdGenerator\mysql-connector-java-5.1.35.jar" /><!--<classPathEntry location="xxxxx\ojdbc14.jar" /> --><context id="DB2Tables" targetRuntime="MyBatis3"><commentGenerator><property name="suppressAllComments" value="true" /></commentGenerator><!-- 数据库链接URL、用户名、密码 --><jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://*。*。*。*:*/*" userId="*" password="*"> <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="xe" password="xe">--></jdbcConnection><javaTypeResolver><property name="forceBigDecimals" value="false" /></javaTypeResolver><!-- 生成模型的包名和位置 --><javaModelGenerator targetPackage="*.model" targetProject="E:\**\src"><property name="enableSubPackages" value="true" /><property name="trimStrings" value="true" /></javaModelGenerator><!-- 生成的映射文件包名和位置 --><sqlMapGenerator targetPackage="*.mapping" targetProject="E:\**\src"><property name="enableSubPackages" value="true" /></sqlMapGenerator><!-- 生成DAO的包名和位置 --><javaClientGenerator type="XMLMAPPER" targetPackage="*.dao" targetProject="E:\**\src"><property name="enableSubPackages" value="true" /></javaClientGenerator><!-- 要生成那些表(更改tableName和domainObjectName就可以) --><table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /><table tableName="user_role" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /><table tableName="role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /><table tableName="role_permission" domainObjectName="RolePermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /><table tableName="permission" domainObjectName="Permission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /></context></generatorConfiguration>很简单,从上往下就是根据数据库驱动包连接你要连接的数据库,生成名字是model、mapping、dao的文件夹,存在在targetProject指向的绝对路径下,并且根据数据库表名实体类的映射;tableName->domainObjectName
第二部进入dos命令,执行java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
目录结构如下:
(2)第二种更简单,直接在spring-sts ->help ->eclipse marketplace 搜索mybatis
点击install,创建一个maven项目,右键新建->others->
创建一个generatorConfig.xml文件,里面内容和上面那个文件一样,复制过来把绝对路径改成项目的绝对路径就行,然后右键general mybatis/ibatis artifacts,完事了。
每次新建一个数据库表,增删查改可以通过这两种方式生成,剩下的多表关联还是要自己写语句,mybatis简单,就是写sql语句。
阅读全文
0 0
- mybatis自动生成mapping文件
- mybatis自动生成dao、Mapping文件
- mybatis,自动生成domain、dao、mapping文件
- Mybatis自动生成dao,mapping,model文件
- 利用mybatis-generator自动生成JavaBean,mapping映射文件等
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 周期串UVa455
- 【LeetCode】 括号匹配1 Valid Parentheses
- 学习网址
- snapdragon camera中专业名词简单介绍
- F
- mybatis自动生成mapping文件
- POJ 3026 Borg Maze 最小生成树+BFS
- 入职第五天
- 使用 vue-cli 搭建项目
- Linux 动态库与静态库制作
- python:导入模块的三种不同方法,类似于import
- 开辟动态空间
- 学识尚浅,闭关修炼
- qt串口调试助手