项目管理javaWEB模块物流项目二.docx

上传人:b****6 文档编号:3545257 上传时间:2022-11-23 格式:DOCX 页数:15 大小:20.42KB
下载 相关 举报
项目管理javaWEB模块物流项目二.docx_第1页
第1页 / 共15页
项目管理javaWEB模块物流项目二.docx_第2页
第2页 / 共15页
项目管理javaWEB模块物流项目二.docx_第3页
第3页 / 共15页
项目管理javaWEB模块物流项目二.docx_第4页
第4页 / 共15页
项目管理javaWEB模块物流项目二.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

项目管理javaWEB模块物流项目二.docx

《项目管理javaWEB模块物流项目二.docx》由会员分享,可在线阅读,更多相关《项目管理javaWEB模块物流项目二.docx(15页珍藏版)》请在冰豆网上搜索。

项目管理javaWEB模块物流项目二.docx

项目管理javaWEB模块物流项目二

 

(项目管理)javaWEB模块物流项目二

BOS物流管理系统第2天

内容安排:

1、Springdata完成数据访问层

2、封装dao

项目使用STS

3、登陆业务

1.登陆业务

使用PD根据大纲绘制用户表

PowerDesigner

点击菜单Database--->genreateDatabase--->点击预览

注意:

PD生成表,默认脚本自带顺引号设置一定去掉双引号否则逆向生成实体类失败!

一般习惯脚本采用大写!

Oracle数据库生成脚本!

去掉双引号设置步骤:

--->EditcurrentDatabase选项

点击生成脚本预览...引号就没有了!

预览用户的脚本

使用plsql工具完成脚本执行!

开发中一般新建一个用户授予resouce+connect角色即可!

plsql/develepor工具使用管理员创建用户并且授权ITCAST29

开发bos采用oracleITCAST29用户!

创建实体类

Springdatajpa注解:

@Entity@Table@Id@GenerateValue

实体类的注册需要编写ApplicationContext.xml

配置ApplicationContext连接池和Bean注册

1:

数据库配置文件

2:

配置连接池以及sessionFactory测试:

启动tomcat

property-placeholderlocation="classpath:

jdbc.properties"/>

--配置连接数据库参数c3p0连接池-->

--连接池给sessionFactory注解版本-->

--配置其他hibernate信息-->

true

true

validate

--update-->

${jdbc.dialect}

cn.itcast.mavenbos.domain

oraclevalidate校验报错:

数据库表字段类型numeric(10,2)---->实体类BigDecimal类型.

需要导入:

hibernate-entity.jarspring-data.jpa依赖的jar

org.hibernate

hibernate-entitymanager

${hibernate.version}

配置Springdata学习

1:

引入spring-data.jar+依赖包

参阅文档

45页

2:

spring主配置文件(以前:

学习hibernate需要连接池--->SessionFactory)

现在springdata不用sessionFactory+注解支持需要配置springdata名称空间

缺少jpa名称空间参照background章节找到quickstart

applicationContext.xml引入名称空间

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

context="http:

//www.springframework.org/schema/context"

xmlns:

aop="http:

//www.springframework.org/schema/aop"

xmlns:

jpa="http:

//www.springframework.org/schema/data/jpa"

xmlns:

tx="http:

//www.springframework.org/schema/tx"

xsi:

schemaLocation="http:

//www.springframework.org/schema/beans

http:

//www.springframework.org/schema/beans/spring-beans.xsd

http:

//www.springframework.org/schema/context

http:

//www.springframework.org/schema/context/spring-context.xsd

http:

//www.springframework.org/schema/aop

http:

//www.springframework.org/schema/aop/spring-aop.xsd

http:

//www.springframework.org/schema/tx

http:

//www.springframework.org/schema/tx/spring-tx.xsd

http:

//www.springframework.org/schema/data/jpa

http:

//www.springframework.org/schema/data/jpa/spring-jpa.xsd">

配置连接池

--使用Springdata-->

property-placeholderlocation="classpath:

jdbc.properties"/>

--配置连接数据库参数c3p0连接池-->

配置EntityManagerFactory参照文档==sessionFactory

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

--自动建表-->

--方言-->

--显示sql-->

配置:

注解包扫描是pring注解扫描以及springdata支持dao扫描

--依赖注入扫描spring注解-->

componen-scanbase-package="cn.itcast.bos.service,cn.itcast.bos.web"/>

--扫描springdata继承dao接口-->

repositoriesbase-package="cn.itcast.bos.dao">

repositories>

配置事务

--注解事务管理器-->

annotation-driventransaction-manager="transactionManager"/>

测试:

配置完成启动tomcat

导入jar

UserDao设计

Reposistory接口最大接口!

根据目录继承树结构--->F4开发中XxxxDaoextendsJpaRepostory即可

springdata提供一套接口以及实现类编写UserDao继承指定接口即可完成crud

userDao完成!

专门针对dao测试!

UserService设计

设计简单业务方法

注解完成业务层实现

测试业务层:

UserDao扫描

需要配置事务管理器采用springdata提供事务管理器

开启spring注解扫描

测试:

JPQL查询说明

1:

根据方法名称自动生成jpql语句

参照文档

案例1测试业务层+junit

业务层调用userDao:

userDao业务方法必须符合命名规范

测试:

s

2:

命名查询推荐注解name查询要求:

类名.方法名springdata自动扫描实体类找寻注解@NamedQuery(name="xxx")

案例2:

要求使用@NamedQuery注解在目标查询实体类上声明

实体类添加注解springdata自动搜索类名.方法名称找寻对应HQL语句

junit

3:

@Query注解的查询dao方法名称可以自定义

注解中编写JPQL语句==HQL

案例三演示

4:

@Query注解完成本地sql查询需要添加nativeQuery=true告知springdata书写语句本地sql

5:

参数注入查询@Param注解指定参数类似HQL占位符@Param("lastname')自动将参数值赋予:

lastname

springdatajpa查询结束!

webaction抽取

通用Action模板

封装通用性代码BaseAction

packagecn.itcast.mavenbos.web.action.base;

importjava.lang.reflect.ParameterizedType;

importjava.lang.reflect.Type;

importorg.apache.struts2.ServletActionContext;

importorg.springframework.beans.factory.annotation.Autowired;

importcn.itcast.mavenbos.service.user.UserService;

importcom.opensymphony.xwork2.ActionContext;

importcom.opensymphony.xwork2.ActionSupport;

importcom.opensymphony.xwork2.ModelDriven;

importcom.opensymphony.xwork2.util.ValueStack;

//复用Action代码

publicabstractclassBaseActionextendsActionSupportimplementsModelDriven{

//各种业务层对象

@Autowired

privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

//@Autowired

//privateUserServiceuserService;

protectedTmodel;//各个action封装对象model

publicTgetModel(){

returnmodel;

}

//后续子类XxxxAction请求参数封装model里面

publicBaseAction(){

//对model进行实例化,通过子类类声明的泛型

Typesuperclass=this.getClass().getGenericSuperclass();

//转化为参数化类型

ParameterizedTypeparameterizedType=(ParameterizedType)superclass;

//获取一个泛型参数

ClassmodelClass=(Class)parameterizedType.getActualTypeArguments()[0];

try{

model=modelClass.newInstance();

}catch(InstantiationExceptione){

e.printStackTrace();

}catch(IllegalAccessExceptione){

e.printStackTrace();

}

}

//获取请求参数

publicStringgetParameter(Stringname){

returnServletActionContext.getRequest().getParameter(name);

}

//获取SessionAttribute

publicObjectgetSessionAttribute(Stringname){

returnServletActionContext.getRequest().getSession().getAttribute(name);

}

//向session保存属性

publicvoidsetSessionAttribute(Stringname,Objectvalue){

ServletActionContext.getRequest().getSession().setAttribute(name,value);

}

//值栈对象的获取

publicValueStackgetStack(){

returnActionContext.getContext().getValueStack();

}

//压入数据到值栈

publicvoidpush(Objectobj){

getStack().push(obj);

}

//压入数据到值栈

publicvoidset(Stringkey,Objectvalue){

getStack().set(key,value);

}

//分页请求属性驱动

protectedintpage;//页码

protectedintrows;//每页记录数

publicvoidsetPage(intpage){

this.page=page;

}

publicvoidsetRows(introws){

this.rows=rows;

}

}

注入各种业务层接口

login.jsp页面设计

登陆按钮--->同步请求不能提交表单

标签超链接变成js点击事件--->函数方法--->提交表单

编写jsgo方法实现提交表单

form表单的设计

验证码ajax校验

js完成!

varcheckcode_flag=false;

//页面加载完成进行验证码校验....离焦事件

$(function(){

$("input[name='checkcode']").blur(function(){

//发送ajax请求

$.post("${pageContext.request.contextPath}/user/userAction_validCheckCode",{"checkcode":

this.value},function(data){

if(data){

//true验证码正确可以提交表单用户提示

$("#checkcode_sp").html("√");

checkcode_flag=true;

}else{

//false验证码错误不可以提交表单用户提示

$("#checkcode_sp").html("×");

checkcode_flag=false;

}

});

});

});

//表单的提交

functiongo(){

//提交表单

if(checkcode_flag){

$("#loginform").submit();

}

}

2:

action校验方法从session获取验证码json返回true/false

测试:

ok

login.jsp表单action地址

login业务方法编写

1:

login.jspaction

2:

login业务方法

//登陆业务方法

//登陆业务

@Action(value="userAction_login",results={@Result(name="login_ok",type="redirect",location="/index.jsp"),@Result(name="login_error",location="/login.jsp")})

publicStringlogin(){

Stringsession_code=(String)getSessionAttribute("key");

Stringinput_code=getParameter("checkcode");

if(StringUtils.isNotBlank(input_code)){

if(input_code.equalsIgnoreCase(session_code)){

UserexistUser=userService.findUserByNameAndPassword(model.getUsername(),model.getPassword());

if(existUser==null){

this.addActionError(this.getText("login.usernameorpassword.error"));

return"login_error";

}else{

//用户存放Session验证码移除

removeSessionAttribute("key");

setSessionAttribute("existUser",existUser);

return"login_ok";

}

}else{

//验证码错误..绕过ajax校验

//thrownewRuntimeException("数据非法...");

this.addActionError(this.getText("login.illegal.error"));

return"login_error";

}

}else{

this.addActionError(this.getText("login.illegal.error"));

return"login_error";

//用户没有输入验证码

//thrownewRuntimeException("数据非法...");

}

}

2:

配置国际化相关信息

3:

login.jsp回显错误信息

登陆请求表单参数校验(登陆参数校验)

UserAction同包下新建局部xml校验文件

编写校验器规则

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEvalidatorsPUBLIC

"-//ApacheStruts//XWorkValidator1.0.3//EN"

"http:

//struts.apache.org/dtds/xwork-validator-1.0.3.dtd">

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 实习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1