Hi,
I am not sure if there is a better solution or not, so maybe you guys have an idea how I can solve this.
When I call something like that:
User user = userMapper.findUser(id);
I get an user object which is a plain and nice POJO populated by MyBatis.
I would like to use this object with some additional logic and would need to inject something to the user object, like:
User user = userMapper.findUser(TimeZone timeZone, id);
In the user object:
class User {
TimeZone timeZone;
// Injection done by constructor
public String formattedDate() {
return this.createdAt.format(timeZone);
}
}
This is just pseudo code, but I hope it makes clear what I want to achieve. What I do now is to iterate through all objects, create new "wrapper" objects containing the additional dependencies and return the wrappers instead.
Of course, this is a lot of overhead and costly with performance. I would love to know if MyBatis could inject these dependencies as well or if there is a better approach I coudl use.
You may have guessed it, I use myBatis with Spring and Annotations.
Thanks!
Christian