我有一个编辑弹出窗口。在我的代码中,我使用的是 String Builder 。我用 append 表示 '.' . 我的消息以“。”结尾。即点。如何使用“\n”让我的消息出现在下一行?我试过 historyMessage.append("\n"),historyMessage.append("\n") 和 historyMessage.append("\r\n"); 但这对我不起作用。任何人都可以请查看我的代码并在我错的地方提供帮助。
private String historyMessage(HdiGdvHistory hdiGdvHistory, String messageType) {
StringBuilder historyMessage = new StringBuilder();
HdiGdv gdv = hdiGdvDAO.getById(hdiGdvHistory.getHdiGdvId());
hdiGdvHistoryList = hdiGdvHistoryDAO.getByIds(gdv.getId());
if("approved".equals(messageType) || "rejected".equals(messageType)){
historyMessage.append("User "+hdiGdvHistory.getUser().getFirstName() +" has "+messageType);
}
if(hdiGdvHistoryList==null || hdiGdvHistoryList.isEmpty()){
if(!gdv.getHouseNumber().equals(hdiGdvHistory.getHouseNumber())){
historyMessage.append(getHistoryMessage(hdiGdvHistory, "House Number" ,gdv.getHouseNumber(),hdiGdvHistory.getHouseNumber()));
historyMessage.append(". ");
}
}else{
hdiGdvHistoryList = hdiGdvHistoryDAO.getByFilteredIds(gdv.getId());
System.out.println("list "+hdiGdvHistoryList.size());
hdiGdvHistoryList = hdiGdvHistoryDAO.getByIds(gdv.getId());
for (HdiGdvHistory history : hdiGdvHistoryList) {
if(!hdiGdvHistory.getHouseNumber().equals(history.getHouseNumber())){
historyMessage.append(getHistoryMessage(hdiGdvHistory, "House Number" ,history.getHouseNumber(),hdiGdvHistory.getHouseNumber()));
historyMessage.append(". ");
break;
}
}
}
if(hdiGdvHistoryList==null || hdiGdvHistoryList.isEmpty()){
if(!gdv.getCity().equals(hdiGdvHistory.getCity())){
historyMessage.append(getHistoryMessage(hdiGdvHistory, "City" ,gdv.getCity(),hdiGdvHistory.getCity()));
historyMessage.append(". ");
}
}else{
for (HdiGdvHistory history : hdiGdvHistoryList) {
if(!hdiGdvHistory.getCity().equals(history.getCity())){
historyMessage.append(getHistoryMessage(hdiGdvHistory, "City" ,history.getCity(),hdiGdvHistory.getCity()));
historyMessage.append(". ");
break;
}
}
}
hdiGdvHistoryList.clear();
gdv=new HdiGdv();
hdiGdvHistory = new HdiGdvHistory();
return historyMessage.toString();
}
private String getHistoryMessage(HdiGdvHistory hdiGdvHistory, String values , String preFieldValue ,String fieldValues ) {
return "User "+hdiGdvHistory.getUser().getFirstName() +" has updated " +values+ " "+preFieldValue +" to "+fieldValues;
}