这是主要功能,值已设置为bean。
package demo.sphbIntegrate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args )
{
ApplicationContext context=new ClassPathXmlApplicationContext("sphb.xml");
EmployeeDAO edao=(EmployeeDAO) context.getBean("d");
Employee e=new Employee();
e.setId(1);
e.setName("sourav");
e.setSalary(100000);
edao.saveEmployee(e);
}
}
这是豆类。
package demo.sphbIntegrate;
public class Employee
{
private int id;
private String name;
private int salary;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
这是我的 DAO 课程。
package demo.sphbIntegrate;
import org.springframework.orm.hibernate5.HibernateTemplate;
public class EmployeeDAO
{
HibernateTemplate template;
public void setTemplate(HibernateTemplate template) {
this.template = template;
}
public void saveEmployee(Employee e)
{
template.saveOrUpdate(e);
}
}
根据代码,必须将记录输入到表中。但是,发生了一些奇怪的事情,执行了一个选择查询,这在整个程序中都没有提到。我无法理解这个异常。PS:我确定,我正在运行正确的程序并且所有文件都正确保存,整个包中也没有编写选择查询的代码。
这是输出:
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hibernate: select employee_.ID, employee_.NAME as NAME2_0_, employee_.SALARY as SALARY3_0_ from EMPLOYEE employee_ where employee_.ID=?
慕斯王
相关分类