List list1 = repository.findByNameLike("%ko");SampleEntity [id=2, name=hanako, mail=hanako@flower.uk]
SampleEntity [id=4, name=sachiko, mail=sachico@happy.com]List list2 = repository.findByMailEndingWith(".com");SampleEntity [id=1, name=tuyano, mail=syoda@tuyano.com]
SampleEntity [id=4, name=sachiko, mail=sachico@happy.com]※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
// ********************
// ※App.java
// ********************
package com.tuyano.libro.db;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
private static EntityManager manager;
public static void main(String[] args) {
//ApplicationContext app = new
AnnotationConfigApplicationContext(SampleEntityConfig.class);
ApplicationContext app = new ClassPathXmlApplicationContext("dbbean.xml");
EntityManagerFactory factory = app.getBean(EntityManagerFactory.class);
manager = factory.createEntityManager();
makeDummyData();
// get repository
SampleEntityRepository repository = app.getBean(SampleEntityRepository.class);
// get list
List list1 = repository.findByNameLike("%ko");
System.out.println("*Find By Name*");
printList(list1);
List list2 = repository.findByMailEndingWith(".com");
System.out.println("*Find By Mail*");
printList(list2);
System.out.println("...ok.");
}
// create dummy entity data.
public static void makeDummyData() {
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
manager.persist(new SampleEntity("tuyano", "syoda@tuyano.com"));
manager.persist(new SampleEntity("hanako", "hanako@flower.uk"));
manager.persist(new SampleEntity("taro", "taro@yamada.jp"));
manager.persist(new SampleEntity("sachiko", "sachico@happy.com"));
manager.flush();
transaction.commit();
}
// print all entity.
public static void printList(List list) { 略 }
}
| << 前へ | 次へ >> |