Search code examples
javamybatismybatis-generatormybatis-mapper

is there any way to force mybatis to use setter


I need to do some logic before the value is set from the db with mybatis, however, my list field always has size=0

enter image description here

i really need help, if someone knows please help me, I'm so appreciative


Solution

  • MyBatis is calling your setter. But it works differently than you might be thinking.

    This is the way it works - MyBatis will create an empty list and set it in your POJO. Then, for each row, MyBatis will call getRoleList().add() to fill out the list row by row. MyBatis does not create an internal list of values and then call setRoleList() with a fully populated list.

    It is best to use MyBatis objects as simple POJOs. Any other processing should be completed after the objects are returned from MyBatis.