实际开发常见错误

实际开发常见错误

1、 绑定错了对象导致attempted to delete null:

现象:在页面中删除对象失败

原因:在DAO的remove方法中

public void reomveSight(Long[] sightid) throws SightException

{

for(int i=0;i<sightid.length;i++)

super.removeObject(TtourInfo***.class,sightid[i]);

}

绑定错了对象,导致attempted to delete null错误。



2、 在一对多的前提下删除的时候不能级联删除子表中的数据:

现象:删除的时候不能级联删除子表中的数据导致报外键引用的错误。

解决方法:sight景点与image图片是一对多的关系,sight的hbm.xml配置文件原来在配置图片时是:

<!-- bi-directional one-to-many association to TtourInfoImage -->

<set

name="ttourInfoImages"

lazy="true"

inverse="true"

cascade="none"

>

<meta attribute="field-description">

@hibernate.set

lazy="true"

inverse="true"

cascade="none"

@hibernate.collection-key

column="COMPANY"

@hibernate.collection-one-to-many

class="com.strongit.tour.bo.TtourInfoImage"

</meta>

<key>

<column name="SIGHTID" />

</key>

<one-to-many

class="com.strongit.tour.bo.TtourInfoImage"

/>

</set>

现在改成

<!-- bi-directional one-to-many association to TtourInfoImage -->

<set

name="ttourInfoImages"

lazy="true"

inverse="true"

cascade="all"

>

<meta attribute="field-description">

@hibernate.set

lazy="true"

inverse="true"

cascade="all"

@hibernate.collection-key

column="COMPANY"

@hibernate.collection-one-to-many

class="com.strongit.tour.bo.TtourInfoImage"

</meta>

<key>

<column name="SIGHTID" />

</key>

<one-to-many

class="com.strongit.tour.bo.TtourInfoImage"

/>

</set>

就可以了。



3、 景区dao配置文件错误

错误描述:

Error registering

bean with name

'tour.scenicArea.sceneryAreaDao'

defined in ServletContext resource

[/WEB-INF/config_ext/applicationContext-tour-sceneryarea-dao.xml]:

Bean class

[import com.strongit.tour.scenicArea.dao.impl.SceneryAreaDaoImpl]

not found;

nested exception is java.lang.ClassNotFoundException:

import com.strongit.tour.scenicArea.dao.impl.SceneryAreaDaoImpl

解决方法:

applicationContext-tour-sceneryarea-dao.xml 中

class="com.strongit.tour.scenicArea.dao.impl.SceneryAreaDaoImpl"

写成了

class="import com.strongit.tour.scenicArea.dao.impl.SceneryAreaDaoImpl"



4、 景点配置文件错误

org.springframework.beans.factory.BeanCreationException:

Error creating bean with name

'tour.service.isightService'

defined in ServletContext resource

[/WEB-INF/config_ext/applicationContext-tour-sight-service.xml]:

Can't resolve reference to bean

'tour.service.sightService'

while setting property 'target';

nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'tour.service.sightService'

defined in ServletContext resource [/WEB-INF/config_ext/applicationContext-tour-sight-service.xml]:

Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:

Invalid property 'sightDao' of bean class [com.strongit.tour.scenicArea.service.impl.SightServiceImpl]:

Bean property 'sightDao' is not writable or has an invalid setter method:

Does the parameter type of the setter match the return type of the getter?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tour.service.sightService' defined in ServletContext resource [/WEB-INF/config_ext/applicationContext-tour-sight-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sightDao' of bean class [com.strongit.tour.scenicArea.service.impl.SightServiceImpl]: Bean property 'sightDao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

org.springframework.beans.NotWritablePropertyException: Invalid property 'sightDao' of bean class [com.strongit.tour.scenicArea.service.impl.SightServiceImpl]: Bean property 'sightDao' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

错误原因:

在com.strongit.tour.scenicArea.service.impl.SightServiceImpl类中没有对sightDao添加set属性。



5、 修改时没有提交值

缺少<html:hidden property="sceneryareaid"></html:hidden>来绑定id的值。



6、 初始化景点信息出错

org.apache.jasper.JasperException:

/member/tour/sceneryareamanage/sight_edit.jsp(121,7)

According to the TLD attribute property is mandatory for tag text

错误原因:htmltext标记与input标记的属性混用



7、 删除景点报500错

javax.servlet.ServletException:

No bean named '/tour/scenicArea/deleteSightAction' is defined:

错误原因:

在applicationcontext-tour-sight-action中删除的action配置的path

与struts-config-tour-sight中相应的删除配置不相同



8、 加载FORM表单的上传的文件数组元素时报参数错误

错误提示:

IllegalArgumentException --argument type mismatch

解决方法:

在<html:form中加入enctype="multipart/form-data"



9、 使用HQL语句时出错

景点与图片是一对多的关系,现在要从一的景点中找到相应的图片的所有信息。

在daoimpl中



public List querySQLEx(String SqlStr) throws SightException

{

return super.getHibernateTemplate().find(SqlStr);

}



public TtourInfoImage getImagePathToSight(Long sightid) throws SightException

{

return (TtourInfoImage) this.querySQLEx("select TtourInfoImage m where m.ttourInfoSight.sightid="+sightid);

}

在删除的action的调用中

String msg="";

try

{

String [] sightid=request.getParameter("delid").split(",");

try

{

String root = getServletContext().getRealPath("/");

System.out.println(root);

Long [] sightID=new Long[sightid.length];

List fileList=new ArrayList();

for(int i=0;i<sightid.length;i++)

{

sightID[i]=Long.valueOf(sightid[i].trim());

//把图片对象放入临时保存图片的图片路径数组中

fileList.add(sightService.getImagePathToSight(sightID[i]).getImageFile());

System.out.println("原图="+sightService.getImagePathToSight(sightID[i]).getImageFile());

fileList.add(sightService.getImagePathToSight(sightID[i]).getImageBreviry());

System.out.println("缩略图="+sightService.getImagePathToSight(sightID[i]).getImageBreviry());

}

sightService.reomveSight(sightID);//先批量删除景点和与景点有关的图片表的数据

sightService.delImage(root,fileList);//再删除图片表中,与景点相关的图片

msg = "景点删除成功!";

}

catch (Exception e)

{

System.out.println(e.getMessage());

log.info(e.getMessage());

msg = "对不起,在您删除的数据中已有数据被使用,无法删除!";

}

}

catch (RuntimeException e)

{

e.printStackTrace();

msg="在删除景点的过程中出现意外错误!";

}

request.setAttribute("msg", msg);

return mapping.findForward("success");



10、 配置文件错误

nested exception is org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'tour.service.commodityService' defined in ServletContext resource

[/WEB-INF/config_user/applicationContext-tour-commodity-service.xml]:

Error setting property values;

nested exception is org.springframework.beans.PropertyAccessExceptionsException:

PropertyAccessExceptionsException (1 errors);

nested propertyAccessExceptions are:

[org.springframework.beans.TypeMismatchException:

Failed to convert property value of type

[com.strongit.tour.commodityManage.dao.impl.CommodityTypeDAOImpl]

to required type [com.strongit.tour.commodityManage.dao.ICommodityDAO]

for property 'commodityDAO']

org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'tour.service.commodityService'

defined in ServletContext resource

[/WEB-INF/config_user/applicationContext-tour-commodity-service.xml]:

Error setting property values;

nested exception is org.springframework.beans.PropertyAccessExceptionsException:

PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are:

[org.springframework.beans.TypeMismatchException:

Failed to convert property value of type [com.strongit.tour.commodityManage.dao.impl.CommodityTypeDAOImpl]

to required type [com.strongit.tour.commodityManage.dao.ICommodityDAO]

for property 'commodityDAO']

PropertyAccessExceptionsException (1 errors)

org.springframework.beans.TypeMismatchException:

Failed to convert property value of type

[com.strongit.tour.commodityManage.dao.impl.CommodityTypeDAOImpl]

to required type [com.strongit.tour.commodityManage.dao.ICommodityDAO]

for property 'commodityDAO'

错误原因:

在dao配置文件中 class="com.strongit.tour.commodityManage.dao.impl.CommodityDAOImpl"

写成了class="com.strongit.tour.commodityManage.dao.impl.CommodityTypeDAOImpl"



11、 级联删除商品的相关图片时报错

将商品hbm.xml文件中图片的相关链接的cascode="none"改为"all"。



12、 添加商品时没有触发action

在<html:form>里的action写错了。



13、 添加商品时没有找到actoin

javax.servlet.ServletException:

Error creating bean with name

'/tour/commodityManage/addCommodityAction'

defined in ServletContext resource

[/WEB-INF/config_user/applicationContext-tour-commodity-action.xml]:

Error setting property values;

nested exception is org.springframework.beans.NotWritablePropertyException:

Invalid property 'commodityService' of bean class

[com.strongit.tour.commodityManage.action.AddCommodityAction]:

Bean property 'commodityService' is not writable or has an invalid setter method:

Does the parameter type of the setter match the return type of the getter?

在AddCommodityAction.do中少了commodityService的set方法

14、 加载工程时有绔绞欢之类的错误

现象:加载工程时有绔绞欢之类的字样的错误,工程不能启动

解决方法:选中工程,选菜单下的Project下的Properties选项,

把字符编码改为UTF-8。

15、 工程中出现没有编译成的class文件

工程中出现没有编译成class文件时,选eclipe里的project的BuildAutomatically就行。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值