• SpringData关键字查询练习


    我们在上一节知道SpringData关键字有很多,我就拿几个例子练练手

    1.需求我们查询lastName like sun and id < ?的查询

    package com.fxr.springdata;
    
    import java.util.List;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    
    
    public interface PersonRepsotory extends JpaRepository<Person,Integer>{
    
    	//根据lastName来获取对应的Person
    	Person getByLastName(String lastName);
    	
    	//我们来试着写一个查询laskName like 'sun' and id < ?的方法
    	List<Person> getByLastNameStartingWithAndIdLessThan(String lastName,Integer id);
    	
    }
    

    2.需求我们查询WHERE lastName LIKE %? AND id < ?

    package com.fxr.springdata;
    
    import java.util.List;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    
    
    public interface PersonRepsotory extends JpaRepository<Person,Integer>{
    
    	//根据lastName来获取对应的Person
    	Person getByLastName(String lastName);
    	
    	//我们来试着写一个查询laskName like 'sun' and id < ?的方法
    	List<Person> getByLastNameStartingWithAndIdLessThan(String lastName,Integer id);
    	
    	
    	//WHERE lastName LIKE %? AND id > ?
    	List<Person> getByLastNameEndingWithAndIdGreaterThan(String lastName,Integer id);
    	
    }
    

      好了,对着我们上一节那个关键字的表,你可以写出符合你的查询的逻辑语句,如果我们在项目中遇见业务特别复杂的查询的话,我们需要自己写SQL,这个怎么实现,我们会在以后的章节中讲到,嘿嘿·········

  • 相关阅读:
    [SUCTF 2019]Pythonginx
    Buuctf-RSA1
    [网鼎杯 2020 朱雀组]phpweb
    [BJDCTF2020]ZJCTF,不过如此
    CTFHub-信息泄露
    vaex读取和处理大型文件的方法
    "生猪数据统计分析系统"----帮助文档
    法治理论1
    很短暂,很喜欢,很遗憾
    「CF1513E Cost Equilibrium」
  • 原文地址:https://www.cnblogs.com/airycode/p/6535475.html
Copyright © 2020-2023  润新知