SSH小框架笔记
2017-01-06 20:23
260 查看
1.加入spring
--加入jar包
--配置web.xml
--生成applicationContext.xml
2.加入Hibernate
--加入jar包
--配置hibernate.cfg,xml(配置基本的数据库信息 方言 格式化sql 显示sql 数据更新方式 hbm--update)
--编写db.properties (写入数据库基本信息 user。password。。)
--创建实体化类 并生成hbm.xml文件
--配置applicationContext.xml
--导入db.properties文件
--配置dataSource
${jdbc.user}
--配置sessionfactory
LocalSessionFactoryBean(hibernate4)
{ <property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml" ></property>
<property name="mappingLocations" value="classpath:entities/*.hbm.xml"></property>
--配置spring声明式事务 HibernateTransactionManager 管理sessionFactory
--配置事务属性: <t
4000
x:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
--配置事务切入点:<aop:config>
<aop:pointcut expression="execution( * service.*.*(..) )" id="txPointcut"/>
注意execution拼写
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
3.加入Struts2
--加入jar包
--在web.xml文件中配置Struts2的filter
--加入Struts2配置文件
--整合
①加入Struts整合spring的jar包
②在spring的配置文件applicationContext-beans.xml中正常配置Action,注意Action的scope为prototype
③在Struts2的配置文件struts.xml中配置Action时,class属性指向该Action在IOC中的id
4.创建applicationContext-beans.xml 配置employeeDao 指向sessionFactory
配置employeeService 、 employeeAction
5.完成功能
①获取所有员工信息:若在dao中只查询employee的信息,而且Employee和Department还是使用的懒加载,页面上还需要显示员工部门信息,此时会出现懒加载异常,代理对象不能被初始化。
解决办法:使用迫切左外链接 FROM Employee e LEFT OUTER JOIN FETCH e.department
②删除员工信息(使用Ajax)
①正常删除:返回值需要是redirect类型,而且重定向到emp-list
--hql:String hql="DELETE FROM Employee WHERE id = ?";
getSession().createQuery(hql).setInteger(0, id).executeUpdate();
---action中需要传入id值
private Integer id ; setid。。。。
②确定要删除吗?确认
使用JQuery时发生异常:
Struts has detected an unhandled exception:
发现错误:
<a href="emp-delete?id=${id}" class="delete">DELETE</a> 中少了红色的引号
③Ajax的使用参见file:///G:/BaiduYunDownload/opensourse/SSH 框架/struts-2.3.15.3/docs/WW/docs/home.html
tips:return值改为delete 并在struts2配置文件中<result type="stream" name="delete">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
public String delete() {
try {
employeeService.delete(id);
inputStream = new ByteArrayInputStream("1".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
try {
inputStream = new ByteArrayInputStream("0".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
return "delete";
}
③增加员工信息
①Action中用到了ModelDriven 、prepareble接口
②输入的字符串类型的birth必须要用类型转换器转换为Date型
遇到问题:birth仍然为空!
发现Employee(util.Date)跟类型转换类(sql.Date)导入的Date包不一致
---解决办法 统一为util.Date
③Ajax验证人员是否存在
Action中写一个ValidatebyLastName的方法
--Dao中写通过姓名查询的方法
--Service中判断是否找到该员工 返回boolean值
-- Action中的验证方法 判断Boolean值 并设置对应的data数据
input.jsp写入相应的Ajax代码
tips:写完之后发现添加员工 Ajax并没有起卵用??????
-----<script type="text/javascript" src="/scripts/jquery-1.7.2.min.js"></script>
多了个/ wtf????
但这并没有什么卵用 还是不能验证????
$this.after("<font color='green'>Lastname可用!
></font>"); 再次粗心多了个>
然而用户名可用可以验证 ,不可用的情况还是不可以??????????
}else if(date=="0"){ ============data写成了date !!!!!!!!!!!!!!!
终于好了O(∩_∩)O
④修改员工信息
--带上Id 通过id查找对应的employee Dao--Service--Action
--表单回显 public String input(){
request.put("departments", departmentService.getAll());
return "input";
}
public void prepareInput(){
if(id!=null){
model=employeeService.get(id);
}
}
--加入jar包
--配置web.xml
--生成applicationContext.xml
2.加入Hibernate
--加入jar包
--配置hibernate.cfg,xml(配置基本的数据库信息 方言 格式化sql 显示sql 数据更新方式 hbm--update)
--编写db.properties (写入数据库基本信息 user。password。。)
--创建实体化类 并生成hbm.xml文件
--配置applicationContext.xml
--导入db.properties文件
--配置dataSource
${jdbc.user}
--配置sessionfactory
LocalSessionFactoryBean(hibernate4)
{ <property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml" ></property>
<property name="mappingLocations" value="classpath:entities/*.hbm.xml"></property>
--配置spring声明式事务 HibernateTransactionManager 管理sessionFactory
--配置事务属性: <t
4000
x:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
--配置事务切入点:<aop:config>
<aop:pointcut expression="execution( * service.*.*(..) )" id="txPointcut"/>
注意execution拼写
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
3.加入Struts2
--加入jar包
--在web.xml文件中配置Struts2的filter
--加入Struts2配置文件
--整合
①加入Struts整合spring的jar包
②在spring的配置文件applicationContext-beans.xml中正常配置Action,注意Action的scope为prototype
③在Struts2的配置文件struts.xml中配置Action时,class属性指向该Action在IOC中的id
4.创建applicationContext-beans.xml 配置employeeDao 指向sessionFactory
配置employeeService 、 employeeAction
5.完成功能
①获取所有员工信息:若在dao中只查询employee的信息,而且Employee和Department还是使用的懒加载,页面上还需要显示员工部门信息,此时会出现懒加载异常,代理对象不能被初始化。
解决办法:使用迫切左外链接 FROM Employee e LEFT OUTER JOIN FETCH e.department
②删除员工信息(使用Ajax)
①正常删除:返回值需要是redirect类型,而且重定向到emp-list
--hql:String hql="DELETE FROM Employee WHERE id = ?";
getSession().createQuery(hql).setInteger(0, id).executeUpdate();
---action中需要传入id值
private Integer id ; setid。。。。
②确定要删除吗?确认
使用JQuery时发生异常:
Struts has detected an unhandled exception:
Messages: | No result defined for action actions.EmployeeAction and result input |
<a href="emp-delete?id=${id}" class="delete">DELETE</a> 中少了红色的引号
③Ajax的使用参见file:///G:/BaiduYunDownload/opensourse/SSH 框架/struts-2.3.15.3/docs/WW/docs/home.html
tips:return值改为delete 并在struts2配置文件中<result type="stream" name="delete">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
public String delete() {
try {
employeeService.delete(id);
inputStream = new ByteArrayInputStream("1".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
try {
inputStream = new ByteArrayInputStream("0".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
return "delete";
}
③增加员工信息
①Action中用到了ModelDriven 、prepareble接口
②输入的字符串类型的birth必须要用类型转换器转换为Date型
遇到问题:birth仍然为空!
发现Employee(util.Date)跟类型转换类(sql.Date)导入的Date包不一致
---解决办法 统一为util.Date
③Ajax验证人员是否存在
Action中写一个ValidatebyLastName的方法
--Dao中写通过姓名查询的方法
--Service中判断是否找到该员工 返回boolean值
-- Action中的验证方法 判断Boolean值 并设置对应的data数据
input.jsp写入相应的Ajax代码
tips:写完之后发现添加员工 Ajax并没有起卵用??????
-----<script type="text/javascript" src="/scripts/jquery-1.7.2.min.js"></script>
多了个/ wtf????
但这并没有什么卵用 还是不能验证????
$this.after("<font color='green'>Lastname可用!
></font>"); 再次粗心多了个>
然而用户名可用可以验证 ,不可用的情况还是不可以??????????
}else if(date=="0"){ ============data写成了date !!!!!!!!!!!!!!!
终于好了O(∩_∩)O
④修改员工信息
--带上Id 通过id查找对应的employee Dao--Service--Action
--表单回显 public String input(){
request.put("departments", departmentService.getAll());
return "input";
}
public void prepareInput(){
if(id!=null){
model=employeeService.get(id);
}
}
相关文章推荐
- Linux Generating SSH Keys
- ssh以及ssh的key认证
- Docker使用Dockerfile创建支持ssh服务自启动的容器镜像
- perl脚本实现限制ssh最大登录次数(支持白名单)
- rsync ssh 数据同步分析
- 搭建SSH时的思考和遇到的几个问题的解决方法
- SSH框架网上商城项目第9战之添加和更新商品类别功能实现
- SSH框架网上商城项目第7战之整合Struts2和Json
- SSH 使用原理 与解释
- SSH整合中 hibernate托管给Spring得到SessionFactory
- Linux VPS利用SSH重置ROOT密码的方法
- SSH框架网上商城项目第15战之线程、定时器同步首页数据
- SSH框架网上商城项目第18战之过滤器实现购物登录功能的判断
- ssh,scp自动登陆的实现方法
- linux下使用ssh远程执行命令批量导出数据库到本地
- shell脚本实现ssh自动登录功能分享
- linux下ssh安装与scp命令使用详解
- ssh项目环境搭建步骤(web项目)
- 脚本实现SSH登录邮件报警