Merge pull request #10544 from sk1418/springdatajdbc
using query method
This commit is contained in:
commit
2bfeafd169
@ -50,7 +50,7 @@ public class Application implements CommandLineRunner {
|
|||||||
LOGGER.info("@@ findByFirstName() call...");
|
LOGGER.info("@@ findByFirstName() call...");
|
||||||
repository.findByFirstName("Franz")
|
repository.findByFirstName("Franz")
|
||||||
.forEach(person -> LOGGER.info(person.toString()));
|
.forEach(person -> LOGGER.info(person.toString()));
|
||||||
LOGGER.info("@@ findByFirstName() call...");
|
LOGGER.info("@@ updateByFirstName() call...");
|
||||||
repository.updateByFirstName(2L, "Date Inferno");
|
repository.updateByFirstName(2L, "Date Inferno");
|
||||||
repository.findAll()
|
repository.findAll()
|
||||||
.forEach(person -> LOGGER.info(person.toString()));
|
.forEach(person -> LOGGER.info(person.toString()));
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
package com.baeldung.springdatajdbcintro.repository;
|
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.Modifying;
|
||||||
import org.springframework.data.jdbc.repository.query.Query;
|
import org.springframework.data.jdbc.repository.query.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import com.baeldung.springdatajdbcintro.entity.Person;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@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(String firstName);
|
||||||
List<Person> findByFirstName(@Param("firstName") String firstName);
|
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("UPDATE person SET first_name = :name WHERE id = :id")
|
@Query("UPDATE person SET first_name = :name WHERE id = :id")
|
||||||
boolean updateByFirstName(@Param("id") Long id, @Param("name") String name);
|
boolean updateByFirstName(@Param("id") Long id, @Param("name") String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user