spring-boot开发微信小程序后台(二)
2019-01-27 10:08
441 查看
spring-boot开发微信小程序后台
spring boot与mybatis整合,mybatis逆向工程生成pojo、mapper、dao
逆向工程目录结构:
pom.xml:
[code]<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- <parent> --> <groupId>cn.zoubin</groupId> <version>0.0.1-SNAPSHOT</version> <!-- </parent> --> <artifactId>mybatis-generatorConfig</artifactId> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- 引入log4j日志依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <version>1.3.8.RELEASE</version> </dependency> <!-- 阿里开源数据源 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> </dependency> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <!--mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>1.2.4</version> </dependency> <!--pagehelper--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency> <!-- mybatis 逆向生成工具 --> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> <scope>compile</scope> <optional>true</optional> </dependency> </dependencies> </project>
GeneratorDisplay:启动类,加载数据库文件。
[code]package cn.zoubin.mybatis.utils; import java.io.File; import java.util.ArrayList; import java.util.List; import org.mybatis.generator.api.MyBatisGenerator; import org.mybatis.generator.config.Configuration; import org.mybatis.generator.config.xml.ConfigurationParser; import org.mybatis.generator.internal.DefaultShellCallback; public class GeneratorDisplay { public void generator() throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true; //指定 逆向工程配置文件 File configFile = new File("generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); } public static void main(String[] args) throws Exception { try { GeneratorDisplay generatorSqlmap = new GeneratorDisplay(); generatorSqlmap.generator(); } catch (Exception e) { e.printStackTrace(); } } }
MyMapper:固定接口,生成dao类的继承父类,不能被扫描。
[code]/* * The MIT License (MIT) * * Copyright (c) 2014-2016 abel533@gmail.com * * 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 cn.zoubin.utils; import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.MySqlMapper; public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> { //TODO //FIXME 特别注意,该接口不能被扫描到,否则会出错 }
generatorConfiguration.xml:配置文件,有关数据库,生成内容都在里面。
[code]<?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> <context id="MysqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat"> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <plugin type="tk.mybatis.mapper.generator.MapperPlugin"> <property name="mappers" value="cn.zoubin.utils.MyMapper"/> </plugin> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/" userId="" password=""> </jdbcConnection> <!-- 对应生成的pojo所在包 --> <javaModelGenerator targetPackage="cn.jxau.panshi.pojo" targetProject="src/main/java"/> <!-- 对应生成的mapper所在目录 --> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/> <!-- 配置mapper对应的java映射 --> <javaClientGenerator targetPackage="cn.jxau.panshi.mapper" targetProject="src/main/java" type="XMLMAPPER"/> <table tableName="answer"></table> <table tableName="blog"></table> <table tableName="book"></table> <table tableName="comment"></table> <table tableName="lend_book"></table> <table tableName="mission"></table> <table tableName="on_watch"></table> <table tableName="question"></table> <table tableName="report"></table> <table tableName="sign"></table> <table tableName="study_plan"></table> <table tableName="user"></table> <table tableName="works"></table> </context> </generatorConfiguration>
在配置文件中配置好所有信息后,就可以启动启动类,生成的代码、类都在你指定的包内。
相关文章推荐
- 微信小程序开发(一)——使用ssh(struts2+hibernate+spring)框架实现后台与微信前台进行通信
- 为什么下一个5年java后台开发你该选择Spring Boot?
- 从零开始学微信小程序开发:9 与后台交互
- 微信小程序--后端管理平台9页面Springboot接受表单实体
- activemq整合springboot使用方法(个人微信小程序用)
- phpcms v9开发的微信小程序后台管理插件(企业版)
- springboot开发中使用postman 向后台传递json数据的时候,为空
- 微信小程序——设置Springboot本地服务器端口和地址,从而访问项目外文件夹的内容
- SpringBoot 仿抖音短视频小程序开发 全栈式实战项目分享
- 微信小程序 获取 open-id --- SpringBoot
- 开发第一个Spring Boot 程序
- 第一个Spring Boot开发的小程序
- 建站集成软件包 XAMPP搭建后台系统与微信小程序开发
- java SpringMVC mybatis 后台框架 集成代码生成器开发利器 全部源码_java微信接口开发
- 记一次外包项目微信接口开发流程-spring-boot
- 为什么下一个5年java后台开发你该选择Spring Boot?
- django后台开发微信小程序
- 前后分离敏捷开发框架源码基于Vue+ElementUI+Springboot后台权限
- 为什么下一个5年java后台开发你该选择Spring Boot?
- Java微信开发——分享功能的实现(Spring boot框架)