更新:
public void Testupdate() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
Student student = new Student();
student.setStuid(1);
student.setStuname(“lan”);
student.setStuage(22);
int rows = studentMapper.updateById(student);
System.out.println(“成功更新”+rows+“条数据”);
}
删除:
where id = ?
public void Testdelete() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
int rows = studentMapper.deleteById(1);
System.out.println(“成功更新”+rows+“条数据”);
}
where id in( ???)
public void Testdelete2() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
List list = new ArrayList();
list.add(1);
list.add(2);
int rows = studentMapper.deleteBatchIds(list);
System.out.println(“成功更新”+rows+“条数据”);
}
where ? =?
public void Testdelete3() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
Map<String, Object> map = new HashMap<String, Object>();
map.put(“stuname”, “chen”);
int rows = studentMapper.deleteByMap(map);
System.out.println(“成功更新”+rows+“条数据”);
}
加入
public void Testinsert() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
Student student = new Student();
student.setStuid(99);
student.setStuname(“fish”);
student.setStuage(100);
int rows = studentMapper.insert(student);
System.out.println(“成功更新”+rows+“条数据”);
}
查询
where id = ?
public void Testselect() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
Student student= studentMapper.selectById(1);
System.out.println(student.getStuage());
}
where id in(???)
public void Testselect2() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
List list = new ArrayList();
list.add(1);
list.add(2);
List student = studentMapper.selectBatchIds(list);
System.out.println(student);
}
where ? =?
public void Testselect3() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
StudentMapper studentMapper = (StudentMapper)context.getBean(“studentMapper”);
Map<String, Object> map = new HashMap<String, Object>();
map.put(“stuname”, “chen”);
List student = studentMapper.selectByMap(map);
System.out.println(student);
}