weixin_39125267 2017-12-12 07:38 采纳率: 0%
浏览 4107
已结题

SSM 遇到的java.lang.NullPointerException问题

报错
java.lang.NullPointerException
** at com.archives.controller.sysmanage.DepartmentController.doPageData(DepartmentController.java:38)
** at com.archives.controller.sy****smanage.DepartmentController.initHome(DepartmentController.java:32)
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:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

mapper.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >




























resultType="Integer">
select count(*) as cnt
from userinfo,dept
and userinfo.deptid = dept.deptid

and userinfo.loginname = #{loginname}


and userinfo.realname = #{realname}


and dept.deptname = #{deptname}


resultMap="userdeptMap">
select userinfo.loginid
, userinfo.loginname
, userinfo.realname
, dept.deptname
, dept.deptid
from userinfo,dept
where userinfo.deptid = dept.deptid
limit #{offsetindex},#{pageCount}


controller.java文件
package com.archives.controller.sysmanage;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.archives.common.Constant;
import com.archives.entity.Menu;
import com.archives.entity.UserDept;
import com.archives.entity.UserInfo;
import com.archives.model.A0104Model;
import com.archives.service.HomeService;
import com.archives.service.UserDeptService;

@Controller
@RequestMapping("/department")
public class DepartmentController {

UserDeptService userdeptService;
@RequestMapping("/init")
public String initHome(HttpServletRequest request) {
    A0104Model model=new A0104Model();
    model.setCurPage(1);
    model.setPageCount(Constant.PAGE_COUNT);
    对应的错误行**doPageData(request,model);**
    return "department";

}
private void doPageData(HttpServletRequest request, A0104Model model) {
    // TODO Auto-generated method stub
    int cnt = userdeptService.selectUserDeptCount(model);
    int totalPage = 0;
    if(cnt%Constant.PAGE_COUNT == 0) {
        totalPage = cnt/Constant.PAGE_COUNT;
    }else {
        totalPage = cnt/Constant.PAGE_COUNT + 1;
    }
    model.setTotalPage(totalPage);
    model.setOffsetindex((model.getCurPage() - 1) * Constant.PAGE_COUNT);
    model.setPageCount(Constant.PAGE_COUNT);
    对应的错误行**List<UserDept> userdeptduiyList=userdeptService.selectUserDeptList(model);**
    request.setAttribute("userdeptList", userdeptList);
    request.setAttribute("model", model);
}

}
model.java文件
package com.archives.model;

public class A0104Model {

private String loginname;
private String realname;
private String deptname;
public String getLoginname() {
    return loginname;
}
public void setLoginname(String loginname) {
    this.loginname = loginname;
}
public String getRealname() {
    return realname;
}
public void setRealname(String realname) {
    this.realname = realname;
}
public String getDeptname() {
    return deptname;
}
public void setDeptname(String deptname) {
    this.deptname = deptname;
}
public int getCurPage() {
    return curPage;
}
public void setCurPage(int curPage) {
    this.curPage = curPage;
}
public int getTotalPage() {
    return totalPage;
}
public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
}
public int getOffsetindex() {
    return offsetindex;
}
public void setOffsetindex(int offsetindex) {
    this.offsetindex = offsetindex;
}
public int getPageCount() {
    return pageCount;
}
public void setPageCount(int pageCount) {
    this.pageCount = pageCount;
}
private int curPage;
private int totalPage;

private int offsetindex;
private int pageCount;

}
Dao
package com.archives.dao;

import java.util.List;

import com.archives.entity.UserDept;
import com.archives.model.A0104Model;

public interface UserDeptDao {

UserDeptDao getUserDeptByName(String loginname);
int selectUserDeptCount(A0104Model model);
List<UserDept> selectUserDeptList(A0104Model model);

}
service
package com.archives.service;

import java.util.List;

import com.archives.entity.UserDept;
import com.archives.model.A0104Model;

public interface UserDeptService {
int selectUserDeptCount(A0104Model model);
List selectUserDeptList(A0104Model model);
}

serviceImpl
package com.archives.service;

import java.util.List;

import com.archives.dao.UserDeptDao;
import com.archives.entity.UserDept;
import com.archives.model.A0104Model;

public class UserDeptServiceImpl implements UserDeptService {

UserDeptDao  userdeptDao;

@Override
public int selectUserDeptCount(A0104Model model) {
    // TODO Auto-generated method stub
    int cnt=userdeptDao.selectUserDeptCount(model);
    return cnt;
}

@Override
public List<UserDept> selectUserDeptList(A0104Model model) {
    // TODO Auto-generated method stub
    List<UserDept> userdeptList =userdeptDao.selectUserDeptList(model);
    return userdeptList;
}

}
UserDept.java
package com.archives.entity;

public class UserDept {

private int deptid;
private String deptname;
private String telephone;
private String fax;
private String managerid;
private String remark;
public String getTelephone() {
    return telephone;
}
public void setTelephone(String telephone) {
    this.telephone = telephone;
}
public String getFax() {
    return fax;
}
public void setFax(String fax) {
    this.fax = fax;
}
public String getManagerid() {
    return managerid;
}
public void setManagerid(String managerid) {
    this.managerid = managerid;
}
public String getRemark() {
    return remark;
}
public void setRemark(String remark) {
    this.remark = remark;
}
public int getDeptid() {
    return deptid;
}
public void setDeptid(int deptid) {
    this.deptid = deptid;
}
public String getDeptname() {
    return deptname;
}
public void setDeptname(String deptname) {
    this.deptname = deptname;
}
public String getLoginid() {
    return loginid;
}
public void setLoginid(String loginid) {
    this.loginid = loginid;
}
public String getLoginname() {
    return loginname;
}
public void setLoginname(String loginname) {
    this.loginname = loginname;
}
public String getRealname() {
    return realname;
}
public void setRealname(String realname) {
    this.realname = realname;
}
private String loginid;
private String loginname;
private String realname;

}

  • 写回答

14条回答 默认 最新

  • jokingZY 2017-12-12 07:46
    关注

    and userinfo.loginname = #{loginname} 、realname deptname 这三个参数取值的时候做下判断

    and userinfo.loginname = #{loginname}

    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境