1>传统方式实现dao层
- 1、在dao包中创建一个包叫作impl,impl创建一个StudentDao实现类,并复写它的方法
package com.bjpowernode.dao.impl;
import com.bjpowernode.dao.StudentDao;
import com.bjpowernode.domain.Student;
import com.bjpowernode.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import java.util.List;
public class StudentDaoImpl implements StudentDao {
@Override
public List<Student> selectStudents() {
SqlSession session = MyBatisUtil.getSession();
String sqlId ="com.bjpowernode.dao.StudentDao.selectStudents";
List<Student> list = session.selectList(sqlId);
return list;
}
}
package com.bjpowernode.dao.impl;
import com.bjpowernode.dao.StudentDao;
import com.bjpowernode.domain.Student;
import com.bjpowernode.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import java.util.List;
public class StudentDaoImpl implements StudentDao {
@Override
public List<Student> selectStudents() {
SqlSession session = MyBatisUtil.getSession();