Merge pull request #10544 from sk1418/springdatajdbc

using query method
This commit is contained in:
Eric Martin 2021-03-13 14:07:43 -06:00 committed by GitHub
commit 2bfeafd169
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);
}