在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ blackInfoDao.selectBlackByCjid為什么報空指針?

blackInfoDao.selectBlackByCjid為什么報空指針?


@Controller(value = "blackServiceAction")
@Scope("prototype")
public class BlackServiceAction extends ActionSupport {

    private static final long serialVersionUID = -5155883818336614584L;

    private BlackInfoDaoImpl blackInfoDao;


    public String execute() throws ServletException, IOException {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        

        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            String customerId = request.getParameter("customerId");
            String address = request.getParameter("address");
            String result = isBlack(customerId,address);
            response.getWriter().print(result);
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;

    }

    //是否在黑名單中
    public String isBlack(String customerId,String address) {
        
        if(customerId==null||customerId.equals("")){
            return "2";
        }
        try {
            List<BlackInfo> list = blackInfoDao.selectBlackByCjid(customerId,address);
            String isblack = null;
            if(list.size()>0){
                isblack = "1";
                return isblack;
            }
            return "0";
        } catch (Exception e) {
            System.out.println(e);
            return "2";
        }
    }

}
2018-09-03 19:52:58,743 INFO [http-7001-Processor23]    Detected AnnotationActionValidatorManager, initializing it...
java.lang.NullPointerException
回答
編輯回答
司令

private BlackInfoDaoImpl blackInfoDao; 沒有初始化呀,

加上@Autowired注解吧,spring的依賴注入。

@Autowired
private BlackInfoDaoImpl blackInfoDao;
2018年5月21日 17:49
編輯回答
柒槿年

因為你的blackInfoDao沒有初始化。
兩個解決辦法:

  1. 初始化blackInfoDao。
private BlackInfoDaoImpl blackInfoDao = new BlackInfoDaoImpl();
  1. 自動注入這個類
@Autowired
private BlackInfoDaoImpl blackInfoDao;
2018年6月20日 01:20