package com.powernode;
import static org.junit.Assert.assertTrue;
import com.powernode.mybatis.mapper.StudentMapper;
import com.powernode.mybatis.pojo.Student;
import com.powernode.mybatis.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AppTest
{
@Test
public void testSimple() throws ParseException {
SqlSession sqlSession = SqlSessionUtil.openSqlSession();
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
// List<Student> students = mapper.selectById(1L);
// List<Student> students = mapper.selectByName("张三");
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// Date birth = sdf.parse("1990-02-01");
// List<Student> students = mapper.selectByBirth(birth);
Character character = Character.valueOf('男');
List<Student> students = mapper.selectBySex(character);
students.forEach(e -> System.out.println(e.toString()));
sqlSession.close();
}
@Test
public void testMap(){
SqlSession sqlSession = SqlSessionUtil.openSqlSession();
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
Map<String,Object> map = new HashMap<>();
map.put("name","小明");
map.put("age",23);
map.put("birth",new Date());
map.put("height",1.7);
map.put("sex","女");
int i = mapper.insertStudentMap(map);
System.out.println(i);
sqlSession.commit();
sqlSession.close();
}
@Test
public void testPojo(){
SqlSession sqlSession = SqlSessionUtil.openSqlSession();
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
Student student = new Student();
student.setName("小猪");
student.setAge(16);
student.setHeight(1.9);
student.setSex('女');
student.setBirth(new Date());
int i = mapper.insertStudentPojo(student);
System.out.println(i);
sqlSession.commit();
sqlSession.close();
}
@Test
public void testParams(){
SqlSession sqlSession = SqlSessionUtil.openSqlSession();
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
List<Student> students = mapper.selectByNameAndSex2("小美", '女');
students.forEach(e-> System.out.println(e.toString()));
sqlSession.close();
}
}