jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///ssh3
jdbc.username=root
jdbc.password=root
(3)log4j.properties
direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
direct messages to file mylog.log
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
set log levels - for more verbose logging change ‘info’ to ‘debug’
error warn info debug trace
log4j.rootLogger= info, stdout
(4)applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://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: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">
<context:property-placeholder location=“classpath:jdbc.properties”/>
3、创建相关的包和类
(1)创建相关的包结构
(2)创建相关的类
Customer
package com.itzheng.ssh.domain;
/*
- 客户管理的实体
*/
public class Customer {
}
CustomerDao
package com.itzheng.ssh.dao;
/*
- 客户管理DAO的接口
*/
public interface CustomerDao {
}
CustomerDaoImpl
package com.itzheng.ssh.dao.impl;
import com.itzheng.ssh.dao.CustomerDao;
/*
- 客户管理DAO的实现类
*/
public class CustomerDaoImpl implements CustomerDao {
}
CustomerService
package com.itzheng.ssh.service;
/*
- 客户管理的Service的接口
*/
public interface CustomerService {
}
CustomerServiceImpl
package com.itzheng.ssh.service.impl;
import com.itzheng.ssh.service.CustomerService;
/*
- 客户管理的Service的实现类
*/
public class CustomerServiceImpl implements CustomerService{
}
CustomerAction
package com.itzheng.ssh.web.action;
import com.itzheng.ssh.domain.Customer;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class CustomerAction extends ActionSupport implements ModelDriven{
//模型驱动使用的对象
private Customer customer = new Customer();
@Override
public Customer getModel() {
// TODO Auto-generated method stub
return customer;
}
}
4、引入相关页面
引入页面下载地址:https://download.csdn.net/download/qq_44757034/12615556
1、修改customer下的add.jsp页面
2、编写CustomerAction的save方法
3、配置CustomerAction
(1)在Spring的当中配置Action ,将Action交给Spring去管理(使用注解方式)
- 开启组件扫描:
在appliactionContext.xml
- 在类上去添加注解:
将当前类交给Spring管理
(2)在struts中去配置Action,Action负责处理请求和页面跳转的
(3)测试跳转成功并且执行了Action当中的方法
4、Action去调用业务层
(1)Service交给Spring管理
在CustomerServiceImpl设置
(2)Action中注入Service
在CustomerAction当中
(3)在Action的方法当中调用业务层
在CustomerAction的save方法当中
(4)测试
5、在Service中调用DAO
(1)将DAO交给Spring管理
(2)在Service当中注入DAO
- 在CustomerServiceImpl当中注入dao并调用DAO
- dao以及对应的实现类
(3)测试
6、创建实体和映射(映射使用的是注解)
- 映射要使用注解来实现(将表和类建立关系,将表当中的字段和类当中的属性建立关系)
在Customer上加一个实体注解
7、在Spring当中去整合Hibernate
在appliactionContext.xml当中
<?xml version="1.0" encoding="UTF-8"?><beans xmlns=“http://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:tx=“http://www.springframework.org/schema/tx”
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
最后
现在正是金三银四的春招高潮,前阵子小编一直在搭建自己的网站,并整理了全套的**【一线互联网大厂Java核心面试题库+解析】:包括Java基础、异常、集合、并发编程、JVM、Spring全家桶、MyBatis、Redis、数据库、中间件MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty等等**
ingframework.org/schema/context"
xmlns:aop=“http://www.springframework.org/schema/aop”
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
最后
现在正是金三银四的春招高潮,前阵子小编一直在搭建自己的网站,并整理了全套的**【一线互联网大厂Java核心面试题库+解析】:包括Java基础、异常、集合、并发编程、JVM、Spring全家桶、MyBatis、Redis、数据库、中间件MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty等等**
[外链图片转存中…(img-BUqWXLPH-1721158506409)]