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这个类有空指针异常,你定位到对应的行单步调试下吧。

解决方案二:

估计是你的持久层session根本就没有获取到

时间: 2025-01-20 13:49:30

spring mvc-在springmvc中做一个根据id删除一条数据的功能,出现500问题,代码如下,请大神指教的相关文章

java中输出一个日期排序,输出格式怎么变成Date@2c905b34类似的了。。请大神指点

问题描述 java中输出一个日期排序,输出格式怎么变成Date@2c905b34类似的了..请大神指点 java中输出一个日期排序,输出格式怎么变成Date@2c905b34. Date@3953c9c7类似的格式了..请大神指点 : Date[] days = new Date[5]; days[0] = new Date(2012123); days[1] = new Date(201515); days[2] = new Date(2008123); days[3] = new Date(

对象-SSH中怎么实现根据id删除一条数据?求大神!!

问题描述 SSH中怎么实现根据id删除一条数据?求大神!! 如题,小白一枚,主要是this.getHibernateTemplate().delete();方法只能传对象,个人感觉太复杂,自己如果写一个删除不用它里面的方法应该怎么写? 解决方案 public void delete(int id){ String hql="delete Person as p where p.id=?"; Query query=session.createQuery(hql); query.setI

递归算法-用栈存储指向一个二叉树结点的指针,中序遍历时,进行调试时总卡在GetTop()函数,请大神帮我看看

问题描述 用栈存储指向一个二叉树结点的指针,中序遍历时,进行调试时总卡在GetTop()函数,请大神帮我看看 利用栈存储指向一个二叉树结点的指针,可不知为什么,在进行中序遍历时,进行调试时总卡在GetTop()函数这里,请大神帮我看看 #include "stdio.h" #include "malloc.h" #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE

我用spring mvc+mybatis整合为什么出这个错误,是不是路径错误?我是新手,请大神指教

问题描述 我用spring mvc+mybatis整合为什么出这个错误,是不是路径错误?我是新手,请大神指教 org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:JAVANewWorkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsstudent

解锁按钮-Java web 如何按钮的解锁问题,根据需求该如何做,请大神指教

问题描述 Java web 如何按钮的解锁问题,根据需求该如何做,请大神指教 1.点击"保存按钮"后保存录入学生成绩,教师可对保存的成绩进行修改, 2.点击"提交按钮"后学生成绩锁定不能再保存修改,只能查看.(即"保存按钮"和"提交按钮"变灰色) 3.解锁功能仅开放给管理员,管理员对成绩解锁后,教师可再次保存或者提交数据. 请问这个过程如何做,高人给点指点吧!!!!!! 解决方案 数据库中每个学生的信息中添加一个status字

二维数组-C语言自学一月,在做数据统合输出,请大神指教。

问题描述 C语言自学一月,在做数据统合输出,请大神指教. C语言自学一月,搞出了读取文件数据,进行平均数和标准偏差计算,再输出的程序. 就像这样. #include #include #include /*main program*/ int main() { float n[831],ave,sd; int i; char in_file_name[FILENAME_MAX], out_file_name[FILENAME_MAX]; FILE *inf, outf; float ave1(i

android fragment-fragmentactivity中了用了办法来解决每次点击后重复加载ui,但是没效,求大神指教

问题描述 fragmentactivity中了用了办法来解决每次点击后重复加载ui,但是没效,求大神指教 package com.doone.changeverday.ui.fragmrnt; import java.util.ArrayList;import java.util.List; import com.doone.changeverday.R;import com.doone.changeverday_bean.ShopBean;import com.doone.changevryd

menu-菜鸟请大神指教,关于在fragment中加入vierpager的问题

问题描述 菜鸟请大神指教,关于在fragment中加入vierpager的问题 package com.yanis.yc_ui_fragment_menu; import java.util.ArrayList; import java.util.List; import com.health.Circle; import com.health.Information; import com.health.Market; import android.os.Bundle; import andr

c++-用C++做个B2c电子商务 ,没有思路,请大神指教!

问题描述 用C++做个B2c电子商务 ,没有思路,请大神指教! 用户注册,用户登录.(编号,账号,密码,姓名,资金,地址) 登录后菜单项:选购商品,查看订单,查看资金,充值,修改账户信息,注销,退出 商家登录,此处商家和系统平台是统一角色,平台自营类似苏宁易购. 登录后菜单项:查看.添加.修改.删除商品(编号,商品名称,商品信息,价格,库存量,规格,颜色,所属商家), 查看订单,查看金额,注销,退出,相应的子菜单里应有返回上一级菜单功能. 选购商品,用户登录后可以直接商品进行购买下单. 记录订单