jpa 原生insert\delete\update\select語句

來源:互聯網
上載者:User

jpa 原生insert的sql語句:

    @Modifying    @Query(value = "insert into t_sys_org_user(org_id,user_id) values(?1,?2)",nativeQuery = true)    int addUserToOrg(Long orgId,Long userId);

jpa 原生delete的sql語句:

 @Modifying    @Query(value = "delete from t_sys_org_user where org_id=?1 and user_id=?2",nativeQuery = true)    int deleteUserFromOrg(Long orgId,Long userId);

jpa 原生update的sql語句:

@Modifying    @Query(value = "update t_sys_user set status=0 where user_id=?1",nativeQuery = true)    int updateUserStatus(Long userId);

jpa 原生select的sql語句:

//jpa 多對多關係的表聯集查詢 DAO層@Query(value = "select s from SysUserDTO s left join s.sysOrgDTOSet o where (?1 is null or s.username like ?1) and (?2 is null or o.name like ?2)")    Page<SysUserDTO> findByUsernameAndOrgName(String username, String orgName, Pageable pageable);// service層public Page<SysUserDTO> findByUsernameAndOrgName(String username, String orgName, Pageable pageable){        String name = (username==null)?null:"%"+username+"%";        String orgname = (orgName==null)?null:"%"+orgName+"%";        return sysUserDAO.findByUsernameAndOrgName(name,orgname,pageable);    }

jpa hql中使用in關鍵字

@Query(value = "select distinct r from SysRoleDTO r left join r.sysOrgDTOSet o where (?1 is null or r.name like ?1) "+           "and (?2 is null or r.code like ?2) and o.id in (?3)")    Page<SysRoleDTO> findAllRole(String name, String code, List<Long> ids, Pageable pageable);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.