问题
I am currently creating a Vaadin app that is supposed to get it's content data from a mysql database on a server (e.g. server run with Xampp). The problem is I am confused with a direction that most information sources give me. Every single tutorial has spring and spring boot code and there is no actual reference to creating a connection with data base in vaadin. I read a lot about the matter but still all that comes up are spring backends with some vaadin UI elements. Does it mean that Vaadin app uses spring components for connection with data base and updating, showing, editing the data using vaadin UI forms etc? I'm really confused right now. So then what is the difference between creating app in Vaadin or spring/spring boot if the back-end is still created in spring no matter what?
回答1:
Vaadin does not take any decisions about how the data is accessed. If you are using spring-boot then creating data source according to their documentation would be a good place to start.
Now you are set to create entities and repositories. You can then edit and display entities in Vaadin application. Some recommend creating separate classes for editing and viewing while others don't.
Each Vaadin page that you have could, for example, have injected repository which it uses to load entities that it will then present to the user.
回答2:
As Mika said, Vaadin does not decide your CMS connection. I recommend using Vaadin and hibernate since you can use dataproviders and hibernate criteria for easy filtering of data.
EDIT: Code-Example (really just an example) I recommend you read about Hibernate and DataProviders yourself
public class EntityDataProvider extends AbstractDataProvider<Entity, Filter> implements DataProvider<CarePiDevice, String> {
private static final long serialVersionUID = 7331161527158310247L;
private SessionFactory sessionFactory;
public EntityDataProvider() {
Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
}
@Override
public boolean isInMemory() {
return false;
}
@Override
public int size(@Nullable Query<Entity, Filter> query) {
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Entity.class);
Filter filter = query.getFilter();
// apply filters to Criteria
return criteria.list().size();
}
@Override
public Stream<CarePiDevice> fetch(@Nullable Query<Entity, Filter> query) {
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Entity.class);
Filter filter = query.getFilter();
// apply filters to Criteria
return criteria.list().stream();
}
}
来源:https://stackoverflow.com/questions/47490002/vaadin-app-with-mysql-database