vps网站管理助手教程,网站的建设 教学计划,探马scrm,iis 添加网站 win7刚学MyBatis逆向工程#xff08;还以为要反汇编呢.....#xff09; MyBatis逆向工程 个人理解就是链接数据库自动生成相关的增删改查相关的类 以及xml文件 #xff08;其中有一些不足 应该就是多表链接的问题需要自己写吧#xff09; MyBatis逆向工程 一般和主项目分开 比较…刚学MyBatis逆向工程还以为要反汇编呢..... MyBatis逆向工程 个人理解就是链接数据库自动生成相关的增删改查相关的类 以及xml文件 其中有一些不足 应该就是多表链接的问题需要自己写吧 MyBatis逆向工程 一般和主项目分开 比较清楚 另外 在配置文件中的包名希望和你工程文件包名都保持一致要不需要手动改 本项目来源 黑马商城资源 我的是mysql 项目地址 https://www.lanzous.com/i3eb3sj generatorConfig.xml ?xml version1.0 encodingUTF-8?
!DOCTYPE generatorConfigurationPUBLIC -//mybatis.org//DTD MyBatis Generator Configuration 1.0//ENhttp://mybatis.org/dtd/mybatis-generator-config_1_0.dtdgeneratorConfigurationcontext idtestTables targetRuntimeMyBatis3commentGenerator!-- 是否去除自动生成的注释 true是 false:否 --property namesuppressAllComments valuetrue //commentGenerator!--数据库连接的信息驱动类、连接地址、用户名、密码 --jdbcConnection driverClasscom.mysql.jdbc.DriverconnectionURLjdbc:mysql://localhost:3306/db_test userIdrootpasswordroot/jdbcConnection!-- jdbcConnection driverClassoracle.jdbc.OracleDriverconnectionURLjdbc:oracle:thin:127.0.0.1:1521:yycg userIdyycgpasswordyycg/jdbcConnection --!-- 默认false把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --javaTypeResolverproperty nameforceBigDecimals valuefalse //javaTypeResolver!-- targetProject:生成PO类的位置 --javaModelGenerator targetPackagecom.pojotargetProject.\src!-- enableSubPackages:是否让schema作为包的后缀 --property nameenableSubPackages valuefalse /!-- 从数据库返回的值被清理前后的空格 --property nametrimStrings valuetrue //javaModelGenerator!-- targetProject:mapper映射文件生成的位置 --sqlMapGenerator targetPackagecom.mappertargetProject.\resource!-- enableSubPackages:是否让schema作为包的后缀 --property nameenableSubPackages valuefalse //sqlMapGenerator!-- targetPackagemapper接口生成的位置 --javaClientGenerator typeXMLMAPPERtargetPackagecom.mappertargetProject.\src!-- enableSubPackages:是否让schema作为包的后缀 --property nameenableSubPackages valuefalse //javaClientGenerator!-- 指定数据库表 --table schema tableNameuser/table!--table schema tableNamepassword/table--!--table schema tableNamecountrylanguage/table--!--table schema tableNamesku/table--!--table schema tableNamebrand/table--!--table schema tableNamead_category/table--!--table schema tableNamead_content/table--!--table schema tableNameuser/table--!--table schema tableNameaddress/table--!--table schema tableNameprovinces/table--!--table schema tableNamecities/table--!--table schema tableNameareas/table--!--table schema tableNameorder_sku/table--!--table schema tableNameorderinfo/table--!-- 有些表的字段需要指定java类型table schema tableNamecolumnOverride column javaType //table --/context
/generatorConfiguration View Code 自动生成类的代码 package com.itcast;import java.io.File;
import java.util.ArrayList;
import java.util.List;import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;public class GeneratorSqlmap {public void generator() throws Exception{ListString warnings new ArrayListString();boolean overwrite true;File configFile new File(generatorConfig.xml); ConfigurationParser cp new ConfigurationParser(warnings);Configuration config cp.parseConfiguration(configFile);DefaultShellCallback callback new DefaultShellCallback(overwrite);MyBatisGenerator myBatisGenerator new MyBatisGenerator(config,callback, warnings);myBatisGenerator.generate(null);} public static void main(String[] args) throws Exception {try {GeneratorSqlmap generatorSqlmap new GeneratorSqlmap();generatorSqlmap.generator();} catch (Exception e) {e.printStackTrace();}}} 关于自动生成的文件一般有两种 一个是example 一个是你数据库的名字类 你 数据库名字(类) set 和get方法用来设置里面的值 比如你Update 一个表 给定的方法一般都是这个具体参照 https://blog.csdn.net/biandous/article/details/65630783 example 类一般是用于添加条件的 比如 你 select username from t_user where username (这里一般是你example 类添加的)转载于:https://www.cnblogs.com/xuexidememeda/p/10513651.html