表格列
`start_time` TIMESTAMP NOT NULL COMMENT '秒杀结束时间',
`end_time` TIMESTAMP NOT NULL COMMENT '秒杀结束时间',
`create_time` TIMESTAMP NOT NULL DEFAULT current_timestamp COMMENT '创建时间',
实体(com.hxy.entity.Seckill
)
实体
private Date start_time;
private Date end_time;
private Date create_time;
映射
<select id="queryById" resultType="com.hxy.entity.Seckill" parameterType="long">
SELECT seckill.seckill_id,seckill.name,seckill.number,seckill.start_time,seckill.end_time,seckill.create_time
FROM
seckill.seckill
WHERE seckill_id=#{seckillId}
</select>
DAO
Seckill queryById(long seckillid);
服务
public Exposer exportSecKillUrl(final long seckillid) {
Seckill seckill = seckillDao.queryById(seckillid);
logger.info(seckill.toString());
}
测试
@Test
public void getById() throws Exception {
long id = 1000;
Seckill seckill = secKillService.getById(id);
logger.info("seckill={}", seckill);
}
日志
19:08:34.579 [main] DEBUG o.m.s.t.SpringManagedTransaction -JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@5ef5c734 [wrapping: com.mysql.jdbc.JDBC4Connection@d771cc9]] will not be managed by Spring
19:08:34.586 [main] DEBUG com.hxy.dao.SeckillDao.queryById -==> Preparing: SELECT seckill.seckill_id,seckill.name,seckill.number,seckill.start_time,seckill.end_time,seckill.create_time FROM seckill.seckill WHERE seckill_id=?
19:08:34.620 [main] DEBUG com.hxy.dao.SeckillDao.queryById -==> Parameters: 1000(Long)
19:08:34.709 [main] DEBUG com.hxy.dao.SeckillDao.queryById -<== Total: 1
19:08:34.713 [main] DEBUG org.mybatis.spring.SqlSessionUtils -Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@48793bef]
19:08:34.715 [main] INFO c.hxy.service.impl.SecKilServiceimpl -Seckill{seckillid=1000, name='1000元秒杀ipone6', number=100, start_time=null, end_time=null, create_time=null}
java.lang.NullPointerException
at com.hxy.service.impl.SecKilServiceimpl.exportSecKillUrl(SecKilServiceimpl.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
SQL Directly
SELECT seckill.seckill_id,seckill.name,seckill.number,seckill.start_time,seckill.end_time,seckill.create_time
FROM
seckill.seckill
WHERE seckill_id=1000;
结果
start_time end_time create_time
1000 1000元秒杀ipone6 100 2015-11-01 00:00:00 2015-11-02 00:00:00 2016-06-11 22:05:07