SSH注解整合项目(struts2+Spring+Hibernate)客户关系管理系统

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等等**

image
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)]

  • 27
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值