# mybatis-mapper-demo **Repository Path**: wxpcode123/mybatis-mapper-demo ## Basic Information - **Project Name**: mybatis-mapper-demo - **Description**: 这是center.wxp.mapper即是通用mapper查询demo,代码模板,自动生成service、serviceImpl、controller模板代码。 、、 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-03-23 - **Last Updated**: 2022-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mybatis-mapper-demo ### 介绍 这是center.wxp.mapper即是通用mapper查询demo,代码模板,自动生成service、serviceImpl、controller模板代码。 、、 #### 软件架构 Spring boot、Mybatis、tk.mapper、freemarker ### 使用说明 #### 1. 项目参数配置: center.wxp.mapper.support.constant.ProjectConstant类: 代码示例: ``` /** * 作者名称 */ public static final String AUTHOR = "wuxiaopeng"; /*******************JDBC配置************************/ public static final String JDBC_URL = "jdbc:mysql://localhost:3306/test?nullCatalogMeansCurrent=true"; public static final String JDBC_USERNAME = "root"; public static final String JDBC_PASSWORD = "123456"; public static final String JDBC_DIVER_CLASS_NAME = "com.mysql.jdbc.Driver"; /*******************文件路径配置************************/ public static final String BASE_PACKAGE = "center.wxp.mapper"; //生成的Model所在包 public static final String MODEL_PACKAGE = BASE_PACKAGE + ".model.entity"; //生成的Mapper所在包 public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".mapper"; //生成的Service所在包 public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service"; //生成的ServiceImpl所在包 public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl"; //生成的Controller所在包 public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".controller"; //生成sql的xml资源文件路径 public static final String XML_PATH = "/mapper"; /**************模板文件路径(需要放在test路径下)******************************/ //项目在硬盘上的基础路径,这是idea默认的不需要修改 public static final String PROJECT_PATH = System.getProperty("user.dir"); //生成的模板位置 public static final String TEMPLATE_FILE_PATH = PROJECT_PATH + "/src/test/resources/generator/template"; /**************资源文件路径******************************/ //java文件路径 public static final String JAVA_PATH = "/src/main/java"; //资源文件路径 public static final String RESOURCES_PATH = "/src/main/resources"; ``` 根据自己的项目进行相应修改,注意模板只能放在test文件下。 #### 2. 在test添加模板 /src/test/resources/generator/template,模板文件 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0323/161012_b044cbc5_375326.png "屏幕截图.png") #### 3. 生成模板类: ![输入图片说明](https://images.gitee.com/uploads/images/2020/0323/161100_f2858f24_375326.png "屏幕截图.png") 其中GeneratorCodeMain是生成模板主类: ``` /** * @author wuxiaopeng * @description: 生成TK模板代码 * @date 2020/3/4 15:46 */ public class GeneratorCodeMain { public static void main(String[] args) { //生成表、可以使用数组同时生成多张表使用逗号分开 genMoreTable("user"); //自定义生成的类名 //genCodeByCustomModelName("user", "user1"); } } ``` #### 码云特技 1. 本人博客:https://blog.csdn.net/xp_lx1