spring配置
<bean id="nutzDao" class="org.nutz.dao.impl.NutDao">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!-- 配置注解 -->
<context:component-scan base-package="com.hcr" />
java代码
package com.hcr.dao.impl;
import javax.annotation.Resource;
import org.nutz.dao.impl.NutDao;
import com.hcr.dao.StaffDao;
import com.hcr.vo.Staff;
//@Repository("staffdao")
public class StaffDaoImpl implements StaffDao{
@Resource
private NutDao nutzDao;
@Override
public Staff getByName(String name) {
return nutzDao.fetch(Staff.class,name);
}
@Override
public void insert(Staff staff) {
nutzDao.insert(staff);
}
}
测试
package com.hcr.test;
import org.junit.Test;
import com.hcr.dao.StaffDao;
import com.hcr.dao.impl.StaffDaoImpl;
import com.hcr.vo.Staff;
public class NuteTest {
@Test
public void test_insert() {
StaffDao staffDao = new StaffDaoImpl();
Staff staff = new Staff("zhangcc", "123456", "java", 1);
staffDao.insert(staff);
}
}