fix findBy multiple results
This commit is contained in:
@@ -4,13 +4,13 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.champonthis</groupId>
|
<groupId>de.champonthis</groupId>
|
||||||
<artifactId>abi</artifactId>
|
<artifactId>abi</artifactId>
|
||||||
<version>0.2.6</version>
|
<version>0.2.7</version>
|
||||||
<name>abi</name>
|
<name>abi</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.5.6</version>
|
<version>3.5.7</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class ContactManager {
|
|||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (StringUtils.isNoneEmpty(line) && !line.startsWith("#")
|
if (StringUtils.isNoneEmpty(line) && !line.startsWith("#")
|
||||||
&& contactRepository.findByName(line).isEmpty()) {
|
&& contactRepository.findFirstByName(line).isEmpty()) {
|
||||||
Contact contact = new Contact();
|
Contact contact = new Contact();
|
||||||
String[] nameParts = line.split(";");
|
String[] nameParts = line.split(";");
|
||||||
contact.setName(nameParts[0]);
|
contact.setName(nameParts[0]);
|
||||||
@@ -75,7 +75,7 @@ public class ContactManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Contact findByName(String name) {
|
public Contact findByName(String name) {
|
||||||
return contactRepository.findByName(name).orElse(null);
|
return contactRepository.findFirstByName(name).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact findByToken(String token) {
|
public Contact findByToken(String token) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import de.champonthis.abi.entity.Contact;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface ContactRepository extends JpaRepository<Contact, Long> {
|
public interface ContactRepository extends JpaRepository<Contact, Long> {
|
||||||
|
|
||||||
Optional<Contact> findByName(String name);
|
Optional<Contact> findFirstByName(String name);
|
||||||
|
|
||||||
Optional<Contact> findByToken(String token);
|
Optional<Contact> findByToken(String token);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user