发表于: 2017-03-18 21:22:10
1 1439
今天完成的任务:
配置好了mybatis,用mybatis进行数据库的增删改查。
package com.ptteng.test;
import java.util.List;
import com.ptteng.domain.Student;
import com.ptteng.mapping.StudentMapper_11;
import com.ptteng.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
public class AppTest3
{
public void testAdd()
{
SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
StudentMapper_11 mapper = sqlSession.getMapper(StudentMapper_11.class);
Student student = new Student();
student.setName("大智若愚");
student.setAge(20);
int add = mapper.add(student);
sqlSession.close();
System.out.println(add);
}
public void testUpdate()
{
SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
StudentMapper_11 mapper = sqlSession.getMapper(StudentMapper_11.class);
Student student = new Student();
student.setId(3);
student.setName("大音希声");
student.setAge(26);
int retResult = mapper.update(student);
sqlSession.close();
System.out.println(retResult);
}
public void testDelete()
{
SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
StudentMapper_11 mapper = sqlSession.getMapper(StudentMapper_11.class);
int retResult = mapper.deleteById(7);
sqlSession.close();
System.out.println(retResult);
}
public void testGetStudent()
{
SqlSession sqlSession = MyBatisUtil.getSqlSession();
StudentMapper_11 mapper = sqlSession.getMapper(StudentMapper_11.class);
Student student = mapper.getById(1);
sqlSession.close();
System.out.println(student);
}
public void testGetAll()
{
SqlSession sqlSession = MyBatisUtil.getSqlSession();
StudentMapper_11 mapper = sqlSession.getMapper(StudentMapper_11.class);
List<Student> lstStudent = mapper.getAll();
sqlSession.close();
System.out.println(lstStudent);
}
}
明天的计划:
学习spring+spring-MVC+mabatis(SSM框架).
遇到的问题:
感觉自己零基础做任务确实有压力,老是要回补翻书,希望能好好坚持下去。
收获:
因为有.xml文件的配置和mapper的使用。对代码理解有点吃力。今天总算是能看懂一部分了。加油!有点慢,老大别骂我!
评论