这是我的问题,给出了这段代码:
studentOutcomeService.getAll()
.get(getStudentOutcomeByID(
selectedStudentOutcome.getId().intValue()))
.setDescription(description);
studentOutcomeService.getAll()
.get(getStudentOutcomeByID(
selectedStudentOutcome.getId().intValue()))
.setSequenceNumber(Integer.valueOf(sequenceNumber));
studentOutcomeService.getAll()
.get(getStudentOutcomeByID(
selectedStudentOutcome.getId().intValue()))
.setShortName(shortName);
studentOutcomeService.getAll()
.get(getStudentOutcomeByID(
selectedStudentOutcome.getId().intValue()))
.setIdentifier(identifier);
我不满意这样一个事实,即我要查询数据库4次以不断更新字段。
我修改了一个StudentOutcome对象,并存储了那里找到的对象,然后修改了我创建的对象,但似乎在创建一个新对象时,尽管设置为等于数据库中找到的对象,使用= ,operator,对新StudentOutcome对象所做的更改不适用于最初设置的等于。
如何才能提高效率?我知道有更好的方法。
答案 0 :(得分:0)
尝试
StudentOutcome toUpdate = studentOutcomeService.getAll().get(
getStudentOutcomeByID(selectedStudentOutcome.getId()));
toUpdate.setDescription(description);
toUpdate.setSequenceNumber(Integer.valueOf(sequenceNumber));
toUpdate.setShortName(shortName);
toUpdate.setIdentifier(identifier);
甚至只是
StudentOutcome toUpdate = getStudentOutcomeByID(selectedStudentOutcome.getId());
toUpdate.setDescription(description);
toUpdate.setSequenceNumber(Integer.valueOf(sequenceNumber));
toUpdate.setShortName(shortName);
toUpdate.setIdentifier(identifier);