티스토리 뷰
* 환경
HIbernate 5
* Entity
개체 이름 NlpSys, 테이블명 nlp_sys
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name ="nlp_sys")
public class NlpSys {
@Id
@Column
public String k;
@Column
public String v;
public NlpSys() {
}
public String getK() {
return k;
}
public void setK(String k) {
this.k = k;
}
public String getV() {
return v;
}
public void setV(String v) {
this.v = v;
}
}
* Dao
package com.cidog.nlp;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.cidog.nlp.model.NlpSys;
@Repository
public class HomeDao {
public HomeDao() {
}
@Autowired
SessionFactory sf;
public SessionFactory getSf() {
return sf;
}
public void setSf(SessionFactory sf) {
this.sf = sf;
}
public List<NlpSys> getAllNlpSys() {
Session s= sf.openSession();
List lst = s.createQuery("from NlpSys").list();
s.close();
return lst;
}
}
* Service
package com.cidog.nlp;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cidog.nlp.model.NlpSys;
@Service
public class HomeService {
@Autowired
HomeDao dao;
public List<NlpSys> findAllNs() {
List lst = dao.getAllNlpSys();
System.out.println("찾은 개체 : " + lst.size());
System.out.println(lst);
return lst;
}
}
'SW개발 > Spring Framework' 카테고리의 다른 글
mysql connector - MySQL 호환성 (0) | 2018.05.11 |
---|---|
Hibernate 설정 과정 (0) | 2018.05.03 |
Ubuntu / Eclipse, Srping, Hibernate 개발환경 설정 (0) | 2018.05.03 |
Hibernate] MariaDB 연결 (0) | 2018.04.25 |
Unknown initial character set index '255' received from server (2) | 2018.04.25 |