JavaWeb宠物店课程设计报告(2)
其中图片在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字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [小学教育]四年级综合实践活动课《衣物的洗涤》教
- [小学教育]2014半年工作总结怎么写
- [小学教育]20世纪外国文学专题综合试题及答案
- [小学教育]TS_1循环使用催化丙烯环氧化反应研究
- [小学教育]最实用的考勤签到表(上下班签到表)
- [小学教育]气候与生态建筑——以新疆民居为例
- [小学教育]二人以上股东有限责任公司章程参考样本
- [小学教育]2014届第一轮复习资料4.1,3美好生活的
- [小学教育]土方开挖、降水方案
- [小学教育]手绘儿童绘本《秋天的图画》(蜡笔)
- [小学教育]2002级硕士研究生卫生统计学考试试题
- [小学教育]环保装备重点发展目录
- [小学教育]金蝶K3合并报表培训教材
- [小学教育]岩浆岩试题及参考答案
- [小学教育]知之深爱之切学习心得
- [小学教育]第十二章 蛋白质的生物合成
- [小学教育]Chapter 2-3 Solid structure and basi
- [小学教育]市政道路雨季专项施工方案
- [小学教育]中国海洋大学2012-2013学年第二学期天
- [小学教育]教育心理学第3章-学习迁移
- 浅谈深化国企改革中加强党管企业
- 2006年中国病理生理学会学术活动安排
- 设计投标工作大纲
- 基于ARP的网络攻击与防御
- 2016届湖北省七市(州)教科研协作体高三
- Google_学术搜索及其检索技巧
- 2019-2020学年七年级地理下册6.3美洲教
- 城市道路可研报告
- 【名师指津】2012高考英语 写作基础技
- 6级知识点培训北京师范大学《幼儿智趣
- 注册会计师会计知识点:金融资产
- 新安装 500 kV 变压器介损分析与判断
- PS2模拟器PCSX2设置及使用教程.
- 医院药事管理与药剂科管理组织机构
- {PPT背景素材}丹巴的醉人美景,免费,一
- NAS网络存储应用解决方案
- 青海省西宁市六年级上学期数学期末考试
- 测量管理体系手册依据ISO10012:2003
- 洞子小学培养骨干教师工作计划
- 浅谈《牛津初中英语》的教材特点及教学




