我创建了 vaadin 聊天,我需要当任何用户进入聊天时,他应该只看到来自 MySQL 数据库的最后 10 条消息。我认为我的代码执行不正确。因为它显示了前 10 条消息,尽管程序应该显示最后 10 条消息。
我的代码 MainView 类 -
public class MainView extends VerticalLayout {
private final MessagesInfoManager messagesInfoManager;
private final RestService restService;
private String username;
private TextField textField;
private Message messageLast;
@Autowired
public MainView(RestService restService) {
this.messagesInfoManager = MessageConfigurator.getInstance().getChatMessagesInfoManager();
addClassName("main-view");
setSizeFull();
setDefaultHorizontalComponentAlignment(Alignment.CENTER);
H1 header = new H1("Vaadin Chat");
header.getElement().getThemeList().add("dark");
add(header);
askUsername();
this.restService = restService;
}
private void askUsername() {
HorizontalLayout layout = new HorizontalLayout();
TextField usernameField = new TextField();
Button startButton = new …Run Code Online (Sandbox Code Playgroud)