springboot项目sql语句在数据库查询都正常,用vo表接收两个表的联合查询的数据用来页面展示,第二个表的参数无法传进vo表中,空指针异常,xml文件的sql语句拿进数据库查询正常,这是什么导致的
debug图片
service实现类
package com.test.service.impl;
import com.test.mapper.GoodsMapper;
import com.test.mapper.SeckillGoodsMapper;
import com.test.model.Goods;
import com.test.model.SeckillGoods;
import com.test.service.GoodsService;
import com.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private SeckillGoodsMapper seckillGoodsMapper;
@Override
public List getGoods() {
List goodsList = goodsMapper.selectAll();
List result = new ArrayList<>();
for (Goods goods : goodsList) {
SeckillGoods seckillGoods=seckillGoodsMapper.getSecGoodsById(goods.getGoodsId());
GoodsVo vo=new GoodsVo();
vo.setGoodsId(goods.getGoodsId());
vo.setGoodsName(goods.getGoodsName());
vo.setGoodsType(goods.getGoodsType());
vo.setPrice(goods.getPrice());
vo.setImgPath(goods.getImgPath());
vo.setPrice(seckillGoods.getSeckillPrice());
vo.setStockNum(seckillGoods.getStockNum());
result.add(vo);
}
return result;
}
public List getSeckill(){
List list = seckillGoodsMapper.selectAll();
return list;
}
}
controller层
package com.test.controller;
import com.test.model.SeckillGoods;
import com.test.service.GoodsService;
import com.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Controller
//@RestController
public class GoodsController {
@Autowired
private GoodsService goodsService;
@RequestMapping("/")
public String list(Model model){
List goodsList =goodsService.getGoods();
model.addAttribute("goodsList",goodsList);
return "list";