---
title: "无意中发现ibatis中ResultMap也处理了无setter的private字段"
author: "Jamsa"
date: "2011-01-13T12:57:59Z"
tags: []
categories: ["编程语言"]
slug: "ibatis-resultmap-setter-private"
draft: false
lastmod: "2011-01-13T12:57:59Z"
id: 870189
url: "https://jamsa.iteye.com/blog/870189"
---

在用scala写的ibatis程序中使用case类作映射对象的时候，发现即使没有使用scala.reflect.BeanProperty注释来让编译器产生getter setter，在ibatis中查询的时数据库字段值也能映射到对象字段上去。

 

case class User(var id:Int,var userName:String){

  def this()=this(-1,"aaa")

}

 

查阅ibatis源码发现，原来com.ibatis.common.beans.ClassInfo中，ibatis对不能访问的字段都使用了field.setAccessible(true)