🎨
application-framework
  • Introduction
  • 设计模式篇
    • 设计原则
      • 单一职责原则
      • 里氏替换原则
      • 依赖倒置原则
      • 接口隔离原则
      • 迪米特法则
      • 开闭原则
    • 代理模式
    • 工厂模式
    • 策略模式
    • 等等..设计模式
    • 常用设计模式在开源软件的应用
    • Template设计模式介绍
  • SpringBoot篇
    • SpringBoot官方教程结构图
    • SpringBoot启动过程源码分析
    • SpringBoot启动过程定制化
    • SpringBoot实现自动配置的基础
    • SpringBoot实现自动配置的原理
    • SpringBoot启动类源码分析以及@EnableAutoConfiguration和@SpringBootApplication讲解
    • EnableAutoConfigurationImportSelector 是如何工作的 ?
    • ConfigurationClassParser 是如何工作的 ?
    • SpringBoot源码分析之Spring上下文refresh(重点)
    • SpringBoot中的ApplicationContext - 执行ApplicationContextInitializer初始化器
    • SpringBoot常用配置-Profile
    • Spring Boot API 版本权限控制
  • Mybatis篇
    • Mybatis基础教程
    • Mybatis-Spring基础教程
    • Sqlsession原理
    • Mybatis代码架构分析
    • Mybatis事务
    • Mybatis与Spring集成事务相关问题
    • 结果/参数绑定
    • Mybatis插件拓展/插件原理
    • Mybatis 使用Ehcache缓存机制//自带缓存与Spring结合使用
    • 使用代码生成器快速开发
    • Mybatis使用时的一些注意事项
    • Mybatis配置打印SQL语句
    • 持久层框架mybatis如何防止sql注入
    • SqlSessionTemplate与SqlSessionDaoSupport讲解
    • MapperFactoryBean与MapperScannerConfigurer讲解
    • Spring+MyBatis多数据源配置实现
    • Mybatis与Spring集成事务相关问题
  • Spring源码解读篇
    • Spring 架构图
    • Spring核心结构及组件分析
    • Spring5 Framework体系结构
    • Spring源码剖析
      • BeanFactory
      • BeanPostProcessor源码讲解
      • BeanFactoryPostProcessor源码讲解
      • BeanDefinition源码解析
      • RootBeanDefinition源码解析
      • AnnotatedBeanDefinition源码解析
      • ApplicationContext源码讲解
      • IoC容器的初始化?
      • @Configuration源码讲解
      • Bean的注解(annotation)
      • @ImportSelector、@Import、ImportResource工作原理分析
      • Bean的生命周期
    • IOC机制从设计理念/实现原理到源码解读
    • AOP实现原理
      • aop编程思想
      • aop在Spring中的应用
      • cglib和jdk动态代理
        • java/jdk代理实现与原理详细分析
        • cglib实现动态代理
    • Transaction事务处理源码分析及高级特性
      • 事务概念
      • Spring事务传播
      • 事务隔离级别
      • 事务实现源码分析
      • Spring事物应用实战(一)
      • Spring事务应用实战(二)之spring+hibernate+JTA 分布式事务的例子
    • SpringMVC源码解读
      • DispatcherServlet说明
      • 核心流程剖析及原理分析
      • 请求映射机制
      • 参数绑定与转换机制
      • 页面渲染机制
      • ContextLoader加载过程
      • web.xml 中的listener、 filter、servlet 加载顺序及其详解
      • Spring中WebApplicationContext、DispatcherServlet与web容器的ServletContext关系梳理
    • Spring新版本特性解读
  • JPA篇
    • 简单叙述
    • 基础教程
    • SpringData Jpa、Hibernate、Jpa 三者之间的关系
    • Spring data jpa 全面解析
    • 数据库schema含义
    • 数据库schema与catalog简介
    • Jpa关联映射以及字段映射注解讲解
      • @Entity、@Table、@id
      • @GeneratedValue
      • @Basic、@Column、@Transient
      • @MappedSuperclass、@Embedded、@OrderBy、@Lob、@Data
      • @OneToOne级联配置
      • @OneToMany、@ManyToOne级联配置
      • 更新的同时删除多的一方的旧数据
      • cascade级联属性讲解
      • JpaSpecificationExecutor接口
      • @Query 创建查询
      • @NamedQueries创建查询
      • @CreateDate @LastModifiedDate @EntityListeners、@SQLDelete、@Where
      • 注解关联时报错总结
      • JPA 多对多关联 中间表带有属性 两个外键作为中间表的联合主键时 直接操作中间表查询修改的方法
    • Jpa 使用@Query查询时 (参数可能为空)语句
    • Jpa校验/验证注解
      • Jpa的list校验方式
      • Jpa的基础校验/验证注解
  • Hibernate篇
    • Hibernate基础教程
    • Hibernate主键生成策略
    • Hibernate的体系结构
    • Hibernate面试题
    • 自定义一个方言类——Hibernate Dialect
    • Hibernate 不同数据库的连接及SQL方言
    • Hibernate中一级缓存和二级缓存的具体区别是什么?
    • Hibernate中,对象有三种状态:
Powered by GitBook
On this page

Was this helpful?

  1. Mybatis篇

Mybatis使用时的一些注意事项

1.Mybatis 使用foreach 时,in 里的参数如果多个是字符串的话,代码不需要加单引号,mybatis应该会自动加,否则查询不出

2.There is no getter for property named ‘XXX’ in ‘class java.lang.String’解决办法

示例1:

传入参数为‘parentCategoryId’,运行报错为:There is no getter for property named 'parentCategoryId' in 'class java.lang.String

<select id="selectCategoryList" parameterType="java.lang.String" resultType="MstCategoryBean">
SELECT
  category_id AS categoryId,
  category_name AS categoryName,
  view_orderby AS viewOrderby
FROM
  mst_category
WHERE
  del_flg =0
<if test="parentCategoryId!=null and parentCategoryId!=''">
 and
 parent_category_id = #{parentCategoryId}
</if>
</select>


发现不能将参数设为bean里的名称,如果传入类型为String类型,则参数需统一修改为[_parameter],修改后的sql语句如下(不管你的参数是什么,都要改成"_parameter")


<select id="selectCategoryList" parametertype="java.lang.String" resulttype="MstCategoryBean">
SELECT
  category_id AS categoryId,
  category_name AS categoryName,
  view_orderby AS viewOrderby
FROM
  mst_category
WHERE
  del_flg =0
  and
  parent_category_id = #{_parameter}
</select>

示例2:

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报


There is no getter for property named 'moduleCode' in 'class java.lang.String
 错误写法:


<select id="queryAllParentModule" resultType="jobModule" parameterType="jobModule">
select 
  modulecode,
  modulename,
  modulevalue,
  linkurl,
  rank,
  parentmodule=isnull(parentmodule,1),
  moduledescription
from job_module
<where>
<choose>
<when test="moduleCode!=null and moduleCode!=''">modulecode = #{moduleCode}</when>
<when test="moduleCode==null or moduleCode==''">(parentmodule is null or len(parentmodule)&lt;=0)</when>
</choose>
</where>
lt;/select>
 需要修改成:


<select id="queryModuleByCode" resultType="jobModule" parameterType="string">
select modulecode,
modulename,
modulevalue,
linkurl,
rank,
parentmodule=isnull(parentmodule,1),
moduledescription
from job_module
<where>
<choose>
<when test="_parameter!=null and _parameter!=''">modulecode = #{_parameter}</when>
<when test="_parameter==null or _parameter==''">(parentmodule is null or len(parentmodule)&lt;=0)</when>
</choose>
</where>
</select>
 不管你的参数是什么,都要改成"_parameter";

3.Error parsing Mapper XML IllegalArgumentException: Mapped Statements collection already contains value for .......

目前知道有三个原因:

  • parameterMap改成parameterType...

  • id 重复

  • parameterType参数有问题

  • mapper.xml中没有加入namespace

  • mapper.xml中的方法和接口mapper的方法不对应

  • mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),例外:配置了mapper文件的包路径的除外

  • mapper.xml文件名和所写的mapper名称不相同。

4.org.apache.ibatis.executor.statement.StatementHandler.prepare(java.sql.Connection)

出现此错误的原因是MyBatis 3.4.0 之后,StatementHandler的prepare方法做了修改,如下

Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException;

解决办法:

  • 在args = { Connection.class }中添加第二个参数,即:

@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class,Integer.class }) })
  • 降低MyBatis版本号。

Previous使用代码生成器快速开发NextMybatis配置打印SQL语句

Last updated 5 years ago

Was this helpful?