程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> spring mvc-在springmvc中做一個根據id刪除一條數據的功能,出現500問題,代碼如下,請大神指教

spring mvc-在springmvc中做一個根據id刪除一條數據的功能,出現500問題,代碼如下,請大神指教

編輯:編程解疑
在springmvc中做一個根據id刪除一條數據的功能,出現500問題,代碼如下,請大神指教

Model層代碼
package com.pengyou.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "sg_registry")
public class registryEntity {

private int id;
private String name;
private String phonenum;
private int intArea; //意向面積
private String recHouse;
private String logTime; //錄入時間
private String salesMan;
private String workArea;
private int visitsCount;
private String address;
private String photoUrl;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id",nullable = false,length = 9)
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}

@Column(name = "name",nullable = false,length = 25)
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

@Column(name = "phonenum",nullable = false,length = 11)
public String getPhonenum() {
    return phonenum;
}
public void setPhonenum(String phonenum) {
    this.phonenum = phonenum;
}

@Column(name = "intArea",nullable = false,length = 9)
public int getIntArea() {
    return intArea;
}
public void setIntArea(int intArea) {
    this.intArea = intArea;
}

@Column(name = "recHouse",nullable = false,length = 255)
public String getRecHouse() {
    return recHouse;
}
public void setRecHouse(String recHouse) {
    this.recHouse = recHouse;
}

@Column(name = "logTime",nullable = false)
public String getLogTime() {
    return logTime;
}
public void setLogTime(String logTime) {
    this.logTime = logTime;
}

@Column(name = "salesMan",nullable = false,length = 255)
public String getSalesMan() {
    return salesMan;
}
public void setSalesMan(String salesMan) {
    this.salesMan = salesMan;
}

@Column(name = "workArea",nullable = false,length = 255)
public String getWorkArea() {
    return workArea;
}
public void setWorkArea(String workArea) {
    this.workArea = workArea;
}

@Column(name = "visitsCount",nullable = false,length = 9)
public int getVisitsCount() {
    return visitsCount;
}
public void setVisitsCount(int visitsCount) {
    this.visitsCount = visitsCount;
}

@Column(name = "address",nullable = true,length = 255)
public String getAddress() {
    return address;
}
public void setAddress(String address) {
    this.address = address;
}

@Column(name = "photoUrl",nullable = false,length = 255)
public String getPhotoUrl() {
    return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
    this.photoUrl = photoUrl;
}

}
DAO實現類代碼
package com.pengyou.dao.impl;
import javax.annotation.Resource;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import com.pengyou.dao.IdelDao;
import com.pengyou.model.registryEntity;

@Repository("deldao")
public class delDaoImpl implements IdelDao{

@Resource
protected SessionFactory sessionFactory;

public Session getSession(){
    return sessionFactory.getCurrentSession();

}
@Override
public void delreg(int id) {
    Session session = this.getSession();
    //registryEntity regens = (registryEntity) session.get(registryEntity.class, id);
    registryEntity regens = new registryEntity();
    regens.setId(id);
    session.delete(regens);

}

}
sevice實現類代碼
package com.pengyou.service.impl;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import com.pengyou.dao.IdelDao;
import com.pengyou.service.IdelService;
@Transactional
@Service("delservice")
public class delServiceImpl implements IdelService{
private IdelDao deldao;
@Override
public void delreg(int id) {
// TODO Auto-generated method stub
System.out.println("delServiceImpl---1------>"+id);
deldao.delreg(id);

    System.out.println("delServiceImpl--------->"+id);

}

/*

@Override
public List allReg() {
    // TODO Auto-generated method stub
    return deldao.allReg();
}

*/

}
Controller層代碼
package com.pengyou.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengyou.service.IdelService;
@Controller
@RequestMapping("/del/")
public class delController extends BaseController{

@Resource
private IdelService idelservice;

@ResponseBody
@RequestMapping("delReg")
public String toadd(HttpServletRequest request){
    System.out.println("id++++++"+request.getParameter("id"));
    idelservice.delreg(Integer.parseInt(request.getParameter("id")));
    /*System.out.println("delController------->");*/
    return "————————————————————";
}

}
頁面代碼


style="width: 35px;height: 35px" src="images/${r.photoUrl }" />
${r.name}
${r.phonenum }
${r.intArea }

${r.recHouse}
${r.logTime }
${r.salesMan }

${r.workArea}
${r.visitsCount }
${r.address }

編輯
刪除
備注


/c:forEach

運行時會報500錯誤,其余的地方都應該沒錯,應該是dao實現類中的方法錯了
id++++++1

delServiceImpl---1------>1
四月 18, 2016 12:18:51 下午 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet [sao] in context with path [/house] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.pengyou.service.impl.delServiceImpl.delreg(delServiceImpl.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy18.delreg(Unknown Source)

最佳回答:


500是服務器後台處理錯誤,異常信息顯示 delServiceImpl.java這個類有空指針異常,你定位到對應的行單步調試下吧。
JX_yang_zhi
u014623594
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved