我想知道这个配方是不是在View或Dozer工作中使用Open Session(场景是spring,jsf,hibernate应用程序):
我在后端模块中有这个:
public abstract class AbstractMap<E extends Serializable> implements Mapper<E> {
public abstract E map(E e) ;
public List<E> map(List<E> l) {
List<E> map = new ArrayList<E>();
for (E t : l) {
map.add(this.map(t));
}
return map;
}
}
@Component
public class PersonService extends AbstractService<Person>{
@Autowired
PersonDAO personDao;
@Transacted
public List<Person> findPeople(Mapper<Person> m, PersonFilter filter) {
return m.map(personDao.findByFilter(filter));
}
}
在前端我有这个jsb bean:
@Component
@Scope("session")
public class PersonBean {
@Autowired
PersonService personService;
PersonFilter personFilter;
List<Person> getPeople() {
return personService.findPeople(new AbstractMap<People>() {
public Person map(Person person) {
Person dto = new Person();
dto.setName(person.getName());
dto.setAddresses(new AbstractMap<Address>() {
public Address map(Address a) {
Address dto = new Address();
dto.setStreet(a.getStreet());
return dto;
}
}.map(person.getAddresses()));
return dto;
}
}, personFilter);
}
}
从我的观点来看有一些优点:
可能导致此建议解决方案的问题是什么?