99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

虛擬視圖

2018-10-28 13:09 更新


多表關(guān)聯(lián)常常通過創(chuàng)建數(shù)據(jù)庫視圖的方式來解決,其實也可以使用虛擬視圖,維護更為方便。


表person和表id_card通過外鍵id_card_id關(guān)聯(lián)。


創(chuàng)建虛擬視圖PersonIdCard類:

@Entity
@Immutable
@Subselect("SELECT p.id id, p.name name, p.age age, ic.number number " +
           "FROM person p " +
           "LEFT JOIN id_card ic " +
           "ON p.id_card_id=ic.id")
public class PersonIdCard {
    @Id
    private Long id;
    private String name;
    private Integer age;
    private String number;

    // getter and setter}
數(shù)據(jù)庫訪問PersonIdCardRepository類:

public interface PersonIdCardRepository extends JpaRepository<PersonIdCard, Long>, JpaSpecificationExecutor<PersonIdCard> {
}
查詢年齡大于20的人。
public List<PersonIdCard> findAll(SearchRequest request) {
    Specification<PersonIdCard> specification = new Specifications<PersonIdCard>()
            .gt(Object.nonNull(request.getAge()), "age", 20)
            .build();

    return personRepository.findAll(specification); 
} 

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號