JPA查询

Pojo: UserDetails

EntityManager: entityManager

1. Ceate Criteria

CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserDetails> criteria = builder.createQuery(UserDetails.class);

Create Criteria

2. Compose SQL

1) table

Root<UserDetails> userDetailsTable = criteria.from(UserDetails.class);

From

2) Condition

Path<UserDetails> uId = userDetailsTable.get("userId");
Predicate condition = builder.equal(uId, userId);
criteria.where(condition);

Condition

3. result

return entityManager.createQuery(criteria).getSingleResult();

Result

上一篇:oracle 参考


下一篇:win下Maven安装和基本设置