BeanUtils.setProperty()可以设置没有setter的值吗?

时间:2017-08-11 18:11:46

标签: java apache-commons-beanutils

我目前正在here举例,将我的public class APIOperationsManager { private static APIOperationsManager instance = null; private Vector<Operation> operations; private int currentOperationId; private static final Logger log = LoggerFactory.getLogger(Application.class); protected APIOperationsManager() {} public static APIOperationsManager getInstance() { if(instance == null) { synchronized(APIOperationsManager.class) { if(instance == null) { instance = new APIOperationsManager(); instance.operations = new Vector<Operation>(); instance.currentOperationId = 1; } } } return instance; } public synchronized int registerNewOperation(OpStatus status) { cleanOperationsList(); currentOperationId = currentOperationId + 1; Operation newOperation = new Operation(currentOperationId, status); operations.add(newOperation); log.info("Registered new Operation to watch: " + newOperation.toString()); return newOperation.getId(); } public synchronized Operation getOperation(int id) { for(Iterator<Operation> iterator = operations.iterator(); iterator.hasNext();) { Operation op = iterator.next(); if(op.getId() == id) { return op; } } Operation notFound = new Operation(-1, OpStatus.INTERNAL_ERROR); notFound.setCrated(null); return notFound; } public synchronized void updateOperationStatus (int id, OpStatus newStatus) { iteration : for(Iterator<Operation> iterator = operations.iterator(); iterator.hasNext();) { Operation op = iterator.next(); if(op.getId() == id) { op.setStatus(newStatus); log.info("Updated Operation status: " + op.toString()); break iteration; } } } public synchronized void updateOperationMessage (int id, String message) { iteration : for(Iterator<Operation> iterator = operations.iterator(); iterator.hasNext();) { Operation op = iterator.next(); if(op.getId() == id) { op.setMessage(message); log.info("Updated Operation status: " + op.toString()); break iteration; } } } private synchronized void cleanOperationsList() { Date now = new Date(); for(Iterator<Operation> iterator = operations.iterator(); iterator.hasNext();) { Operation op = iterator.next(); if((now.getTime() - op.getCrated().getTime()) >= Constants.MIN_HOLD_DURATION_OPERATIONS ) { log.info("Removed operation from watchlist: " + op.toString()); iterator.remove(); } } } } 映射到自定义ResultSet。我已经测试了Object,看起来该对象需要setter才能工作。有没有办法像BeanUtils.setProperty()那样映射值?我不想拥有公共制定者。

0 个答案:

没有答案