All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tk.mybatis.mapper.generator.TkMyBatis3SimpleImpl Maven / Gradle / Ivy

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2017 [email protected]
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package tk.mybatis.mapper.generator;

import org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3SimpleImpl;

import java.text.MessageFormat;

import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;

/**
 * 可以通过MBG1.3.4+版本提供的table元素的mapperName属性设置统一的名称,使用{0}作为实体类名的占位符。
 * 

* 用法: *

 * <context id="Mysql" targetRuntime="tk.mybatis.mapper.generator.TkMyBatis3SimpleImpl" defaultModelType="flat">
 * </context>
 * 
*

* * @author liuzh * @since 2016-09-04 09:57 */ public class TkMyBatis3SimpleImpl extends IntrospectedTableMyBatis3SimpleImpl { @Override protected String calculateMyBatis3XmlMapperFileName() { StringBuilder sb = new StringBuilder(); if (stringHasValue(tableConfiguration.getMapperName())) { String mapperName = tableConfiguration.getMapperName(); int ind = mapperName.lastIndexOf('.'); if (ind != -1) { mapperName = mapperName.substring(ind + 1); } //支持mapperName = "{0}Dao" 等用法 sb.append(MessageFormat.format(mapperName, fullyQualifiedTable.getDomainObjectName())); sb.append(".xml"); //$NON-NLS-1$ } else { sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("Mapper.xml"); //$NON-NLS-1$ } return sb.toString(); } @Override protected void calculateJavaClientAttributes() { if (context.getJavaClientGeneratorConfiguration() == null) { return; } StringBuilder sb = new StringBuilder(); sb.append(calculateJavaClientImplementationPackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("DAOImpl"); //$NON-NLS-1$ setDAOImplementationType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("DAO"); //$NON-NLS-1$ setDAOInterfaceType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); if (stringHasValue(tableConfiguration.getMapperName())) { //支持mapperName = "{0}Dao" 等用法 sb.append(MessageFormat.format(tableConfiguration.getMapperName(), fullyQualifiedTable.getDomainObjectName())); } else { sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("Mapper"); //$NON-NLS-1$ } setMyBatis3JavaMapperType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); if (stringHasValue(tableConfiguration.getSqlProviderName())) { //支持mapperName = "{0}SqlProvider" 等用法 sb.append(MessageFormat.format(tableConfiguration.getSqlProviderName(), fullyQualifiedTable.getDomainObjectName())); } else { sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("SqlProvider"); //$NON-NLS-1$ } setMyBatis3SqlProviderType(sb.toString()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy