为什在测试successSeckill的时候查出来的是null,前面测试insert已经成功数据库也有相应的字段

来源:4-9 DAO层单元测试编码和问题排查(下)

qq_Ve_14

2016-12-07 13:29

测试类-----------------------

@Test

public void testInsertSuccessKilled() {

long userPhone = 13550922395L;

long seckillId = 9998L;

int count =  successKillDao.insertSuccessKilled(seckillId, userPhone);

System.out.println("count = " + count);

}


@Test

public void testQueryByIdWithSecKill() {

long userPhone = 13550922395L;

long seckillId = 9998L;

SuccessKilled successSeckill = successKillDao.queryByIdWithSecKill(seckillId, userPhone);

System.out.println(successSeckill);

}

----------------------------控制台输出

13:21:49.178 [main] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@19932c16] will not be managed by Spring

13:21:49.265 [main] DEBUG c.s.d.S.queryByIdWithSecKill - ==>  Preparing: select sk.seckill_id, sk.user_phone, sk.create_time, s.seckill_id "seckill.seckill_id", s.name "seckill.name", s.number "seckill.number", s.start_time "seckill.start_time", s.end_time "seckill.end_time", s.create_time "seckill.create_time" from success_killed sk inner join seckill s on sk.seckill_id = s.seckill_id where sk.seckill_id=? and sk.user_phone = ? 

13:21:49.457 [main] DEBUG c.s.d.S.queryByIdWithSecKill - ==> Parameters: 9998(Long), 13550922395(Long)

13:21:49.601 [main] DEBUG c.s.d.S.queryByIdWithSecKill - <==      Total: 0

13:21:49.616 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@53fb3dab]

null

-----------------------------sql

<select id="queryByIdWithSecKill" resultType="SuccessKilled">

<!-- 根据查询successKilled同时并携带seckill实体 -->

<!-- 如果告诉mybatis把结果集映射到seccessKilled同时映射到seckill属性 -->

<!-- 可以自由控制SQL -->

select 

sk.seckill_id,

sk.user_phone,

sk.create_time,

s.seckill_id "seckill.seckill_id",

s.name "seckill.name",

s.number "seckill.number",

s.start_time "seckill.start_time",

s.end_time "seckill.end_time",

s.create_time "seckill.create_time"

from success_killed sk

inner join seckill s on sk.seckill_id = s.seckill_id

where sk.seckill_id=#{seckillId} and sk.user_phone = #{userPhone}

</select>

------------------求解啊

写回答 关注

1回答

  • qq_Ve_14
    2016-12-07 13:35:52

    因为在seckill里面的seckillId没有9998

Java高并发秒杀API之业务分析与DAO层

Java实现高并发秒杀API的第一门课,还等什么,赶快来加入吧

87426 学习 · 496 问题

查看课程

相似问题