In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to achieve Springboot version of mybatis reverse generation, the article is very detailed, has a certain reference value, interested friends must read it!
Code generator
Reverse generation of pojo and mybatis corresponding to mysql does not affect existing business logic through a separate project.
Mybatis-generatorConfig project
Generate the corresponding table structure and table data through the sql in the source code.
Pom file for mybatis-generatorConfig
4.0.0 com.idig8 0.0.1-SNAPSHOT mybatis-generatorConfig UTF-8 org.springframework.boot spring-boot-starter-log4j 1.3.8.RELEASE com.alibaba druid 1.1.0 Com.alibaba druid-spring-boot-starter 1.1.0 mysql mysql-connector-java 5.1.41 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 Tk.mybatis mapper-spring-boot-starter 1.2.4 com.github.pagehelper pagehelper-spring-boot-starter 1.2.3 org.mybatis.generator mybatis-generator-core 1.3.2 compile true
Add a generatorConfig.xml file
GeneratorDisplay.java class
Package com.idig8.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 warnings = new ArrayList (); boolean overwrite = true / / specify reverse engineering configuration files 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 ();}
Add a MyMapper.java file
/ * 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 com.idig8.utils;import tk.mybatis.mapper.common.Mapper;import tk.mybatis.mapper.common.MySqlMapper;public interface MyMapper extends Mapper, MySqlMapper {/ / TODO / / FIXME pay special attention to the fact that the interface cannot be scanned, otherwise an error will occur.
Run the main method of GeneratorDisplay
Copy the com.idig8.mapper directory to the wx-springboot-mapper project
Copy the com.idig8.pojo directory to the wx-springboot-pojo project
Copy the com.idig8.utils directory to the wx-springboot-common project
Copy resources mapper into the resources of wx-springboot-api
PS:mybatis-generatorConfig can be seen as a separate project, the main purpose is to upgrade to the corresponding mapper.xml and the corresponding pojo entity class, mapper corresponding entity.
These are all the contents of the article "how to reverse generate mybatis for Springboot". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.