ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]>

本文介绍在XML映射文件中如何使用CDATA元素来避免特殊字符如>&等被解析,通过示例展示如何正确书写包含比较运算符的表达式。

转自:http://blog.youkuaiyun.com/xiaofengxiaoling/article/details/12850515

因为这个是xml格式的,所以不允许出现类似“>”这样的字符,但是都可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析 
你的可以写成这个: 

mapper文件示例代码<![CDATA[ when min(starttime)<='12:00' and max(endtime)<='12:00' ]]>   

    &lt;          < 
    &gt;          >  
    &lt;&gt;   <>
    &amp;      & 
    &apos;      '
    &quot;      "

 

实例:

select  to_date(to_char(tf.created_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') from t_ff_rt_workitem tf
where to_date(to_char(tf.created_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')<=to_date(to_char('2012-05-19','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')

错误:ORA-01722:无效数字

select  to_date(to_char(tf.created_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') from t_ff_rt_workitem tf
where to_date(to_char(tf.created_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')<=to_date('2012-05-19','yyyy-mm-dd hh24:mi:ss')

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>wjdc</artifactId> <version>0.0.1-SNAPSHOT</version> <name>wjdc</name> <description>wjdc</description> <properties> <java.version>17</java.version> </properties> <dependencies> <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- MySQL 驱动 --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <!-- 原生 MyBatis 依赖(适配 Spring 3.x) --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.3</version> <!-- 最新版适配 Spring 3.x --> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.7</version> </dependency> <!-- Lombok 依赖 --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- 测试依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- MyBatis 代码生成器核心依赖 --> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.1</version> </dependency> </dependencies> <build> <plugins> <!-- MyBatis 代码生成器 Maven 插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.4.1</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <!-- 数据库驱动依赖(生成器需要) --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>9.2.0</version> <!-- 与项目驱动版本一致 --> </dependency> </dependencies> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>报错Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2025-07-05T21:12:00.447+08:00 ERROR 10268 --- [wjdc] [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.parse(MybatisMapperAnnotationBuilder.java:122) The following method did not exist: 'void org.apache.ibatis.session.Configuration.parsePendingMethods(boolean)' The calling method's class, com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder, was loaded from the following location: jar:file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/com/baomidou/mybatis-plus-core/3.5.7/mybatis-plus-core-3.5.7.jar!/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.class The called method's class, org.apache.ibatis.session.Configuration, is available from the following locations: jar:file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar!/org/apache/ibatis/session/Configuration.class The called method's class hierarchy was loaded from the following locations: org.apache.ibatis.session.Configuration: file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder and org.apache.ibatis.session.Configuration
最新发布
07-06
### 问题分析 在 Spring Boot 3.5.3 环境中,使用 MyBatis-Plus 3.5.7 可能会遇到 `Configuration.parsePendingMethods(boolean)` 方法不存在的问题。此异常通常与 MyBatis 核心库的版本不兼容有关。 MyBatis-Plus 3.5.7 要求底层依赖的 MyBatis 版本为 3.5.10 或更高[^2]。如果项目中手动引入了旧版本的 MyBatis(如 3.5.2),则会导致运行时方法缺失错误。这是因为旧版 MyBatis 的 `org.apache.ibatis.session.Configuration` 类未包含 `parsePendingMethods` 方法,该方法是在后续版本中新增的功能。 ### 解决方案 确保项目的依赖管理中正确指定以下版本: #### Maven 配置示例 ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.7</version> </dependency> <!-- 显式声明 MyBatis 主版本以避免冲突 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.10</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.0.6</version> </dependency> ``` 通过上述配置,可确保 MyBatis-Plus 3.5.7 所需的底层 API 完整可用,从而避免 `parsePendingMethods` 方法缺失问题。 ### 注意事项 若项目中存在自定义 MyBatis 配置文件或 XML Mapper 文件,应检查其是否引用了过时的命名空间或类路径。Spring Boot 3.x 已全面迁移至 `jakarta.*` 包名,因此需要更新所有相关注解和导入语句,例如将 `javax.annotation.Resource` 替换为 `jakarta.annotation.Resource`。 此外,对于数据库方言、分页插件等高级功能,建议启用 `MybatisPlusInterceptor` 并注册 `PaginationInnerInterceptor` 插件以保证兼容性: ```java @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } ``` 最后,确认主应用类已正确配置 Mapper 扫描路径: ```java @SpringBootApplication @MapperScan("com.example.mapper") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值