package Com.Book.Dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.Map;
public interface ITeacherDao {
//查询老师的数量
@Select(" select count(*) from teacher")
int getTeacher();
//查询编号为10的老师的姓名
@Select("select teacherName from teacher where id=#{id}")
String getteacherNameId(@Param("id") int id);
//查询所有的书籍信息
@Select(" select * from teacher")
List
package Com.Book.Test;
import Com.Book.Dao.ITeacherDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TwoTest {
public SqlSession ss = null;
public ITeacherDao dao = null;
public void init() {
try {
InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
ss = new SqlSessionFactoryBuilder().build(is).openSession();
dao = ss.getMapper(ITeacherDao.class);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getTeacherNum() {
init();
int count = dao.getTeacher();
System.out.println("查询到老师的数量为" + count + "位");
}
@Test
public void getteacherNameId() {
init();
String teacherName=dao.getteacherNameId(6);
System.out.println("查询到老师的名称为"+teacherName);
}
@Test
public void getTeacherAll(){
init();
List> teachers=dao.getTeacherAll();
teachers.forEach(map -> System.out.println(map));
}
@Test
public void getTeacherinfo(){
init();
Map map=dao.getTeacherinfo("王一飞",45);
System.out.println(map);
}
@Test
public void getTeacher2(){
init();
Map map=dao.getTeacher2("只想一辈子");
System.out.println(map);
}
@Test
public void getTeacherLimit(){
init();
List> maps=dao.getTeacherLimit(1,4);
System.out.println("测试数据一");
maps.forEach(map -> System.out.println(map));
}
@Test
public void getTeacherLimit1(){
init();
List> maps=dao.getTeacherLimit(6,10);
System.out.println("测试数据二");
maps.forEach(map -> System.out.println(map));
}
@Test
public void addTeacher() {
init();
Map map = new HashMap<>();
map.put("teacherNumber", "BiLL_2022034013");
map.put("teacherName", "项目");
map.put("teacherAge", 23);
map.put("teacherSex", "女");
map.put("teacherId", "345789200310980987");
map.put("teacherClass", "24级软件三班");
map.put("teacherPhone", "12345678976");
map.put("teacherAddress", "上饶市区中心");
ss.commit();
int i=dao.addTeacher(map);
if(i>0){
System.out.println("恭喜用户成功增加一条用户的数据信息");
}
}
}