using query method

This commit is contained in:
Kent@lhind.hp.g5 2021-03-10 11:28:43 +01:00
parent ce6f1e878e
commit a83d25884e
2 changed files with 5 additions and 8 deletions

View File

@ -50,7 +50,7 @@ public class Application implements CommandLineRunner {
LOGGER.info("@@ findByFirstName() call...");
repository.findByFirstName("Franz")
.forEach(person -> LOGGER.info(person.toString()));
LOGGER.info("@@ findByFirstName() call...");
LOGGER.info("@@ updateByFirstName() call...");
repository.updateByFirstName(2L, "Date Inferno");
repository.findAll()
.forEach(person -> LOGGER.info(person.toString()));

View File

@ -1,23 +1,20 @@
package com.baeldung.springdatajdbcintro.repository;
import java.util.List;
import com.baeldung.springdatajdbcintro.entity.Person;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.baeldung.springdatajdbcintro.entity.Person;
import java.util.List;
@Repository
public interface PersonRepository extends CrudRepository<Person,Long> {
public interface PersonRepository extends CrudRepository<Person, Long> {
@Query("select * from person where first_name=:firstName")
List<Person> findByFirstName(@Param("firstName") String firstName);
List<Person> findByFirstName(String firstName);
@Modifying
@Query("UPDATE person SET first_name = :name WHERE id = :id")
boolean updateByFirstName(@Param("id") Long id, @Param("name") String name);
}