A simple example is created, but the following code always reports null exceptions:
Configuration of mybatis-generator. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype generatorconfiguration System
Http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd>
<Generatorconfiguration>
<! -- Configure the path of the JDBC driver package -->
<! -- <Classpathentry location = "F: \ workspace \ javaee \ mybatis2 \ webcontent \ WEB-INF \ Lib \ sqljdbc4.jar"/> -->
<Classpathentry location = ". lib/sqljdbc4.jar"/>
<Context ID = "account_table" targetruntime = "mybatis3">
<! -- Configuration comment -->
<Commentgenerator>
<! -- Whether to remove all automatically generated comment files -->
<Property name = "suppressallcomments" value = "true"/>
<! -- Whether to remove the timestamp of all automatically generated files. The default value is false. -->
<Property name = "suppressdate" value = "true"/>
</Commentgenerator>
<Jdbcconnection
Connectionurl = "JDBC: sqlserver: // localhost: 1433; databasename = mybank"
Driverclass = "com. Microsoft. sqlserver. JDBC. sqlserverdriver"
Userid = "sa"
Password = "zxcv1234"
/>
<Javatyperesolver>
<! -- Convert the decimal and numberic types in JDBC to the integer type -->
<Property name = "forcebigdecimals" value = "false"/>
</Javatyperesolver>
<! -- Model layer corresponding to the data table -->
<Javamodelgenerator targetpackage = "com. My. pojo" targetproject = "src">
<Property name = "enablesubpackages" value = "true"/>
<Property name = "trimstrings" value = "true"/>
</Javamodelgenerator>
<! -- SQL mapper ing configuration -->
<Sqlmapgenerator targetpackage = "com. My. mapper" targetproject = "src">
<Property name = "enablesubpackages" value = "true"/>
</Sqlmapgenerator>
<! -- Mapper interface -->
<Javaclientgenerator targetpackage = "com. My. Inter" type = "xmlmapper" targetproject = "src">
<Property name = "enablesubpackages" value = "true"/>
</Javaclientgenerator>
<! -- Operate on those data tables -->
<! -- Schema: tablename indicates that domainobjectname corresponds to your JavaBean class name, and whether to generate the corresponding example -->
<Table tablename = "Account" schema = "mybatis_db" domainobjectname = "Account"
Enablecountbyexample = "false" enabledeletebyexample = "false"
Enableselectbyexample = "false" enableupdatebyexample = "false"
Selectbyexamplequeryid = "false"
/>
</Context>
</Generatorconfiguration>
Test implementation class genmain
Package com. My. test;
Import java. Io. file;
Import java. Io. ioexception;
Import java. SQL. sqlexception;
Import java. util. arraylist;
Import java. util. List;
Import org. JUnit. test;
Import org. mybatis. generator. API. mybatisgenerator;
Import org. mybatis. generator. config. configuration;
Import org. mybatis. generator. config. xml. configurationparser;
Import org. mybatis. generator. Exception. invalidconfigurationexception;
Import org. mybatis. generator. Exception. xmlparserexception;
Import org. mybatis. generator. Internal. defaultshellcallback;
Public class gentest {
@ Test
Public static void main (string [] ARGs ){
List <string> warnings = new arraylist <string> ();
Boolean overwrite = true;
String gencfg = "/mbg_config.xml ";
File configfile = new file (gentest. Class. getresource (gencfg). GetFile ());
Configurationparser CP = new configurationparser (warnings );
Configuration Config = NULL;
Try {
Config = CP. parseconfiguration (configfile );
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (xmlparserexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Defaultshellcallback callback = new defaultshellcallback (overwrite );
Try {
Mybatisgenerator = new mybatisgenerator (config, callback, warnings );
Mybatisgenerator. Generate (null );
} Catch (invalidconfigurationexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (interruptedexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
System. Out. println ("mybatis generated successfully! ");
}
}
I have not changed it. Write it here first.
Create an object class in mybatis