欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring 单元测试之 Dao 层

程序员文章站 2022-04-26 11:18:27
...
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.saiku.dao.SjAdminMapper;
import com.saiku.pojo.SjAdmin;
import com.saiku.pojo.SjAdminExample;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class AdminTestDao {

     @Autowired
     SjAdminMapper sjAdminMapper;
  
     @Test
    public void test_1(){

           SjAdminExample example = new SjAdminExample();
     List<SjAdmin> sjAdmins = sjAdminMapper.selectByExample(example);

        if(null != sjAdmins && sjAdmins.size()>0){
            for(int i=0;i<sjAdmins.size();i++){
                System.out.println("ID号:"+sjAdmins.get(i).getAdminid());
            }
        }
    }
}