wwz_ henu 2022-02-13 05:19:50 阅读数:344
One .entity Defined on the
1.entity Definition SQL
@Entity
@Table(name = "user", schema = "test", catalog = "")
@NamedQuery(name = "UserEntity.all", query = "select u from UserEntity u ")
public class UserEntity {
private int id;
private String name;
private String email;
2.repository Call in
List<UserEntity> all();
Two .repository In the definition of
1. Non-native SQL- Attention and primordial SQL The difference in writing
@Query("select u from UserEntity u")
List<UserEntity> getAll();
2. Native SQL
@Query(value = "select u.id,u.name,u.email from user u",nativeQuery = true)
List<UserEntity> getAllNative();
3. With parameters SQL- Native / Non-native identical
@Query(value = "select u from UserEntity u where u.name = :name")
List<UserEntity> getByName(@Param("name") String name);
// ?1 Represents the first formal parameter ,?2 Represents the second formal parameter , By analogy
@Query(value = "select u from UserEntity u where u.name = ?1")
List<UserEntity> getByName(String name);
copyright:author[wwz_ henu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130519492329.html