发表于: 2019-11-01 23:48:26

1 955


今天完成的事情:


今天把剩下的

spring+mybatis增删查改写完


接口文件    增加了部分参数值 

@Repository
public interface StudentMapper {

public Student selectStudentId(int id );

public List<Student> selectStudent();

public void insertStudent(Student student);

public void  deleteStudentId(int id);

public void updateStudent(Student student);


public class AppTest {

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
   StudentMapper studentMapper = (StudentMapper) applicationContext.getBean("mapperFactoryBean");
   @Test
   public void selectStudentId() throws Exception {
Student student = studentMapper.selectStudentId(6);
       System.out.println(student);
   }
@Test
   public void selectStudent() throws Exception {
List<Student> list = studentMapper.selectStudent();
       System.out.println(list);
   }
@Test
   public void insertStudent() throws Exception {
Student student = new Student();
       student.setName("郑和");
       student.setqq(55552211);
       student.setType("后端");
       student.settime("22");
       student.setStunum(22555);
       studentMapper.insertStudent(student);
       System.out.println(student);
   }

@Before
   public void deleteStudentSt() throws Exception{
studentMapper.deleteStudentId(21);
   }
@Test
   public void updateStudent() throws  Exception{
Student student = new Student();
       student.setName("刘场");
       student.setId(6);
       studentMapper.updateStudent(student);
       System.out.println(student);
   }
}

并跑了单元测试




买了个阿里云mysql 服务器

但还没有配置


明天计划的事情:


spring+mybtis 整合再看一遍

连接服务器  

推进任务


遇到的问题:

juit4  log4j   只是了解  简单使用

但未深入了解、


spring    mybatis 要再看看


收获:

关于application的配置


mapperLocations 的作用

 当mybatis的xml文件和mapper接口不在相同包下时,需要用mapperLocations属性指定xml文件的路径。
*是个通配符,代表所有的文件,**代表所有目录下 -->

<property name="mapperLocations" value="classpath*:StudentMapper.xml"></property>


mapperInterface 的作用

<!--        mapperInterface指定接口-->
<!--        将接口(interface) 和映射文件(mapper.xml)整合在一起-->

<property name="mapperInterface" value="com.ptteng.mapper.StudentMapper"></property>






返回列表 返回列表
评论

    分享到