diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..89e08fb002e48e22363b7b3789a5470ffe71fea1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b567fc82280a90b1a79a7d293fd8c815f7d48cac --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# mybatisdubbomysql + +#### 介绍 +mybatis连接双数据库 +3种方式 + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/dynamicmybatisdubbomysql/pom.xml b/dynamicmybatisdubbomysql/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..4ac4bd8bc28178cc79c5525fd06f59c011fb3f05 --- /dev/null +++ b/dynamicmybatisdubbomysql/pom.xml @@ -0,0 +1,91 @@ + + + + mybatisdubbomysql + com.lin + 0.0.1-SNAPSHOT + + 4.0.0 + + dynamicmybatisdubbomysql + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-aop + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + mysql + mysql-connector-java + + + com.baomidou + mybatis-plus-boot-starter + + + com.alibaba + druid-spring-boot-starter + + + com.baomidou + mybatis-plus-generator + test + + + org.apache.velocity + velocity-engine-core + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + \ No newline at end of file diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplication.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplication.java similarity index 66% rename from staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplication.java rename to dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplication.java index 1779cd954a357f1d1cd0eead25059dfb412cdfb6..83a9da52e92b91db86285c2c99174808f5fba7b5 100644 --- a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplication.java +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplication.java @@ -1,6 +1,6 @@ package com.lin.mybatisdubbomysql; -import org.mybatis.spring.annotation.MapperScan; +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @@ -10,12 +10,11 @@ import org.springframework.context.annotation.ComponentScan; * @author 九分石人 */ @ComponentScan(basePackages = "com.lin.mybatisdubbomysql.*") -@MapperScan(basePackages = "com.lin.mybatisdubbomysql.dal.mapper") -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) -public class StaticmybatisdubbomysqlApplication { +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class}) +public class DynamicMybatisDubboMysqlApplication { public static void main(String[] args) { - SpringApplication.run(StaticmybatisdubbomysqlApplication.class, args); + SpringApplication.run(DynamicMybatisDubboMysqlApplication.class, args); } } diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/aop/DatasourceAspect.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/aop/DatasourceAspect.java new file mode 100644 index 0000000000000000000000000000000000000000..d42600486db9e2ea60b2ce4e4e46f198bb57d29c --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/aop/DatasourceAspect.java @@ -0,0 +1,33 @@ +package com.lin.mybatisdubbomysql.aop; + +import com.lin.mybatisdubbomysql.enums.DateBaseEnum; +import com.lin.mybatisdubbomysql.extend.DynamicDataSource; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +/** + * @author 九分石人 + */ +@Component +@Aspect +public class DatasourceAspect { + + + @Pointcut("execution(public * com.lin.mybatisdubbomysql.dal.mapper.databasetwo..*.*(..))") + public void dataSourcePointCut() { + + } + + @Around("dataSourcePointCut()") + public Object around(ProceedingJoinPoint point) throws Throwable { + DynamicDataSource.setDataSource(DateBaseEnum.DataBaseTwo.getValue()); + try { + return point.proceed(); + } finally { + DynamicDataSource.clearDataSource(); + } + } +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DBConfig.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DBConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..21c8ebcc3f8176fa3c9db694f8a7b326cae8b37c --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DBConfig.java @@ -0,0 +1,53 @@ +package com.lin.mybatisdubbomysql.config; + +import com.alibaba.druid.pool.DruidDataSource; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.lin.mybatisdubbomysql.enums.DateBaseEnum; +import com.lin.mybatisdubbomysql.extend.DynamicDataSource; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +/** + * @author 九分石人 + */ +@Configuration +@MapperScan(basePackages = "com.lin.mybatisdubbomysql.dal.mapper",sqlSessionFactoryRef = "sqlSessionFactory") +public class DBConfig { + + @Bean + @ConfigurationProperties(prefix = "spring.datasourceone") + public DataSource dataSourceOne() { + return new DruidDataSource(); + } + + @Bean + @ConfigurationProperties(prefix = "spring.datasourcetwo") + public DataSource dataSourceTwo() { + return new DruidDataSource(); + } + + @Bean + @Primary + public DynamicDataSource dataSource(DataSource dataSourceOne,DataSource dataSourceTwo){ + Map targetDataSources = new HashMap<>(8); + targetDataSources.put(DateBaseEnum.DataBaseOne.getValue(),dataSourceOne); + targetDataSources.put(DateBaseEnum.DataBaseTwo.getValue(), dataSourceTwo); + return new DynamicDataSource(dataSourceOne, targetDataSources); + } + + @Bean + public SqlSessionFactory sqlSessionFactory(DynamicDataSource dynamicDataSource) throws Exception { + MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); + sqlSessionFactoryBean.setDataSource(dynamicDataSource); + return sqlSessionFactoryBean.getObject(); + } + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3738657e22716028a5af0fc5374466b69f74af65 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java @@ -0,0 +1,48 @@ +package com.lin.mybatisdubbomysql.config; + +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +/** + * @author 九分石人 + */ +@Configuration +public class DruidConfig { + /** + * 主要实现WEB监控的配置处理 + */ + @Bean + public ServletRegistrationBean druidServlet() { + // 现在要进行druid监控的配置处理操作 + ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>( + new StatViewServlet(), "/druid/*"); + // 白名单,多个用逗号分割, 如果allow没有配置或者为空,则允许所有访问 + servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); + // 黑名单,多个用逗号分割 (共同存在时,deny优先于allow) + servletRegistrationBean.addInitParameter("deny", "192.168.1.110"); + // 控制台管理用户名 + servletRegistrationBean.addInitParameter("loginUsername", "admin"); + // 控制台管理密码 + servletRegistrationBean.addInitParameter("loginPassword", "admin"); + // 是否可以重置数据源,禁用HTML页面上的“Reset All”功能 + servletRegistrationBean.addInitParameter("resetEnable", "false"); + return servletRegistrationBean; + } + + @Bean + public FilterRegistrationBean filterRegistrationBean() { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(); + filterRegistrationBean.setFilter(new WebStatFilter()); + //所有请求进行监控处理 + filterRegistrationBean.addUrlPatterns("/*"); + //添加不需要忽略的格式信息 + filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.css,/druid/*"); + return filterRegistrationBean; + } + +} \ No newline at end of file diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java new file mode 100644 index 0000000000000000000000000000000000000000..552ebca331109641bf696b2ff9c9aefe749e144f --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java @@ -0,0 +1,36 @@ +package com.lin.mybatisdubbomysql.dal.bean.databaseone; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("user") +public class User implements Serializable { + + private static final long serialVersionUID=1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String username; + + private String mobile; + + private LocalDateTime createTime; + + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..79eef03b85b54aaae053afd18642940bd12fa2c7 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java @@ -0,0 +1,36 @@ +package com.lin.mybatisdubbomysql.dal.bean.databasetwo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("order_info") +public class OrderInfo implements Serializable { + + private static final long serialVersionUID=1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String orderId; + + private Integer userId; + + private LocalDateTime createTime; + + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..930eb34cc843d4942f58a1762742183f06e776d6 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.dal.mapper.databaseone; + +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface UserMapper extends BaseMapper { + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..a90d4e43b943e21cb529f6534aa670f027ce90b1 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.dal.mapper.databasetwo; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoMapper extends BaseMapper { + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/enums/DateBaseEnum.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/enums/DateBaseEnum.java new file mode 100644 index 0000000000000000000000000000000000000000..9965d24c4fd1c3615f40220d8017caba222828a8 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/enums/DateBaseEnum.java @@ -0,0 +1,25 @@ +package com.lin.mybatisdubbomysql.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author 九分石人 + */ +@AllArgsConstructor +@Getter +public enum DateBaseEnum { + + + /** + * 数据库one + */ + DataBaseOne("one", "one"), + /** + * 数据库two + */ + DataBaseTwo("two", "two"); + + private final String name; + private final String value; +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/extend/DynamicDataSource.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/extend/DynamicDataSource.java new file mode 100644 index 0000000000000000000000000000000000000000..3cc1f653f671ec5d2c17168ce6b3d5615b10ee1c --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/extend/DynamicDataSource.java @@ -0,0 +1,37 @@ +package com.lin.mybatisdubbomysql.extend; + +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; + +import javax.sql.DataSource; +import java.util.Map; + +/** + * @author 九分石人 + */ +public class DynamicDataSource extends AbstractRoutingDataSource { + + private static final ThreadLocal CONTEXT_HOLDER = new ThreadLocal<>(); + + public DynamicDataSource(DataSource defaultTargetDataSource, Map targetDataSources) { + super.setDefaultTargetDataSource(defaultTargetDataSource); + super.setTargetDataSources(targetDataSources); + super.afterPropertiesSet(); + } + + @Override + protected Object determineCurrentLookupKey() { + return getDataSource(); + } + + public static void setDataSource(String dataSource) { + CONTEXT_HOLDER.set(dataSource); + } + + public static String getDataSource() { + return CONTEXT_HOLDER.get(); + } + + public static void clearDataSource() { + CONTEXT_HOLDER.remove(); + } +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java new file mode 100644 index 0000000000000000000000000000000000000000..df071c13a9e746221bd98f21d3266eb3f5d99e8a --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoService extends IService { + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java new file mode 100644 index 0000000000000000000000000000000000000000..b643233cfbcfb62eae60547be84c9fafa7434671 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface UserService extends IService { + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..a4f0fd37e3239a4d4f6bb1281e420331298c895b --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java @@ -0,0 +1,20 @@ +package com.lin.mybatisdubbomysql.service.impl; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.lin.mybatisdubbomysql.dal.mapper.databasetwo.OrderInfoMapper; +import com.lin.mybatisdubbomysql.service.OrderInfoService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Service +public class OrderInfoServiceImpl extends ServiceImpl implements OrderInfoService { + +} diff --git a/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..cded7ba4151e281c18997cbbb7e79ed9dfc9da11 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java @@ -0,0 +1,20 @@ +package com.lin.mybatisdubbomysql.service.impl; + +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.lin.mybatisdubbomysql.dal.mapper.databaseone.UserMapper; +import com.lin.mybatisdubbomysql.service.UserService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + +} diff --git a/dynamicmybatisdubbomysql/src/main/resources/application.yml b/dynamicmybatisdubbomysql/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..14c20e6caffa558c9a6fa8c930e6aba1a8304201 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/resources/application.yml @@ -0,0 +1,15 @@ +spring: + application: + name: dynamicmybatisdubbomysql + datasourceone: + url: jdbc:mysql://localhost:3306/mybatisdubboone?serverTimezone=GMT + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 1234 + type: com.alibaba.druid.pool.DruidDataSource + datasourcetwo: + url: jdbc:mysql://localhost:3306/mybatisdubbotwo?serverTimezone=GMT + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 1234 + type: com.alibaba.druid.pool.DruidDataSource \ No newline at end of file diff --git a/dynamicmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml b/dynamicmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..15cd17fa8eac3543b6671773177be84a97fc2960 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/dynamicmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml b/dynamicmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..62023eb9d9bc26eb8d6d38a0e3fb150bffb67e05 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplicationTests.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..c272060af8f5dee3146f4549d7cdca6051e13569 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/DynamicMybatisDubboMysqlApplicationTests.java @@ -0,0 +1,7 @@ +package com.lin.mybatisdubbomysql; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class DynamicMybatisDubboMysqlApplicationTests { +} diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..87fdf21d4858608e87e29c62ad562025a36f0a12 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java @@ -0,0 +1,98 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +public class DatabaseOneCodeGenerator { + + public static final String DB_URL = "jdbc:mysql://localhost:3306/mybatisdubboone?serverTimezone=GMT"; + public static final String USER_NAME = "root"; + public static final String PASSWORD = "1234"; + public static final String DRIVER = "com.mysql.cj.jdbc.Driver"; + public static final String AUTHOR = "九分石人"; + //生成的文件输出到哪个目录 + public static final String OUTPUT_FILE = "/src/main/java"; + //包名,会按照com/example/demo这种形式生成类 + public static final String PACKAGE = "com.lin.mybatisdubbomysql"; + + //TODO 更多配置请参考http://mp.baomidou.com/#/generate-code + + public void generateByTables(boolean serviceNameStartWithI, String path, String tablePrefix, String... tableNames) { + GlobalConfig config = new GlobalConfig(); + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setDbType(DbType.MYSQL) + .setUrl(DB_URL) + .setUsername(USER_NAME) + .setPassword(PASSWORD) + .setDriverName(DRIVER); + StrategyConfig strategyConfig = new StrategyConfig(); + strategyConfig + .setCapitalMode(true) + .setEntityLombokModel(true) + .setTablePrefix(tablePrefix) + .setNaming(NamingStrategy.underline_to_camel) + .setColumnNaming(NamingStrategy.underline_to_camel) + .setInclude(tableNames);//修改替换成你需要的表名,多个表名传数组 + config.setActiveRecord(false) + .setAuthor(AUTHOR) + .setOutputDir(path + OUTPUT_FILE) + .setFileOverride(true) + .setMapperName("%sMapper").setXmlName("%sMapper"); + if (!serviceNameStartWithI) { + config.setServiceName("%sService"); + config.setServiceImplName("%sServiceImpl"); + } + + AutoGenerator autoGenerator = new AutoGenerator(); + + +// String templatePath = "/templates/mapper.xml.ftl"; + // 如果模板引擎是 velocity + String templatePath = "/templates/mapper.xml.vm"; + + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + } + }; + List focList = new ArrayList<>(); + // 自定义配置会被优先输出 + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! + return path + "/src/main/resources/mapper/databaseone/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + cfg.setFileOutConfigList(focList); + autoGenerator.setCfg(cfg); + + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setXml(null); + autoGenerator.setTemplate(templateConfig); + + autoGenerator.setGlobalConfig(config) + .setDataSource(dataSourceConfig) + .setStrategy(strategyConfig) + .setPackageInfo( + new PackageConfig().setParent(PACKAGE) + .setController(null) + .setEntity("dal.bean.databaseone") + .setMapper("dal.mapper.databaseone") + .setService("service") + .setServiceImpl("service.impl") + ) + .setTemplateEngine(new VelocityTemplateEngine()) + .execute(); + } +} \ No newline at end of file diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..9e45f2bf1afe4aacb455e4eef31e5a68fa950c45 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java @@ -0,0 +1,98 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +public class DatabaseTwoCodeGenerator { + + public static final String DB_URL = "jdbc:mysql://localhost:3306/mybatisdubbotwo?serverTimezone=GMT"; + public static final String USER_NAME = "root"; + public static final String PASSWORD = "1234"; + public static final String DRIVER = "com.mysql.cj.jdbc.Driver"; + public static final String AUTHOR = "九分石人"; + //生成的文件输出到哪个目录 + public static final String OUTPUT_FILE = "/src/main/java"; + //包名,会按照com/example/demo这种形式生成类 + public static final String PACKAGE = "com.lin.mybatisdubbomysql"; + + //TODO 更多配置请参考http://mp.baomidou.com/#/generate-code + + public void generateByTables(boolean serviceNameStartWithI, String path, String tablePrefix, String... tableNames) { + GlobalConfig config = new GlobalConfig(); + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setDbType(DbType.MYSQL) + .setUrl(DB_URL) + .setUsername(USER_NAME) + .setPassword(PASSWORD) + .setDriverName(DRIVER); + StrategyConfig strategyConfig = new StrategyConfig(); + strategyConfig + .setCapitalMode(true) + .setEntityLombokModel(true) + .setTablePrefix(tablePrefix) + .setNaming(NamingStrategy.underline_to_camel) + .setColumnNaming(NamingStrategy.underline_to_camel) + .setInclude(tableNames);//修改替换成你需要的表名,多个表名传数组 + config.setActiveRecord(false) + .setAuthor(AUTHOR) + .setOutputDir(path + OUTPUT_FILE) + .setFileOverride(true) + .setMapperName("%sMapper").setXmlName("%sMapper"); + if (!serviceNameStartWithI) { + config.setServiceName("%sService"); + config.setServiceImplName("%sServiceImpl"); + } + + AutoGenerator autoGenerator = new AutoGenerator(); + + +// String templatePath = "/templates/mapper.xml.ftl"; + // 如果模板引擎是 velocity + String templatePath = "/templates/mapper.xml.vm"; + + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + } + }; + List focList = new ArrayList<>(); + // 自定义配置会被优先输出 + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! + return path + "/src/main/resources/mapper/databasetwo/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + cfg.setFileOutConfigList(focList); + autoGenerator.setCfg(cfg); + + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setXml(null); + autoGenerator.setTemplate(templateConfig); + + autoGenerator.setGlobalConfig(config) + .setDataSource(dataSourceConfig) + .setStrategy(strategyConfig) + .setPackageInfo( + new PackageConfig().setParent(PACKAGE) + .setController(null) + .setEntity("dal.bean.databasetwo") + .setMapper("dal.mapper.databasetwo") + .setService("service") + .setServiceImpl("service.impl") + ) + .setTemplateEngine(new VelocityTemplateEngine()) + .execute(); + } +} \ No newline at end of file diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..8122beb50074e43035d477c6dd6f67e095de5f28 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java @@ -0,0 +1,23 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import org.junit.jupiter.api.Test; + +/** + * @author 九分石人 + */ +public class LQKCodeGenerator { + + @Test + public void dataOneCodeGernerator() { + DatabaseOneCodeGenerator gse = new DatabaseOneCodeGenerator(); + gse.generateByTables(false, "D:/IdeaProjects/mybatisdubbomysql/dynamicmybatisdubbomysql","", "user"); + } + + @Test + public void dataTwoCodeGernerator() { + DatabaseTwoCodeGenerator gse = new DatabaseTwoCodeGenerator(); + gse.generateByTables(false, "D:/IdeaProjects/mybatisdubbomysql/dynamicmybatisdubbomysql","", "order_info"); + } + +} diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d4c37d3a43cf4f82d70ccc52f5dc79115d4f3bcf --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java @@ -0,0 +1,21 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.DynamicMybatisDubboMysqlApplicationTests; +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; + +public class OrderInfoTest extends DynamicMybatisDubboMysqlApplicationTests { + + @Resource + OrderInfoService orderService; + + @Test + public void addOrderInfo() { + OrderInfo orderInfo = new OrderInfo(); + orderInfo.setOrderId("2345678dfghj"); + orderInfo.setUserId(12); + orderService.save(orderInfo); + } +} diff --git a/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bc3cc62ec021bb7423ea76302ef30c4a494e18d8 --- /dev/null +++ b/dynamicmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java @@ -0,0 +1,23 @@ +package com.lin.mybatisdubbomysql.service; + + +import com.lin.mybatisdubbomysql.DynamicMybatisDubboMysqlApplicationTests; +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; + +public class UserTest extends DynamicMybatisDubboMysqlApplicationTests { + + @Resource + UserService userService; + + @Test + public void userSaveTest() { + User user = new User(); + user.setUsername("linqiankun"); + user.setMobile("14729291172"); + userService.save(user); + } + +} diff --git a/plusmybatisdubbomysql/pom.xml b/plusmybatisdubbomysql/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..2da261b4ad28c9e03e5bfb62c47f183b1f836311 --- /dev/null +++ b/plusmybatisdubbomysql/pom.xml @@ -0,0 +1,75 @@ + + + + mybatisdubbomysql + com.lin + 0.0.1-SNAPSHOT + + 4.0.0 + + plusmybatisdubbomysql + + + + org.springframework.boot + spring-boot-starter-aop + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + com.alibaba + druid-spring-boot-starter + + + com.baomidou + mybatis-plus-boot-starter + + + com.baomidou + dynamic-datasource-spring-boot-starter + + + com.baomidou + mybatis-plus-generator + test + + + mysql + mysql-connector-java + + + org.apache.velocity + velocity-engine-core + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + + test + + + + + \ No newline at end of file diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplication.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..4cdec1149873e30a68a76e84493fd2226ef2ceac --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplication.java @@ -0,0 +1,17 @@ +package com.lin.mybatisdubbomysql; + +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; + +/** + * @author 九分石人 + */ +@ComponentScan(basePackages = "com.lin.mybatisdubbomysql.*") +@MapperScan(basePackages = "com.lin.mybatisdubbomysql.dal.mapper") +@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) +public class PlusMybatisDubboMysqlApplication { +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java new file mode 100644 index 0000000000000000000000000000000000000000..552ebca331109641bf696b2ff9c9aefe749e144f --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databaseone/User.java @@ -0,0 +1,36 @@ +package com.lin.mybatisdubbomysql.dal.bean.databaseone; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("user") +public class User implements Serializable { + + private static final long serialVersionUID=1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String username; + + private String mobile; + + private LocalDateTime createTime; + + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..79eef03b85b54aaae053afd18642940bd12fa2c7 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java @@ -0,0 +1,36 @@ +package com.lin.mybatisdubbomysql.dal.bean.databasetwo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("order_info") +public class OrderInfo implements Serializable { + + private static final long serialVersionUID=1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String orderId; + + private Integer userId; + + private LocalDateTime createTime; + + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..930eb34cc843d4942f58a1762742183f06e776d6 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databaseone/UserMapper.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.dal.mapper.databaseone; + +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface UserMapper extends BaseMapper { + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..a90d4e43b943e21cb529f6534aa670f027ce90b1 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.dal.mapper.databasetwo; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoMapper extends BaseMapper { + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java new file mode 100644 index 0000000000000000000000000000000000000000..df071c13a9e746221bd98f21d3266eb3f5d99e8a --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoService extends IService { + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java new file mode 100644 index 0000000000000000000000000000000000000000..b643233cfbcfb62eae60547be84c9fafa7434671 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/UserService.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface UserService extends IService { + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..ca67b9e5c2d7bf6921e89ba3059e7b38bf0b0df6 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java @@ -0,0 +1,22 @@ +package com.lin.mybatisdubbomysql.service.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.lin.mybatisdubbomysql.dal.mapper.databasetwo.OrderInfoMapper; +import com.lin.mybatisdubbomysql.service.OrderInfoService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Service +@DS("slave") +public class OrderInfoServiceImpl extends ServiceImpl implements OrderInfoService { + +} diff --git a/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..82149c1a101b57aa2df0c317f44e19a1b01c08dc --- /dev/null +++ b/plusmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/UserServiceImpl.java @@ -0,0 +1,22 @@ +package com.lin.mybatisdubbomysql.service.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import com.lin.mybatisdubbomysql.dal.mapper.databaseone.UserMapper; +import com.lin.mybatisdubbomysql.service.UserService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Service +@DS("master") +public class UserServiceImpl extends ServiceImpl implements UserService { + +} diff --git a/plusmybatisdubbomysql/src/main/resources/application.yml b/plusmybatisdubbomysql/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..595a96297c04a614f52e86760a55d3809fd9651a --- /dev/null +++ b/plusmybatisdubbomysql/src/main/resources/application.yml @@ -0,0 +1,18 @@ +spring: + application: + name: plusmybatisdubbomysql + datasource: + dynamic: + primary: master #设置默认的数据源或者数据源组,默认值即为master + strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源. + datasource: + master: + url: jdbc:mysql://localhost:3306/mybatisdubboone?serverTimezone=GMT + username: root + password: 1234 + driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0开始支持SPI可省略此配置 + slave: + url: jdbc:mysql://localhost:3306/mybatisdubbotwo?serverTimezone=GMT + username: root + password: 1234 + driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/plusmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml b/plusmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..15cd17fa8eac3543b6671773177be84a97fc2960 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/resources/mapper/databaseone/UserMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/plusmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml b/plusmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..62023eb9d9bc26eb8d6d38a0e3fb150bffb67e05 --- /dev/null +++ b/plusmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplicationTests.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..b96427db004ed683f95dc6d2e38a4212e6487b08 --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/PlusMybatisDubboMysqlApplicationTests.java @@ -0,0 +1,15 @@ +package com.lin.mybatisdubbomysql; + +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; + +/** + * @author 九分石人 + */ +@SpringBootTest +public class PlusMybatisDubboMysqlApplicationTests { +} diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..87fdf21d4858608e87e29c62ad562025a36f0a12 --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java @@ -0,0 +1,98 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +public class DatabaseOneCodeGenerator { + + public static final String DB_URL = "jdbc:mysql://localhost:3306/mybatisdubboone?serverTimezone=GMT"; + public static final String USER_NAME = "root"; + public static final String PASSWORD = "1234"; + public static final String DRIVER = "com.mysql.cj.jdbc.Driver"; + public static final String AUTHOR = "九分石人"; + //生成的文件输出到哪个目录 + public static final String OUTPUT_FILE = "/src/main/java"; + //包名,会按照com/example/demo这种形式生成类 + public static final String PACKAGE = "com.lin.mybatisdubbomysql"; + + //TODO 更多配置请参考http://mp.baomidou.com/#/generate-code + + public void generateByTables(boolean serviceNameStartWithI, String path, String tablePrefix, String... tableNames) { + GlobalConfig config = new GlobalConfig(); + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setDbType(DbType.MYSQL) + .setUrl(DB_URL) + .setUsername(USER_NAME) + .setPassword(PASSWORD) + .setDriverName(DRIVER); + StrategyConfig strategyConfig = new StrategyConfig(); + strategyConfig + .setCapitalMode(true) + .setEntityLombokModel(true) + .setTablePrefix(tablePrefix) + .setNaming(NamingStrategy.underline_to_camel) + .setColumnNaming(NamingStrategy.underline_to_camel) + .setInclude(tableNames);//修改替换成你需要的表名,多个表名传数组 + config.setActiveRecord(false) + .setAuthor(AUTHOR) + .setOutputDir(path + OUTPUT_FILE) + .setFileOverride(true) + .setMapperName("%sMapper").setXmlName("%sMapper"); + if (!serviceNameStartWithI) { + config.setServiceName("%sService"); + config.setServiceImplName("%sServiceImpl"); + } + + AutoGenerator autoGenerator = new AutoGenerator(); + + +// String templatePath = "/templates/mapper.xml.ftl"; + // 如果模板引擎是 velocity + String templatePath = "/templates/mapper.xml.vm"; + + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + } + }; + List focList = new ArrayList<>(); + // 自定义配置会被优先输出 + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! + return path + "/src/main/resources/mapper/databaseone/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + cfg.setFileOutConfigList(focList); + autoGenerator.setCfg(cfg); + + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setXml(null); + autoGenerator.setTemplate(templateConfig); + + autoGenerator.setGlobalConfig(config) + .setDataSource(dataSourceConfig) + .setStrategy(strategyConfig) + .setPackageInfo( + new PackageConfig().setParent(PACKAGE) + .setController(null) + .setEntity("dal.bean.databaseone") + .setMapper("dal.mapper.databaseone") + .setService("service") + .setServiceImpl("service.impl") + ) + .setTemplateEngine(new VelocityTemplateEngine()) + .execute(); + } +} \ No newline at end of file diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..9e45f2bf1afe4aacb455e4eef31e5a68fa950c45 --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java @@ -0,0 +1,98 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +public class DatabaseTwoCodeGenerator { + + public static final String DB_URL = "jdbc:mysql://localhost:3306/mybatisdubbotwo?serverTimezone=GMT"; + public static final String USER_NAME = "root"; + public static final String PASSWORD = "1234"; + public static final String DRIVER = "com.mysql.cj.jdbc.Driver"; + public static final String AUTHOR = "九分石人"; + //生成的文件输出到哪个目录 + public static final String OUTPUT_FILE = "/src/main/java"; + //包名,会按照com/example/demo这种形式生成类 + public static final String PACKAGE = "com.lin.mybatisdubbomysql"; + + //TODO 更多配置请参考http://mp.baomidou.com/#/generate-code + + public void generateByTables(boolean serviceNameStartWithI, String path, String tablePrefix, String... tableNames) { + GlobalConfig config = new GlobalConfig(); + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setDbType(DbType.MYSQL) + .setUrl(DB_URL) + .setUsername(USER_NAME) + .setPassword(PASSWORD) + .setDriverName(DRIVER); + StrategyConfig strategyConfig = new StrategyConfig(); + strategyConfig + .setCapitalMode(true) + .setEntityLombokModel(true) + .setTablePrefix(tablePrefix) + .setNaming(NamingStrategy.underline_to_camel) + .setColumnNaming(NamingStrategy.underline_to_camel) + .setInclude(tableNames);//修改替换成你需要的表名,多个表名传数组 + config.setActiveRecord(false) + .setAuthor(AUTHOR) + .setOutputDir(path + OUTPUT_FILE) + .setFileOverride(true) + .setMapperName("%sMapper").setXmlName("%sMapper"); + if (!serviceNameStartWithI) { + config.setServiceName("%sService"); + config.setServiceImplName("%sServiceImpl"); + } + + AutoGenerator autoGenerator = new AutoGenerator(); + + +// String templatePath = "/templates/mapper.xml.ftl"; + // 如果模板引擎是 velocity + String templatePath = "/templates/mapper.xml.vm"; + + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + } + }; + List focList = new ArrayList<>(); + // 自定义配置会被优先输出 + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! + return path + "/src/main/resources/mapper/databasetwo/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + cfg.setFileOutConfigList(focList); + autoGenerator.setCfg(cfg); + + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setXml(null); + autoGenerator.setTemplate(templateConfig); + + autoGenerator.setGlobalConfig(config) + .setDataSource(dataSourceConfig) + .setStrategy(strategyConfig) + .setPackageInfo( + new PackageConfig().setParent(PACKAGE) + .setController(null) + .setEntity("dal.bean.databasetwo") + .setMapper("dal.mapper.databasetwo") + .setService("service") + .setServiceImpl("service.impl") + ) + .setTemplateEngine(new VelocityTemplateEngine()) + .execute(); + } +} \ No newline at end of file diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..62fa362127d62b6341bbbe41c03ef90bfa2325b5 --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/LQKCodeGenerator.java @@ -0,0 +1,23 @@ +package com.lin.mybatisdubbomysql.mybatisplus; + + +import org.junit.jupiter.api.Test; + +/** + * @author 九分石人 + */ +public class LQKCodeGenerator { + + @Test + public void dataOneCodeGernerator() { + DatabaseOneCodeGenerator gse = new DatabaseOneCodeGenerator(); + gse.generateByTables(false, "D:/IdeaProjects/mybatisdubbomysql/plusmybatisdubbomysql","", "user"); + } + + @Test + public void dataTwoCodeGernerator() { + DatabaseTwoCodeGenerator gse = new DatabaseTwoCodeGenerator(); + gse.generateByTables(false, "D:/IdeaProjects/mybatisdubbomysql/plusmybatisdubbomysql","", "order_info"); + } + +} diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java new file mode 100644 index 0000000000000000000000000000000000000000..339a0bf757a596b9d8629e114c7a5ae31909d2bf --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java @@ -0,0 +1,22 @@ +package com.lin.mybatisdubbomysql.service; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.lin.mybatisdubbomysql.PlusMybatisDubboMysqlApplicationTests; +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; + +public class OrderInfoTest extends PlusMybatisDubboMysqlApplicationTests { + + @Resource + OrderInfoService orderService; + + @Test + public void addOrderInfo() { + OrderInfo orderInfo = new OrderInfo(); + orderInfo.setOrderId("2345678dfghj"); + orderInfo.setUserId(12); + orderService.save(orderInfo); + } +} diff --git a/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2cf5e8faef8a9dd18d92c7b82778768f8e0952e4 --- /dev/null +++ b/plusmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java @@ -0,0 +1,23 @@ +package com.lin.mybatisdubbomysql.service; + + +import com.lin.mybatisdubbomysql.PlusMybatisDubboMysqlApplicationTests; +import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; +import org.junit.jupiter.api.Test; + +import javax.annotation.Resource; + +public class UserTest extends PlusMybatisDubboMysqlApplicationTests { + + @Resource + UserService userService; + + @Test + public void userSaveTest() { + User user = new User(); + user.setUsername("linqiankun"); + user.setMobile("14729291172"); + userService.save(user); + } + +} diff --git a/pom.xml b/pom.xml index 26dfdcf2d605962ebb726f0744a938b8825ad55e..fba860101590ac26c402f971967796146073445a 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,8 @@ staticmybatisdubbomysql + dynamicmybatisdubbomysql + plusmybatisdubbomysql @@ -27,29 +29,35 @@ 8 1.8 8.0.22 - 3.3.2 + 3.3.1 2.1.4 - 1.1.6 + 1.1.10 2.3.7.RELEASE 1.18.16 + + org.springframework.boot + spring-boot-starter-web + ${spring.version} + + + org.springframework.boot + spring-boot-starter-aop + ${spring.version} + + org.mybatis.spring.boot mybatis-spring-boot-starter ${mybatis-spring.version} - - mysql - mysql-connector-java - ${mysql.version} - com.alibaba - druid + druid-spring-boot-starter ${druid.version} @@ -57,11 +65,21 @@ mybatis-plus-boot-starter ${mybatis-plus.version} + + com.baomidou + dynamic-datasource-spring-boot-starter + ${mybatis-plus.version} + com.baomidou mybatis-plus-generator ${mybatis-plus.version} + + mysql + mysql-connector-java + ${mysql.version} + org.apache.velocity velocity-engine-core diff --git a/staticmybatisdubbomysql/pom.xml b/staticmybatisdubbomysql/pom.xml index c692fa6e2f4bacb7e22153bb9ba02d675f0677a6..276ec36c5bbee719a14f69b32dc160f503c9bf95 100644 --- a/staticmybatisdubbomysql/pom.xml +++ b/staticmybatisdubbomysql/pom.xml @@ -12,6 +12,10 @@ staticmybatisdubbomysql + + org.springframework.boot + spring-boot-starter-web + org.mybatis.spring.boot mybatis-spring-boot-starter @@ -22,7 +26,7 @@ com.alibaba - druid + druid-spring-boot-starter com.baomidou diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplication.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..3623bc8a3903ec7c66b02162d96d52b3d93f04c0 --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplication.java @@ -0,0 +1,22 @@ +package com.lin.mybatisdubbomysql; + +import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * @author 九分石人 + */ +@EnableTransactionManagement +@ComponentScan(basePackages = "com.lin.mybatisdubbomysql.*") +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class}) +public class StaticMybatisDubboMysqlApplication { + + public static void main(String[] args) { + SpringApplication.run(StaticMybatisDubboMysqlApplication.class, args); + } + +} diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseOneConfig.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseOneConfig.java index 04cb326d3313d30648a93885cb6ff979e0d54092..67dd06495d1f29c5f4c5261a81975dd24fa5a86c 100644 --- a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseOneConfig.java +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseOneConfig.java @@ -8,10 +8,12 @@ import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.annotation.Resource; import javax.sql.DataSource; @@ -53,4 +55,10 @@ public class DatabaseOneConfig { public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactoryOne")SqlSessionFactory sqlSessionFactory){ return new SqlSessionTemplate(sqlSessionFactory); } + + @Bean("Txone") + @Primary + public DataSourceTransactionManager dataSourceTransactionManager(@Qualifier("dataSourceOne") DataSource dataSource){ + return new DataSourceTransactionManager(dataSource); + } } diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseTwoConfig.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseTwoConfig.java index 719826ccdafcc9247a1e4953db3cd1a026e896d1..19081537cda7ed7f38b2c1819db69f3e987fab0c 100644 --- a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseTwoConfig.java +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DatabaseTwoConfig.java @@ -11,6 +11,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.annotation.Resource; import javax.sql.DataSource; @@ -50,4 +51,9 @@ public class DatabaseTwoConfig { return new SqlSessionTemplate(sqlSessionFactory); } + @Bean("Txtwo") + public DataSourceTransactionManager dataSourceTransactionManager(@Qualifier("dataSourceTwo") DataSource dataSource){ + return new DataSourceTransactionManager(dataSource); + } + } diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3738657e22716028a5af0fc5374466b69f74af65 --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/config/DruidConfig.java @@ -0,0 +1,48 @@ +package com.lin.mybatisdubbomysql.config; + +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +/** + * @author 九分石人 + */ +@Configuration +public class DruidConfig { + /** + * 主要实现WEB监控的配置处理 + */ + @Bean + public ServletRegistrationBean druidServlet() { + // 现在要进行druid监控的配置处理操作 + ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>( + new StatViewServlet(), "/druid/*"); + // 白名单,多个用逗号分割, 如果allow没有配置或者为空,则允许所有访问 + servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); + // 黑名单,多个用逗号分割 (共同存在时,deny优先于allow) + servletRegistrationBean.addInitParameter("deny", "192.168.1.110"); + // 控制台管理用户名 + servletRegistrationBean.addInitParameter("loginUsername", "admin"); + // 控制台管理密码 + servletRegistrationBean.addInitParameter("loginPassword", "admin"); + // 是否可以重置数据源,禁用HTML页面上的“Reset All”功能 + servletRegistrationBean.addInitParameter("resetEnable", "false"); + return servletRegistrationBean; + } + + @Bean + public FilterRegistrationBean filterRegistrationBean() { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>(); + filterRegistrationBean.setFilter(new WebStatFilter()); + //所有请求进行监控处理 + filterRegistrationBean.addUrlPatterns("/*"); + //添加不需要忽略的格式信息 + filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.css,/druid/*"); + return filterRegistrationBean; + } + +} \ No newline at end of file diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..79eef03b85b54aaae053afd18642940bd12fa2c7 --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/bean/databasetwo/OrderInfo.java @@ -0,0 +1,36 @@ +package com.lin.mybatisdubbomysql.dal.bean.databasetwo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("order_info") +public class OrderInfo implements Serializable { + + private static final long serialVersionUID=1L; + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + private String orderId; + + private Integer userId; + + private LocalDateTime createTime; + + +} diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..a90d4e43b943e21cb529f6534aa670f027ce90b1 --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/dal/mapper/databasetwo/OrderInfoMapper.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.dal.mapper.databasetwo; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoMapper extends BaseMapper { + +} diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java new file mode 100644 index 0000000000000000000000000000000000000000..df071c13a9e746221bd98f21d3266eb3f5d99e8a --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/OrderInfoService.java @@ -0,0 +1,16 @@ +package com.lin.mybatisdubbomysql.service; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +public interface OrderInfoService extends IService { + +} diff --git a/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..a4f0fd37e3239a4d4f6bb1281e420331298c895b --- /dev/null +++ b/staticmybatisdubbomysql/src/main/java/com/lin/mybatisdubbomysql/service/impl/OrderInfoServiceImpl.java @@ -0,0 +1,20 @@ +package com.lin.mybatisdubbomysql.service.impl; + +import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; +import com.lin.mybatisdubbomysql.dal.mapper.databasetwo.OrderInfoMapper; +import com.lin.mybatisdubbomysql.service.OrderInfoService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 九分石人 + * @since 2021-03-11 + */ +@Service +public class OrderInfoServiceImpl extends ServiceImpl implements OrderInfoService { + +} diff --git a/staticmybatisdubbomysql/src/main/resources/application.yml b/staticmybatisdubbomysql/src/main/resources/application.yml index 2fc3acc1ef75ed025ad89d777d097bdc5e2bda30..8a99d464b678a992c6bdd43d499e455fc25a2988 100644 --- a/staticmybatisdubbomysql/src/main/resources/application.yml +++ b/staticmybatisdubbomysql/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: application: - name: ebwcrm + name: staticmybatisdubbomysql datasourceone: jdbc-url: jdbc:mysql://localhost:3306/mybatisdubboone?serverTimezone=GMT driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/staticmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml b/staticmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..62023eb9d9bc26eb8d6d38a0e3fb150bffb67e05 --- /dev/null +++ b/staticmybatisdubbomysql/src/main/resources/mapper/databasetwo/OrderInfoMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplicationTests.java b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplicationTests.java similarity index 68% rename from staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplicationTests.java rename to staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplicationTests.java index c0e0a7fd05206640ff264e1daff7cfc3a3554f94..ec90a7f39c89474f079fbd6b602c8e2ef862e2d8 100644 --- a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticmybatisdubbomysqlApplicationTests.java +++ b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/StaticMybatisDubboMysqlApplicationTests.java @@ -3,6 +3,6 @@ package com.lin.mybatisdubbomysql; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -public class StaticmybatisdubbomysqlApplicationTests { +public class StaticMybatisDubboMysqlApplicationTests { } diff --git a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java index df8b9f015c1827e3dbcecc050f07aa4e751b4268..c0e4a1324b0c4f68c59df789500ac4e14084fdf9 100644 --- a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java +++ b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseOneCodeGenerator.java @@ -86,7 +86,7 @@ public class DatabaseOneCodeGenerator { .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig().setParent(PACKAGE) -// .setController("controller") + .setController("") .setEntity("dal.bean.databaseone") .setMapper("dal.mapper.databaseone") .setService("service") diff --git a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java index fe7070f072ff20c5b08e0fc5e6e1c18e106193bc..cf436325f6141b710cf8314438222e4da7179d6c 100644 --- a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java +++ b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/mybatisplus/DatabaseTwoCodeGenerator.java @@ -86,7 +86,7 @@ public class DatabaseTwoCodeGenerator { .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig().setParent(PACKAGE) -// .setController("controller") + .setController("") .setEntity("dal.bean.databasetwo") .setMapper("dal.mapper.databasetwo") .setService("service") diff --git a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java index 80c6e5b97907e77de7ee90cf0f2a1c7d8f16c5a6..c4cf870890ab7c34461851c27a941badee2191a5 100644 --- a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java +++ b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/OrderInfoTest.java @@ -1,12 +1,12 @@ package com.lin.mybatisdubbomysql.service; -import com.lin.mybatisdubbomysql.StaticmybatisdubbomysqlApplicationTests; +import com.lin.mybatisdubbomysql.StaticMybatisDubboMysqlApplicationTests; import com.lin.mybatisdubbomysql.dal.bean.databasetwo.OrderInfo; import org.junit.jupiter.api.Test; import javax.annotation.Resource; -public class OrderInfoTest extends StaticmybatisdubbomysqlApplicationTests { +public class OrderInfoTest extends StaticMybatisDubboMysqlApplicationTests { @Resource OrderInfoService orderService; diff --git a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java index d52eaee95fd39532b0ba749ba3f858caf107c100..d83846de140b3df655115bba17109ff59718c016 100644 --- a/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java +++ b/staticmybatisdubbomysql/src/test/java/com/lin/mybatisdubbomysql/service/UserTest.java @@ -1,13 +1,13 @@ package com.lin.mybatisdubbomysql.service; -import com.lin.mybatisdubbomysql.StaticmybatisdubbomysqlApplicationTests; +import com.lin.mybatisdubbomysql.StaticMybatisDubboMysqlApplicationTests; import com.lin.mybatisdubbomysql.dal.bean.databaseone.User; import org.junit.jupiter.api.Test; import javax.annotation.Resource; -public class UserTest extends StaticmybatisdubbomysqlApplicationTests { +public class UserTest extends StaticMybatisDubboMysqlApplicationTests { @Resource UserService userService;