教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 小学教育 >

JavaWeb宠物店课程设计报告(2)

来源:网络收集 时间:2026-09-08
导读: 其中图片在petaction中默认由本地,上传到服务器上的upload文件夹中,以便游客浏览以及管理员管理,id为系统自动+1生成,userid与user列表中的userid一致,typename与t_type列表中的typename一致,需要t_type预添加

其中图片在petaction中默认由本地,上传到服务器上的upload文件夹中,以便游客浏览以及管理员管理,id为系统自动+1生成,userid与user列表中的userid一致,typename与t_type列表中的typename一致,需要t_type预添加。

3.3 宠物管理系统功能说明

根据对宠物管理系统业务流程的分析,用户登录后要能自己添加自己的宠物信息,包括宠物的姓名,年龄,宠物的id,上传图片,是否疫苗,疫苗事件,疫苗地点,是否领养以及是否伤人等信息。用户登录后可以浏览别的用户的宠物信息,而管理员可以对用户前台添加的信息进行修改与删除。

3.4主要的宠物信息管理的实现 3.4.1 DAO层的实现

数据访问层,又称DAO层,在该层主要完成对象-关系映射的建立,通过这个映射,再通过访问业务对象即可实现对数据库的访问,使得开发中不必再用SQL语句编写复杂的数据库访问程序,这样就简化了对数据库的访问,提高了开发效率。同时通过对象-关系映射的配置,可以建立业务对象之间的复杂关系,如一对多、多对一、一对一、多对多等关系。这样就不再需要在数据库中建立表之间的复杂联系,使得业务对象之间的关系和数据库相分离,简化了数据库的建立和维护。在这一层中主要使用Hibernate框架来实现。

Tpet以及Tpet.hbm.xml为hibernate自动生成文件,用于连接数据库。

3.4.2 Service层的实现

Service为业务逻辑层,主要业务逻辑包括这些类分别实现了相应的接口,这些类在工作的过程中还需要依赖相应的DAO对象和JavaBean对象。实际操作时,在Action中通过Service对DAO接口进行调用,使整个系统有良好的层次。比如这边Petservices调用TPet,而PetserviceImpl继承Petservices,进行查询、添加、修改和删除操作。

Petservices代码:

import com.oa.models.TPet; import com.oa.utils.PageInfo; public interface PetServices { //查询

public PageInfo queryPet(int currentpage, int pageunit,

HttpServletRequest request, String url, String cond);

//添加

public Boolean addPet(TPet pet); //修改

public Boolean updatePet(TPet pet); //ID查询

public TPet getPet(Integer id); //删除

public TPet delPet(Integer id); }

PetserviceImpl主要代码:

public class PetServicesImpl extends AbstractServices implements PetServices { //查询

public PageInfo queryPet(int currentpage, int pageunit, }

HttpServletRequest request, String url, String cond) {

int rowCount = this.getPetsCount(cond); List<TPet> list = this.getPets(currentpage,

pageunit, cond);

PageInfo PageInfo = new PageInfo(currentpage, pageunit, rowCount, url,

list);

return PageInfo;

//获得

public List<TPet> getPets(int currentpage, int pageunit,

String cond) {

}

try {

String hql = " from TPet a where 1=1 " + cond; return this.query(hql, currentpage, pageunit);

} catch (Exception e) { }

return null;

e.printStackTrace();

//添加

public Boolean addPet(TPet pet) { }

save(pet); return true;

以上为查询以及添加的代码,其余删除修改略。

3.4.3 Action层的实现

Action用于处理视图层与业务层之间的衔接,当页面产生一个动作请求时候,通过Struts配置文件找到对应的Action中的接口,经过Action处理后返回结果并从Struts的配置文件中找到对应的跳转页面。 查询代码:

public String queryPet() throws Exception{

if (getSessionAttribute("querypageunit") == null) { }

StringBuffer cond = new StringBuffer(); if(null!=searchname&&""!=searchname.trim()){ }

cond.append(" and a.petname like '%"+searchname.trim()+"%' "); setSessionAttribute("querypageunit",this.pageunit);

int curpage =

Integer.parseInt(this.getCurrentpage(ServletActionContext.getRequest()));

int pageunit =

Integer.parseInt(this.getPageunit(ServletActionContext.getRequest(), "querypageunit"));

String url = "pet_queryPet?a=a";

PageInfo pageInfo = this.petServices.queryPet(curpage,

pageunit, ServletActionContext.getRequest(), url,

cond.toString());

预添加以及添加代码:

public String preaddPet() throws Exception{

}

List<TType> list = typeServices.queryType(); setRequestAttribute("list",list); return "preaddPet"; }

setRequestAttribute("pageinfo", pageInfo);

setRequestAttribute("searchname", this.searchname); return "queryPet";

public String addPet() throws Exception{

TUser user = (TUser) getSessionAttribute("user"); TPet pet = new TPet(); pet.setAge(age); pet.setIsbiter(isbiter); pet.setIsuser(isuser); pet.setPetname(petname);

pet.setRemark(remark);

}

pet.setTypename(typename); pet.setUserid(user.getUsername()); pet.setVacadrr(vacadrr); pet.setVaccin(vaccin); pet.setVaccin(vaccin); pet.setVacdate(vacdate);

// 将图片上传到工程下的upload文件夹中

String targetDirectory = ServletActionContext.getRequest()

String targetFileName = generateFileName(pictureFileName); File target = new File(targetDirectory, targetFileName); FileUtils.copyFile(picture, target); pet.setPicture(targetFileName); petServices.addPet(pet); return "addPet";

预添加将后台管理员添加的宠物类型添加到宠物信息,添加功能中有图片上传。 查看代码:

public String viewPet() throws Exception{

}

TPet pet = petServices.getPet(id); setRequestAttribute("pet",pet); return "viewPet";

其余修改删除代码等省略。

struts中宠物管理功能的实现:

<action name="pet_*" class="petAction" method="{1}">

<result name="queryPet">/files/pet/list.jsp</result>

<result name="addPet" type="redirectAction">pet_queryPet</result>

<result name="delPet" type="redirectAction">pet_queryPet</result> <result name="updatePet"

type="redirectAction">pet_queryPet</result>

<result name="preaddPet">/files/pet/add.jsp</result> …… 此处隐藏:3260字,全部文档内容请下载后查看。喜欢就下载吧 ……

JavaWeb宠物店课程设计报告(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/43455.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)