<?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>
<!-- 配置属性文件 用来在配置文件中引入变量 El表达式 -->
<!-- 如果是用cmd方式运行 这里应该写url方式写全路径 因为找不到classpath 对于resource来说 -->
<!--
<properties url="file:///D:/workspaces/mybatisGen/bin/generatorConfig.properties"/>
-->
<!-- 数据库驱动包位置 -->
<!-- SQL Server数据驱动包 -->
<classPathEntry location="D:\JavaProject\generator\sqljdbc4-4.0.jar" />
<!-- Oracle数据驱动包 -->
<!--
<classPathEntry location="D:\Java\m2\repository\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar" />
-->
<!-- MySQL数据驱动包 -->
<!--
<classPathEntry location="D:\JavaProject\generator\mysql-connector-java-5.1.34.jar" />
-->
<!-- 此处指定生成针对MyBatis3的DAO-->
<!--
id: 必须配置。这个上下文的惟一标识符。该值将被用在一些错误消息。
defaultModelType:用来定义生成模型类型策略。
1.conditional 默认策略,为每个表生成一个Model class
2.flat:将所有的表中生成一个Model class,即这个类将保存所有表中字段
3.hierarchical :如果表有一个主键,该模型将生成一个主键类,另一个类,用于容纳任何BLOB列在表中,和另一个类,用于容纳其余的字段。这个是一个适当的继承类之间的关系。
targetRuntime:此属性用于指定运行时目标生成的代码。
1.MyBatis3 默认值 将生成对象兼容MyBatis版本3.0和更高版本,和JSE 5.0和更高版本
(例如Java模型和mapper接口将使用泛型类型)。
“by example”方法在这些生成的对象支持几乎无限的动态where子句。
此外,Java对象与这些生成器生成支持许多JSE 5.0特性包括参数化的类型和注释。
2.Ibatis2Java2
3.Ibatis2Java5
-->
<context id="MySQLTables" targetRuntime="MyBatis3" defaultModelType="conditional">
<!--
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
-->
<!--
用来生成注释
1. suppressAllComments 默认是false 此属性用于指定在生成的代码是否将包括任何注释。如果设置为true 则不生成注释
2. suppressDate 默认是false 此属性用于指定在生成的注释是否将包括MBG代时间戳。
-->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<!-- MySQL数据库链接URL、用户名、密码 -->
<!--
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3310/test" userId="test" password="1234">
</jdbcConnection>
-->
<!-- Oracle数据库链接URL、用户名、密码 -->
<!--
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl" userId="test" password="1234">
</jdbcConnection>
-->
<!-- SQL Server数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test" userId="test" password="1234">
</jdbcConnection>
<!-- H2
<entry key="jdbc.url">jdbc:h2:tcp://localhost/test</entry>
<entry key="jdbc.driver">org.h2.Driver</entry>
-->
<!-- SQLServer2000
<entry key="jdbc.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=[database]</entry>
<entry key="jdbc.driver">com.microsoft.jdbc.sqlserver.SQLServerDriver</entry>
-->
<!-- SQLServer2005
<entry key="jdbc.url">jdbc:sqlserver://192.168.0.98:1433;DatabaseName=[database]</entry>
<entry key="jdbc.driver">com.microsoft.sqlserver.jdbc.SQLServerDriver</entry>
-->
<!-- JTDs for SQLServer
<entry key="jdbc.url">jdbc:jtds:sqlserver://192.168.0.102:1433/[database];tds=8.0;lastupdatecount=true</entry>
<entry key="jdbc.driver">net.sourceforge.jtds.jdbc.Driver</entry>
-->
<!-- PostgreSql
<entry key="jdbc.url">jdbc:postgresql://localhost/[database]</entry>
<entry key="jdbc.driver">org.postgresql.Driver</entry>
-->
<!-- Sybase
<entry key="jdbc.url">jdbc:sybase:Tds:localhost:5007/[database]</entry>
<entry key="jdbc.driver">com.sybase.jdbc.SybDriver</entry>
-->
<!-- DB2
<entry key="jdbc.url">jdbc:db2://localhost:5000/[database]</entry>
<entry key="jdbc.driver">com.ibm.db2.jdbc.app.DB2Driver</entry>
-->
<!-- HsqlDB
<entry key="jdbc.url">jdbc:hsqldb:mem:generatorDB</entry>
<entry key="jdbc.driver">org.hsqldb.jdbcDriver</entry>
-->
<!-- Derby
<entry key="jdbc.url">jdbc:derby://localhost/databaseName</entry>
<entry key="jdbc.driver">org.apache.derby.jdbc.ClientDriver</entry>
-->
<!-- java类型解析器 可选配置 -->
<!--
<javaTypeResolver type="">
type属性: 这可用于指定一个用户提供的Java类型解析器。这个类必须实现接口org.mybatis.generator.api。
JavaTypeResolver,必须有一个公共的默认构造函数。属性还可以接受特殊的值默认在这种情况下,将使用默认的实现(这同样的效果不指定类型)。
该标签支持的属性:
forceBigDecimals:默认是false 是否强制使用BigDecimal来表示所有的十进制和数值字段。
•如果规模很大,长度大于18,将使用BigDecimal类型。
•如果其长度为10到18,则Java类型解析器将java.lang.Long来代替了。
•如果长度为5到9,然后Java类型解析器将替换为一个Java.lang.integer。
•如果其长度小于5,则Java类型解析器将以java.lang.Short替代。
-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成vo对象 -->
<!--
< javaModelGenerator >元素用于定义Java模型生成的属性。
Java模型生成器建立主键类,记录类,和查询示例类相匹配的表进行自省。这个元素是所需的子元素<上下文>元素。
支持的属性:
constructorBased:
此属性用于选择是否MyBatis生成器将生成一个类的构造函数,它接受一个值类中的每个字段。同时,SQL结果地图将建成投入使用构造函数而不是“setter”每个字段。
这个属性是只适用于MyBatis3和将被忽略了iBATIS2。
默认值是false。
immutable:
不可变,此属性用于选择是否MyBatis生成器将产生不可变模型类——这意味着类不会有“setter”方法和构造函数会接受类中每个字段的值。默认为false。
trimStrings:
此属性用于选择MyBatis生成器是否添加代码来修剪的字符字段从数据库返回的空白空间。
这很有用,如果您的数据库将数据存储在字符字段而不是VARCHAR字段。MyBatis生成器将插入代码来削减字符字段。
默认值是false。
-->
<!-- 生成实体类的包名和位置,这里配置将生成的实体类放在com.ouc.model这个包下 -->
<javaModelGenerator targetPackage="com.ouc.model" targetProject="D:\JavaProject\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成用于查询的mapping对象 -->
<!-- 生成的SQL映射文件包名和位置,这里配置将生成的SQL映射文件放在com.ouc.mapping这个包下 -->
<sqlMapGenerator targetPackage="com.ouc.mapping" targetProject="D:\JavaProject\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的类文件以及配置文件 -->
<!--
< javaClientGenerator >元素是用来定义Java客户机代码生成器的属性。
Java客户机生成器用来建立Java接口和类,以便可以方便地使用生成的Java模型和XML映射文件。
对于iBATIS2目标环境,这些生成的对象采用形式的DAO接口和实现类。
对于MyBatis,生成的对象采用mapper形式的接口。
这个元素是一个可选的子元素。
如果你不指定这个元素,MyBatis生成器(MBG)不会生成Java客户端接口和类。
其中的type属性:
如果targetRuntime 为MyBatis3
XMLMAPPER:生成的对象将Java接口MyBatis 3.x mapper基础设施。接口将会依赖生成的XML映射器文件。一般都是使用这个XMLMAPPER.
-->
<!-- 生成DAO的包名和位置,这里配置将生成的dao类放在com.ouc.dao这个包下 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.ouc.dao" targetProject="D:\JavaProject\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--
<table>元素用于选择数据库中的一个表。选择的表将导致为每个表生成以下对象:
•一个MyBatis / iBATIS•格式化的SQL的映射文件
•一组类,形成了“模型”表包括:
•一个类来匹配•表的主键(如果表有一个主键)。
•表中字段匹配的,不是在主键,而非BLOB字段。这个类将扩展主键,如果有一个。
•一个类来持有任何表中的BLOB字段(如果有的话)。这个类将扩展其中一个的前面两个类取决于表的配置。
•一个类,用于生成动态where子句,在不同的“by Example”方法(selectByExample,deleteByExample)。
•(可选)DAO接口和类
tableName:必须配置 指定表的名称
domainObjectName:生成javabean对象的基本名称。如果未指定,MBG将自动基于表名生成。
这个名字(无论是在这里指定,或自动生成)将被用来作为域类名和DAO类的名字。
enableInsert:是否生成插入语句。默认是true
enableSelectByPrimaryKey:是否通过主键生成选择语句。不管是否有这种设置,如果该表没有一个主键将不会生成。
enableUpdateByPrimaryKey:是否通过主键生成更新语句。如果该表没有主键,不管是否设置该属性,语句将不会生成。
enableDeleteByPrimaryKey:是否通过主键生成删除语句。如果该表没有主键,不管这种设置该属性,语句将不会生成。
enableDeleteByExample:是否通过example对象生成删除语句。这个声明使得许多不同的动态删除在运行时生成。
enableCountByExample:是否通过example对象生成计算行数语句。该语句将返回一个表中的行数相匹配的example。
enableUpdateByExample:是否通过example对象生成更新语句。该语句将更新一个表中相匹配的记录。
selectByPrimaryKeyQueryId:这个值将被添加到选择列表中选择通过主键的声明在本表格:“' <值>作为QUERYID”。这可以用于识别查询在DBA在运行时跟踪工具。如果你需使用,你应该指定一个唯一的id为每个不同的查询生成MBG。
selectByExampleQueryId:这个值将被添加到选择列表中选择通过例子的声明在本表格:“' <值>作为QUERYID”。这可以用于识别查询在DBA在运行时跟踪工具。如果你需使用,你应该指定一个唯一的id为每个不同的查询生成MBG。
enableSelectByExample:是否应该生成通过example的选择语句。这个声明使得许多不同的动态查询是在运行时生成。
modelType:此属性用于覆盖默认的模型类型,如果你想对这张表这么做。如果未指定,MBG将生成的域对象基于上下文默认的模型类型。
该模型类型定义了如何将生成MBG域类。
一些模型类型MBG将生成一个单一的域类为每个表,和其他可能产生不同的类MBG取决于表的结构。
escapeWildcards:排除通配符。这意味着无论SQL通配符(' _ '和' % ')的模式和表名都应该避免在搜寻列。
这是一些驱动要求如果模式或表包含一个SQL通配符(例如,如果一个表的名字是MY_TABLE,一些驱动要求的下划线字符进行转义)。
-->
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<table tableName="V_SupplyUser" domainObjectName="VSupplyUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="WJ_GateList" domainObjectName="WJGateList" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="cacheEnabled" value="true" /> <setting name="lazyLoadingEnabled" value="true" /> <setting name="multipleResultSetsEnabled" value="true" /> <setting name="useColumnLabel" value="true" /> <setting name="useGeneratedKeys" value="false" /> <setting name="autoMappingBehavior" value="PARTIAL" /> <setting name="defaultExecutorType" value="SIMPLE" /><!-- SIMPLE REUSE BATCH --> <!-- <setting name="defaultExecutorType" value="BATCH" /> --> <setting name="defaultStatementTimeout" value="" /> <setting name="safeRowBoundsEnabled" value="false" /> <setting name="mapUnderscoreToCamelCase" value="false" /> <setting name="localCacheScope" value="SESSION" /> <!-- <setting name="jdbcTypeForNull" value="OTHER" /> --> <setting name="jdbcTypeForNull" value="NULL" /> <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString" /> </settings> <typeAliases> <!-- 模块 --> <typeAlias alias="User" type="com.ouc.mkhl.platform.authority.model.User"/> <typeAlias alias="Role" type="com.ouc.mkhl.platform.authority.model.Role"/> <typeAlias alias="Equipment" type="com.ouc.mkhl.platform.basedata.model.Equipment"/> <typeAlias alias="Factory" type="com.ouc.mkhl.platform.basedata.model.Factory"/> </typeAliases> <typeHandlers> <typeHandler handler="com.ouc.openplatform.dao.mybatis.SerializableTypeHandler"/> </typeHandlers> </configuration>
package com.ouc.openplatform.dao.mybatis;
import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
/**
* @author WuPing
*/
public class SerializableTypeHandler extends BaseTypeHandler<Serializable> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Serializable parameter, JdbcType jdbcType)
throws SQLException {
ps.setObject(i, parameter);
}
@Override
public Serializable getNullableResult(ResultSet rs, String columnName)
throws SQLException {
return (Serializable)rs.getObject(columnName);
}
@Override
public Serializable getNullableResult(ResultSet rs, int columnIndex)
throws SQLException {
return (Serializable)rs.getObject(columnIndex);
}
@Override
public Serializable getNullableResult(CallableStatement cs, int columnIndex)
throws SQLException {
return (Serializable)cs.getObject(columnIndex);
}
}
<resultMap id="UserBaseResultMap" type="User" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="userName" property="userName" jdbcType="VARCHAR" /> <result column="password" property="password" jdbcType="VARCHAR" /> <result column="email" property="email" jdbcType="VARCHAR" /> <result column="trueName" property="trueName" jdbcType="VARCHAR" /> <result column="sex" property="sex" jdbcType="VARCHAR" /> <result column="age" property="age" jdbcType="INTEGER" /> <result column="telephone" property="telephone" jdbcType="VARCHAR" /> </resultMap>
package com.ouc.mkhl.platform.authority.model;
import java.io.Serializable;
//用户信息
public class User implements Serializable {
private static final long serialVersionUID = 1098321123L;
private Integer id; //用户Id
private String userName; //用户名
private String password; //未加密密码
private String email; //邮箱
private String trueName; //真实姓名
private String sex; //性别
private Integer age; //年龄
private String telephone; //手机
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName == null ? null : userName.trim();
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password == null ? null : password.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email == null ? null : email.trim();
}
public String getTrueName() {
return trueName;
}
public void setTrueName(String trueName) {
this.trueName = trueName == null ? null : trueName.trim();
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex == null ? null : sex.trim();
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone == null ? null : telephone.trim();
}
}
<select id="selectUsers" resultMap="UserBaseResultMap"> select id,userName,email from user </select>
<insert id="saveUser" parameterType="User" >
insert into user (userName, password, email, trueName, sex, age, telephone)
values (#{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{trueName,jdbcType=VARCHAR},
#{sex,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}, #{telephone,jdbcType=VARCHAR})
</insert>
<update id="updateUser" parameterType="User" >
update user
<set >
<if test="userName != null" >
userName = #{userName,jdbcType=VARCHAR},
</if>
<if test="password != null" >
password = #{password,jdbcType=VARCHAR},
</if>
<if test="email != null" >
email = #{email,jdbcType=VARCHAR},
</if>
<if test="trueName != null" >
trueName = #{trueName,jdbcType=VARCHAR},
</if>
<if test="sex != null" >
sex = #{sex,jdbcType=VARCHAR},
</if>
<if test="age != null" >
age = #{age,jdbcType=INTEGER},
</if>
<if test="telephone != null" >
telephone = #{telephone,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteUser" parameterType="Integer">
delete from user
where id = #{id,jdbcType=INTEGER}
</delete>
<sql id="UserBaseColumnList" > userName, password, email, telephone </sql> <select id="getUsers" resultMap="UserBaseResultMap"> select <include refid="UserBaseColumnList" /> from user </select>
<select id="getUserByName" resultType="User" parameterType="String" >
select id, userName, email from user
where userName = #{userName,jdbcType=VARCHAR}
</select>
public User getUserByName(String name); // 根据用户名获取用户信息
<insert id="saveUser" parameterType="User" >
insert into user (userName, password, email, trueName, sex, age, telephone)
values (#{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{trueName,jdbcType=VARCHAR},
#{sex,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}, #{telephone,jdbcType=VARCHAR})
</insert>
public int saveUser(User user); // 插入用户信息
<select id="selectChildGroupTotalNum" resultType="Integer" >
select count(*) from groupinfo
<trim prefix="WHERE" prefixOverrides="AND|OR">
and id in
<foreach collection="idStr" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
<if test="name!= null and name!='' " >
and name LIKE CONCAT(CONCAT('%', #{name}),'%')
</if>
<if test="description!= null and description!='' " >
AND description LIKE CONCAT(CONCAT('%', #{description}),'%')
</if>
<if test="type != null and type!=-1 " >
AND type = #{type,jdbcType=INTEGER}
</if>
<if test="category != null and category!=-1 " >
AND category = #{category,jdbcType=INTEGER}
</if>
</trim>
</select>
//获取子组总记录数
public int selectChildGroupTotalNum(Map<String, Object> recordMap);
Map<String, Object> recordMap = new HashMap<String, Object>();
recordMap.put("idStr", group.getChildgroupids().split(","));
recordMap.put("name", name);
recordMap.put("description", description);
recordMap.put("type", -1);
recordMap.put("category", -1);
childGroupTotalNum = groupDao.selectChildGroupTotalNum(recordMap);
<!-- 根据参数名查询参数 -->
<select id="selectSensorNobySensorName" resultType="Integer" useCache="false" flushCache="true">
select SensorNo from sensorconfig
where Name = #{0} and TestunitNo = #{1} and LABCODE = #{2}
</select>
//根据参数名查询参数ID public int selectSensorNobySensorName(String sensorName, int testUnitNo, String labCode);
<select id="selectByUserNameAndVCode" resultMap="UserBaseResultMap">
select id, userName from user
<trim prefix="WHERE" prefixOverrides="AND|OR">
<if test="userName!= null and userName!='' ">
and userName LIKE CONCAT(CONCAT('%', #{userName}),'%')
</if>
<if test="supplierno!= null and supplierno!='' ">
and supplierNo LIKE CONCAT(CONCAT('%', #{supplierno}),'%')
</if>
and supplierNo != 'test'
</trim>
LIMIT #{startIndex},#{pageSize}
</select>
// 根据用户名和V码查询用户信息
public List<User> selectByUserNameAndVCode(
@Param("userName") String userName,
@Param("supplierno") String supplierno,
@Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
<select id="selectTotalNumByAccountType" resultType="Integer" >
select count(*) from user
<trim prefix="WHERE" prefixOverrides="AND|OR">
and id not in
<foreach collection="idStr" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
<if test="userName!= null and userName!='' ">
and userName LIKE CONCAT(CONCAT('%', #{userName}),'%')
</if>
<if test="supplierno!= null and supplierno!='' ">
and supplierNo LIKE CONCAT(CONCAT('%', #{supplierno}),'%')
</if>
<if test="trueName!= null and trueName!='' ">
and trueName LIKE CONCAT(CONCAT('%', #{trueName}),'%')
</if>
AND accountType = #{accountType}
</trim></select>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有