简体   繁体   中英

what I want is when I press the initial letter of each name to show me the name with its initial letter

I make a simple database of names. There are a couple of names:(for example) Alexander, Anthony, Amelia, Asher and Matin. And I want to get all names that contains letter "a" but only these which have first letter "a" not Matin because a is the second letter in the word. I have in my repository this method:

@Query(value = "select ID, F_NAME, L_NAME FROM TEACHERS WHERE F_NAME LIKE  %:firstName% ",nativeQuery = true )
List<Teacher>findByFirstname( @Param("firstName") String firstName);

I created an application with a list of professors with spring and when I click on the first letter of the name, the list shows all the names that contain this letter,

what I want is when I press the initial letter of each name to show me the name with its initial letter

I think in your case you should delete the first % and make your code like this:

@Query(value = "SELECT ID, F_NAME, L_NAME FROM TEACHERS WHERE F_NAME LIKE :firstName%", nativeQuery = true)
List<Teacher> findByFirstname(@Param("firstName") String firstName);

Then, you can call the method and pass in the letter you want to search for as a parameter, like this:

List<Teacher> teachers = findByFirstname("a");

This will return a list of all teachers whose first names start with the letter "a".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM