报错
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;
}