zoukankan      html  css  js  c++  java
  • springtest+juint开发测试如下:

     项目结构目录如下:

    UserMapper.java 为接口文件。User 为实体类。UserMapper.xml 为对应mybatis的xml文件。test为对应的测试包

    applicationtest.xml文件为对于的spring配置文件的。db.propertise 为数据库配置。log4j是对应的日志文件

    UserDao为操作数据库的类

    public class UserDao extends SqlSessionDaoSupport implements UserMapper {

    @Autowired(required=true)
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
    super.setSqlSessionFactory(sqlSessionFactory);
    }

    public User selectByPrimaryKey(Integer userid) {
    UserMapper sqlSession = (UserMapper) getSqlSession().getMapper(UserMapper.class);
    return sqlSession.selectByPrimaryKey(1);
    }

    }

    UserDaoTest类


    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = "classpath:applicationtest.xml")
    public class UserDaoTest extends AbstractJUnit4SpringContextTests {
    public UserDao userDao;

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Test
    public void test1(){
    User user = userDao.selectByPrimaryKey(1);
    System.out.println(user);
    logger.info("111111111111111111");
    }

    public UserDao getUserDao() {
    return userDao;
    }

    @Autowired
    public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
    }

    }

  • 相关阅读:
    k8s nod rc service 使用
    Linux $() 与 ${}
    Linux set
    Linux 上传下载 rz 与sz
    Linux !的使用
    K8s创建pod yaml文件详解
    Kubernetes 安装
    Python 生成器
    k8s 使用详解
    微信 网页授权
  • 原文地址:https://www.cnblogs.com/zxf330301/p/6015680.html
Copyright © 2011-2022 走看看