zoukankan      html  css  js  c++  java
  • [Java Spring data] @Query @Param

    package com.example.university.repo;
    
    import com.example.university.domain.Staff;
    import com.example.university.domain.Student;
    import com.example.university.view.CourseView;
    import com.example.university.domain.Course;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.Pageable;
    import org.springframework.data.jpa.repository.Query;
    import org.springframework.data.repository.CrudRepository;
    import org.springframework.data.repository.query.Param;
    
    import java.util.List;
    
    /**
     * DataSource Management for the Courses at the University.
     *
     * Created by maryellenbowman
     */
    public interface CourseRepository extends CrudRepository<Course,Integer>{
    
        Course findByName(String name);
    
        List<Course> findByDepartmentChairMemberLastName(String chair);
        // or
        @Query("Select c from Course c where c.department.chair.member.lastName=:chair")
        List<Course> findByChairLastName(@Param("chair")String chairLastName);
        // or
        @Query("Select c from Course c where c.department.chair.member.lastname = ?1")
        List<Course> findByChairLastName(String chairLastName);
    
        @Query("Select c from Course c join c.prerequisites p where p.id = ?1")
        List<Course> findCourseByPrerequisite(int id);
    
        @Query("Select new com.example.university.view.CourseView" +
                "(c.name, c.instructor.member.lastName, c.department.name) from Course c where c.id=?1")
        CourseView getCourseView(int courseId) ;
    
        List<Course> findByCredits(@Param("credits") int credits);
    
        Page<Course> findByCredits(@Param("credits") int credits, Pageable pageable);
    
    //      Common Querying Mistake
    //      Uncomment to Debug.
    //
    //    Course findByDeptName(String deptName);
    //
    //    @Query("Select new com.example.university.view.CourseView" +
    //            "(c.name, c.instructor.member.lastName, c.department.name) from course c where c.name=?1")
    //    Course getCourseViewByName(String name);
    
    }
    

      

  • 相关阅读:
    J2EE之ANT
    lsof在运维中的应用
    Qt编译OpenGL程序遇到的问题
    算法导论第八章__实现计数排序
    MYSQL 更新时间自己主动同步与创建时间默认值共存问题
    微软系统工具套件SysinternalsSuite各个工具功能说明
    【转】如何查看linux版本 如何查看LINUX是多少位
    【转】linux下解压.bz2压缩文件
    【转】db/dbm
    【转】BLE_CC2540_初学者入门指导
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14153045.html
Copyright © 2011-2022 走看看