Commit d53783a9 authored by jmdhappy's avatar jmdhappy
Browse files

初始化提交

parent 324ccaaf
package org.xxpay.dal.dao.plugin;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;
import java.util.List;
/**
* @Description: MySql分页插件
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
public class PaginationPlugin extends PluginAdapter {
@Override
public boolean validate(List<String> list) {
return true;
}
/**
* 为每个Example类添加limit和offset属性和set、get方法
*/
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
PrimitiveTypeWrapper integerWrapper = FullyQualifiedJavaType.getIntInstance().getPrimitiveTypeWrapper();
Field limit = new Field();
limit.setName("limit");
limit.setVisibility(JavaVisibility.PRIVATE);
limit.setType(integerWrapper);
topLevelClass.addField(limit);
Method setLimit = new Method();
setLimit.setVisibility(JavaVisibility.PUBLIC);
setLimit.setName("setLimit");
setLimit.addParameter(new Parameter(integerWrapper, "limit"));
setLimit.addBodyLine("this.limit = limit;");
topLevelClass.addMethod(setLimit);
Method getLimit = new Method();
getLimit.setVisibility(JavaVisibility.PUBLIC);
getLimit.setReturnType(integerWrapper);
getLimit.setName("getLimit");
getLimit.addBodyLine("return limit;");
topLevelClass.addMethod(getLimit);
Field offset = new Field();
offset.setName("offset");
offset.setVisibility(JavaVisibility.PRIVATE);
offset.setType(integerWrapper);
topLevelClass.addField(offset);
Method setOffset = new Method();
setOffset.setVisibility(JavaVisibility.PUBLIC);
setOffset.setName("setOffset");
setOffset.addParameter(new Parameter(integerWrapper, "offset"));
setOffset.addBodyLine("this.offset = offset;");
topLevelClass.addMethod(setOffset);
Method getOffset = new Method();
getOffset.setVisibility(JavaVisibility.PUBLIC);
getOffset.setReturnType(integerWrapper);
getOffset.setName("getOffset");
getOffset.addBodyLine("return offset;");
topLevelClass.addMethod(getOffset);
return true;
}
/**
* 为Mapper.xml的selectByExample添加limit,offset
*/
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element,
IntrospectedTable introspectedTable) {
XmlElement ifLimitNotNullElement = new XmlElement("if");
ifLimitNotNullElement.addAttribute(new Attribute("test", "limit != null"));
XmlElement ifOffsetNotNullElement = new XmlElement("if");
ifOffsetNotNullElement.addAttribute(new Attribute("test", "offset != null"));
ifOffsetNotNullElement.addElement(new TextElement("limit ${offset}, ${limit}"));
ifLimitNotNullElement.addElement(ifOffsetNotNullElement);
XmlElement ifOffsetNullElement = new XmlElement("if");
ifOffsetNullElement.addAttribute(new Attribute("test", "offset == null"));
ifOffsetNullElement.addElement(new TextElement("limit ${limit}"));
ifLimitNotNullElement.addElement(ifOffsetNullElement);
element.addElement(ifLimitNotNullElement);
return true;
}
}
package org.xxpay.dal.dao.plugin;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.*;
import java.util.List;
import java.util.Properties;
/**
* @Description: Example类和model类实现序列化插件
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
public class SerializablePlugin extends PluginAdapter {
private FullyQualifiedJavaType serializable = new FullyQualifiedJavaType("java.io.Serializable");
private FullyQualifiedJavaType gwtSerializable = new FullyQualifiedJavaType("com.google.gwt.user.client.rpc.IsSerializable");
private boolean addGWTInterface;
private boolean suppressJavaInterface;
public SerializablePlugin() {
}
public boolean validate(List<String> warnings) {
return true;
}
public void setProperties(Properties properties) {
super.setProperties(properties);
this.addGWTInterface = Boolean.valueOf(properties.getProperty("addGWTInterface")).booleanValue();
this.suppressJavaInterface = Boolean.valueOf(properties.getProperty("suppressJavaInterface")).booleanValue();
}
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
this.makeSerializable(topLevelClass, introspectedTable);
return true;
}
public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
this.makeSerializable(topLevelClass, introspectedTable);
return true;
}
public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
this.makeSerializable(topLevelClass, introspectedTable);
return true;
}
protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
if(this.addGWTInterface) {
topLevelClass.addImportedType(this.gwtSerializable);
topLevelClass.addSuperInterface(this.gwtSerializable);
}
if(!this.suppressJavaInterface) {
topLevelClass.addImportedType(this.serializable);
topLevelClass.addSuperInterface(this.serializable);
Field field = new Field();
field.setFinal(true);
field.setInitializationString("1L");
field.setName("serialVersionUID");
field.setStatic(true);
field.setType(new FullyQualifiedJavaType("long"));
field.setVisibility(JavaVisibility.PRIVATE);
this.context.getCommentGenerator().addFieldComment(field, introspectedTable);
topLevelClass.addField(field);
}
}
/**
* 添加给Example类序列化的方法
* @param topLevelClass
* @param introspectedTable
* @return
*/
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable){
makeSerializable(topLevelClass, introspectedTable);
for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
if ("GeneratedCriteria".equals(innerClass.getType().getShortName())) {
innerClass.addSuperInterface(serializable);
}
if ("Criteria".equals(innerClass.getType().getShortName())) {
innerClass.addSuperInterface(serializable);
}
if ("Criterion".equals(innerClass.getType().getShortName())) {
innerClass.addSuperInterface(serializable);
}
}
return true;
}
}
generator.jdbc.driver=com.mysql.jdbc.Driver
generator.jdbc.url=jdbc:mysql://127.0.0.1:3306/xxpaydb?useUnicode=true&characterEncoding=utf-8&autoReconnect=true
generator.jdbc.username=xxpay
generator.jdbc.password=xxpay
classPathEntry=/Users/dingzhiwei/java/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar
\ No newline at end of file
<?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>
<!-- 配置文件 -->
<properties resource="generator.properties"></properties>
<!-- 驱动包 -->
<classPathEntry location="${classPathEntry}" />
<context id="MysqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号("),在Mysql中不能这么写,所以还要将这两个默认值改为` -->
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="useActualColumnNames" value="false" />
<!-- 为生成的Java模型创建一个toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
<!-- 为生成的Java模型类添加序列化接口,并生成serialVersionUID字段 -->
<plugin type="org.xxpay.dal.dao.plugin.SerializablePlugin">
<property name="suppressJavaInterface" value="false"/>
</plugin>
<!-- 生成一个新的selectByExample方法,这个方法可以接收offset和limit参数,主要用来实现分页 -->
<plugin type="org.xxpay.dal.dao.plugin.PaginationPlugin"></plugin>
<!-- Java模型生成equals和hashcode方法 -->
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
<!-- 生成的代码去掉注释 -->
<commentGenerator type="org.xxpay.dal.dao.plugin.CommentGenerator">
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!-- 数据库连接 -->
<jdbcConnection driverClass="${generator.jdbc.driver}"
connectionURL="${generator.jdbc.url}"
userId="${generator.jdbc.username}"
password="${generator.jdbc.password}"/>
<!-- model生成 -->
<javaModelGenerator targetPackage="org.xxpay.dal.dao.model" targetProject="src/main/java"/>
<!-- MapperXML生成 -->
<sqlMapGenerator targetPackage="org.xxpay.dal.dao.mapper" targetProject="src/main/resources"/>
<!-- Mapper接口生成 -->
<javaClientGenerator targetPackage="org.xxpay.dal.dao.mapper" targetProject="src/main/java" type="XMLMAPPER"/>
<!-- 需要映射的表 -->
<table tableName="t_pay_order" domainObjectName="PayOrder"><property name="useActualColumnNames" value="true" /></table>
<table tableName="t_trans_order" domainObjectName="TransOrder"><property name="useActualColumnNames" value="true" /></table>
<table tableName="t_pay_channel" domainObjectName="PayChannel"><property name="useActualColumnNames" value="true" /></table>
<table tableName="t_mch_info" domainObjectName="MchInfo"><property name="useActualColumnNames" value="true" /></table>
<table tableName="t_iap_receipt" domainObjectName="IapReceipt"><property name="useActualColumnNames" value="true" /></table>
</context>
</generatorConfiguration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.xxpay.dal.dao.mapper.MchInfoMapper" >
<resultMap id="BaseResultMap" type="org.xxpay.dal.dao.model.MchInfo" >
<id column="MchId" property="mchId" jdbcType="VARCHAR" />
<result column="Name" property="name" jdbcType="VARCHAR" />
<result column="Type" property="type" jdbcType="VARCHAR" />
<result column="ReqKey" property="reqKey" jdbcType="VARCHAR" />
<result column="ResKey" property="resKey" jdbcType="VARCHAR" />
<result column="State" property="state" jdbcType="TINYINT" />
<result column="CreateTime" property="createTime" jdbcType="TIMESTAMP" />
<result column="UpdateTime" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
MchId, Name, Type, ReqKey, ResKey, State, CreateTime, UpdateTime
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="org.xxpay.dal.dao.model.MchInfoExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from t_mch_info
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from t_mch_info
where MchId = #{mchId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from t_mch_info
where MchId = #{mchId,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="org.xxpay.dal.dao.model.MchInfoExample" >
delete from t_mch_info
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="org.xxpay.dal.dao.model.MchInfo" >
insert into t_mch_info (MchId, Name, Type,
ReqKey, ResKey, State,
CreateTime, UpdateTime)
values (#{mchId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR},
#{reqKey,jdbcType=VARCHAR}, #{resKey,jdbcType=VARCHAR}, #{state,jdbcType=TINYINT},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="org.xxpay.dal.dao.model.MchInfo" >
insert into t_mch_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="mchId != null" >
MchId,
</if>
<if test="name != null" >
Name,
</if>
<if test="type != null" >
Type,
</if>
<if test="reqKey != null" >
ReqKey,
</if>
<if test="resKey != null" >
ResKey,
</if>
<if test="state != null" >
State,
</if>
<if test="createTime != null" >
CreateTime,
</if>
<if test="updateTime != null" >
UpdateTime,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="mchId != null" >
#{mchId,jdbcType=VARCHAR},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="type != null" >
#{type,jdbcType=VARCHAR},
</if>
<if test="reqKey != null" >
#{reqKey,jdbcType=VARCHAR},
</if>
<if test="resKey != null" >
#{resKey,jdbcType=VARCHAR},
</if>
<if test="state != null" >
#{state,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="org.xxpay.dal.dao.model.MchInfoExample" resultType="java.lang.Integer" >
select count(*) from t_mch_info
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update t_mch_info
<set >
<if test="record.mchId != null" >
MchId = #{record.mchId,jdbcType=VARCHAR},
</if>
<if test="record.name != null" >
Name = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.type != null" >
Type = #{record.type,jdbcType=VARCHAR},
</if>
<if test="record.reqKey != null" >
ReqKey = #{record.reqKey,jdbcType=VARCHAR},
</if>
<if test="record.resKey != null" >
ResKey = #{record.resKey,jdbcType=VARCHAR},
</if>
<if test="record.state != null" >
State = #{record.state,jdbcType=TINYINT},
</if>
<if test="record.createTime != null" >
CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null" >
UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update t_mch_info
set MchId = #{record.mchId,jdbcType=VARCHAR},
Name = #{record.name,jdbcType=VARCHAR},
Type = #{record.type,jdbcType=VARCHAR},
ReqKey = #{record.reqKey,jdbcType=VARCHAR},
ResKey = #{record.resKey,jdbcType=VARCHAR},
State = #{record.state,jdbcType=TINYINT},
CreateTime = #{record.createTime,jdbcType=TIMESTAMP},
UpdateTime = #{record.updateTime,jdbcType=TIMESTAMP}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="org.xxpay.dal.dao.model.MchInfo" >
update t_mch_info
<set >
<if test="name != null" >
Name = #{name,jdbcType=VARCHAR},
</if>
<if test="type != null" >
Type = #{type,jdbcType=VARCHAR},
</if>
<if test="reqKey != null" >
ReqKey = #{reqKey,jdbcType=VARCHAR},
</if>
<if test="resKey != null" >
ResKey = #{resKey,jdbcType=VARCHAR},
</if>
<if test="state != null" >
State = #{state,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
CreateTime = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
UpdateTime = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where MchId = #{mchId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="org.xxpay.dal.dao.model.MchInfo" >
update t_mch_info
set Name = #{name,jdbcType=VARCHAR},
Type = #{type,jdbcType=VARCHAR},
ReqKey = #{reqKey,jdbcType=VARCHAR},
ResKey = #{resKey,jdbcType=VARCHAR},
State = #{state,jdbcType=TINYINT},
CreateTime = #{createTime,jdbcType=TIMESTAMP},
UpdateTime = #{updateTime,jdbcType=TIMESTAMP}
where MchId = #{mchId,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment