控制台报错: java.lang.NoSuchMethodException:tk.mybatis.mapper.provider.base.BaseSelectProvider.<init>() 浏览器访问:http://localhost:8081/category/list?pid=0 解决办法: 应该导入import tk.mybatis.spring.annotation.MapperScan这个包。 from:https://blog.csdn.net/qq_37495786/article/details/83448614
View Details使用Mybatis的开发者,大多数都会遇到一个问题,就是要写大量的SQL在xml文件中,除了特殊的业务逻辑SQL之外,还有大量结构类似的增删改查SQL。而且,当数据库表结构改动时,对应的所有SQL以及实体类都需要更改。这工作量和效率的影响或许就是区别增删改查程序员和真正程序员的屏障。这时,通用Mapper便应运而生……
View DetailsUnsigned Fields MySql supports both signed, and unsigned, numeric fields. These are not JDBC types, so MyBatis generator cannot automatically account for these types of fields. The Java data types are always signed. This can lead to a loss of precision when using unsigned fields. The solution is to provide a <columnOverride> for any unsigned numeric field in MySql. Here is an example of how to deal with an unsigned bigint field in MySql:
1 2 3 |
<table tableName="ALLTYPES" > <columnOverride column="UNSIGNED_BIGINT_FIELD" javaType="java.lang.Object" jdbcType="LONG" /> </table> |
You will have to cast the returned value to the appropriate type yourself (in this […]
View Details错误日志:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Exception in thread "main" java.lang.NoClassDefFoundError: org/mybatis/generator/api/dom/xml/Element at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.mybatis.generator.internal.ObjectFactory.internalClassForName(ObjectFactory.java:144) at org.mybatis.generator.internal.ObjectFactory.createInternalObject(ObjectFactory.java:180) at org.mybatis.generator.internal.ObjectFactory.createCommentGenerator(ObjectFactory.java:241) at org.mybatis.generator.config.Context.getCommentGenerator(Context.java:266) at org.mybatis.generator.codegen.mybatis3.model.SimpleModelGenerator.getCompilationUnits(SimpleModelGenerator.java:51) at org.mybatis.generator.codegen.mybatis3.IntrospectedTableMyBatis3Impl.getGeneratedJavaFiles(IntrospectedTableMyBatis3Impl.java:181) at org.mybatis.generator.config.Context.generateFiles(Context.java:460) at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:262) at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:132) at com.weChat.MybatisStartup.GeneratorDisplay.generator(GeneratorDisplay.java:33) at com.weChat.MybatisStartup.GeneratorDisplay.main(GeneratorDisplay.java:17) Caused by: java.lang.ClassNotFoundException: org.mybatis.generator.api.dom.xml.Element at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 13 more |
原因及其解决办法: 错误日志中很明显的说是 mybatis 的代码自动生成依赖 generator 的 api 存在问题,查看 pom.xml 文件的依赖,发现引用是正常的,也就是说引用和使用都不可能有问题,因为我并没有直接操作 generator 的 api ,那么只可能是版本的问题了,而我的这个依赖的版本是 1.4.0 ,是目前最高的版本: 所以只有可能是我的版本太高了,下降一个版本试试,换成1.3.7的果然就好了!看来做这个不能写的太满,不然很容易给自己埋雷啊! from:https://www.cnblogs.com/90s-ITBoy/p/13388452.html
View Details在 Intellij IDEA 中结合 Gradle 使用 MyBatis Generator 逆向生成代码 Info: JDK 1.8 Gradle 2.14 Intellij IDEA 2016.3 前言 由于 IDEA 的教程较少,且 MyBatis Generator 不支持 Gradle 直接运行,因此这次是在自己折腾项目过程中,根据一些参考资料加上自己的实践得出的结论,并附上相应的 Demo 可供自己未来参考,也与大家分享。 本文的 Demo 也可以当作工具直接导入 IDEA,加上自己的数据库信息即可生成代码。 创建项目 详细的创建步骤可以参考使用 Gradle 构建 Struts 2 Web 应用中「新建 Gradle Web 项目」一节即可。当创建完毕,需要等待 Gradle 联网构建,由于国内网络因素,可能需要稍作等待。当构建完成,目录结构应如下图一致: Gradle 构建完成 配置依赖 这里需要使用 MyBatis Generator,MySQL 驱动,以及 MyBatis Mapper。由于代码生成单独运行即可,不需要参与到整个项目的编译,因此在 build.gradle 中添加配置:
1 2 3 |
configurations { mybatisGenerator } |
在 Maven Repository (http://mvnrepository.com/) 分别搜索依赖: org.mybatis.generator mysql-connector-java tk.mybatis:mapper 依赖的版本并不是局限于某个特定版本,可以选择适时相应的更新版本。添加到 build.gradle 的 dependencies 中(注意前面需将「compile group:」改为 「mybatisGenerator」):
1 2 3 4 5 6 7 |
dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.5' mybatisGenerator 'mysql:mysql-connector-java:5.1.40' mybatisGenerator 'tk.mybatis:mapper:3.3.9' } |
设置数据库信息 在 resources 下,新建 mybatis 文件夹,并新建 config.properties 和 generatorConfig.xml,文件结构如下: 配置文件目录 在 config.properties 中配置数据库和要生成的 […]
View Details今天写东西测试的时候发现一个问题,如下: application.yml中数据源是这样配置的: 第一反应就是记忆中连接mysql的驱动不都是com.mysql.jdbc.Driver吗?com.mysql.cj.jdbc.Driver是什么鬼? 后来查看了一下才知道 这个跟驱动的依赖版本有关
1 2 3 4 5 |
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> |
com.mysql.cj.jdbc.Driver是mysql-connector-java 6 中的特性,相比mysql-connector-java 5 多了一个时区:serverTimezone,把数据源配置的驱动改一下就好了 这样启动就不会再报:Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 使用UTC会有8小时的时差(中国快全球标准8小时,比如:全球标准当前是上午1点,中国时间则为上午9点),可设置为北京时间东八区GMT%2B8 或者上海时间Asia/Shanghai。 总结: com.mysql.jdbc.Driver和mysql-connector-java 5一起用。 com.mysql.cj.jdbc.Driver和mysql-connector-java 6 一起用。 from:https://blog.csdn.net/weixin_43770545/article/details/90486809
View Details1、在win10桌面编写test.gradle脚本,里面内容如下
1 2 3 |
task helloword << { println 'Hello gradle qick start' } |
2、在doc命令窗口执行脚本
1 |
gradle -q helloword |
结果如下: 3、解决办法 查看为gradle 5.0中 << 已经过时了,即(<<),是推荐使用doLast 来替代的,可以通过降低gradle版本(比如4.10.1)或者使用doLast解决 重新修改脚本如下,执行后正常输出’Hello gradle qick start
1 2 3 |
task helloword { println 'Hello gradle qick start' } |
或者
1 2 3 4 5 |
task helloword { doLast{ println 'Hello gradle qick start' } } |
人要耐得住寂寞,才能守得住繁华。人生最痛苦的就是拿不起放不下,不属于自己的快乐,及时放手也许是一种解脱,生活中没有谁对谁错,只有适不适合。当发现很多已经改变,更要面对的是事实。 from:https://www.cnblogs.com/yuanchaoyong/p/11421595.html
View Details