黔程似锦 2022-11-12 14:22 采纳率: 50%
浏览 10

数据层接收不到另一个表数据,空指针异常

springboot项目sql语句在数据库查询都正常,用vo表接收两个表的联合查询的数据用来页面展示,第二个表的参数无法传进vo表中,空指针异常,xml文件的sql语句拿进数据库查询正常,这是什么导致的
debug图片

img


错误异常

img

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<GoodsVo> getGoods() {
        List<Goods> goodsList = goodsMapper.selectAll();
        List<GoodsVo> 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<SeckillGoods> getSeckill(){
        List<SeckillGoods> 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<GoodsVo> goodsList =goodsService.getGoods();
        model.addAttribute("goodsList",goodsList);
        return "list";
  • 写回答

1条回答 默认 最新

  • WaitIKnowYou 2022-11-12 14:34
    关注

    img


    这里不是null吧?

    评论

报告相同问题?

问题事件

  • 创建了问题 11月12日

悬赏问题

  • ¥15 github录制项目
  • ¥15 H.264选择性加密例程
  • ¥50 windows的SFTP服务器如何能批量同步用户信息?
  • ¥15 centos7.9升级python3.0的问题
  • ¥15 如何解决调试dev-出++5.11不成功问题
  • ¥15 安装CentOS6时卡住
  • ¥20 关于#监控系统#的问题,如何解决?(相关搜索:系统软件)
  • ¥20 c语言写的8051单片机存储器mt29的模块程序
  • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
  • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。