我在spring mvc项目中使用namedParameterJdbcTemplate和sql脚本 我的时候我从db获得所有来自db的命令我得到了14的结果,但我只有7个写入的插入语句,我尝试做的是干净安装,我从数据脚本中删除了数据,只剩下一个,当我运行我的时候测试它显示两个数据。
@Override
public final Collection<OrderWithTruckCodeDto> getAllOrdersWithTruckCode() {
LOGGER.debug("getAllOrdersWithTruckCode()");
Collection<OrderWithTruckCodeDto> ordersDto = namedParameterJdbcTemplate
.getJdbcOperations()
.query(selectAllWithTruckCodeSql, new OrderWithTruckCodeDtoRowMapper());
return ordersDto;
}
我的scipts看起来像这样
INSERT INTO orderz (petrolQty, orderDate ,truckId )
VALUES (13, '2006-01-21',3);
INSERT INTO orderz (petrolQty , orderDate , TRUCKID )
VALUES (13.0, '2006-1-21', 3);
我的考试
@Test
public void getAllOrderWithTruckCodeDto() {
Collection<OrderWithTruckCodeDto> orders =
orderDao.getAllOrdersWithTruckCode();
Assert.assertFalse(orders.isEmpty());
Assert.assertTrue(orders.size() == 7);
}
我正在使用h2 db,当在h2控制台上尝试这一切时,一切正常
这些是我的疑问
order.selectAllWithTruckCode = SELECT o.orderId, o.orderDate, petrolQty, t.truckCode \
FROM orderz o left join truck t ON (o.truckId = t.truckId) \
group by o.orderId
order.filterByDate = SELECT o.orderId, o.orderDate, petrolQty, t.truckCode \
FROM orderz o left join truck t ON (o.truckId = t.truckId) \
where o.orderDate >= :start and o.orderDate <= :end \
group by o.orderId
答案 0 :(得分:1)
我的创建脚本看起来像这样
CREATE TABLE IF NOT EXISTS orderz (
orderId INT NOT NULL AUTO_INCREMENT,
petrolQty DOUBLE NOT NULL,
orderDate timestamp NOT NULL,
truckId INT,
PRIMARY KEY (orderId),
FOREIGN KEY (truckId) REFERENCES truck(truckId)
ON UPDATE CASCADE
ON DELETE CASCADE
当我改为这个
DROP TABLE IF EXISTS orderz;
CREATE TABLE orderz (
orderId INT NOT NULL AUTO_INCREMENT,
petrolQty DOUBLE NOT NULL,
orderDate timestamp NOT NULL,
truckId INT,
PRIMARY KEY (orderId),
FOREIGN KEY (truckId) REFERENCES truck(truckId)
ON UPDATE CASCADE
ON DELETE CASCADE
);
问题解决了,但我不知道为什么这可能会造成共和党
答案 1 :(得分:0)
可能过滤掉
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
所以你只是执行你在评论中的陈述