Spring框架实现层间转换(注解)

本文详细介绍了使用Spring MVC框架添加图书的步骤,包括配置Spring、创建实体类、控制器、业务层和服务层,以及DAO层的接口和实现类,最后通过test进行应用验证。

添加图书

操作步骤:

1.jar包
< beans xmlns=“http://www.springframework.org/schema/beans
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xmlns:p=“http://www.springframework.org/schema/p
xmlns:context=“http://www.springframework.org/schema/context
xmlns:util=“http://www.springframework.org/schema/util
xsi:schemaLocation=“http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd”>
2.创建每一个层的包
在这里插入图片描述
3.创建实体类Book 写对应的属性,加get/set
在这里插入图片描述

配置applicationContex.xml
在这里插入图片描述
4.创建controller 现在是随便的一个class 控制器里填写方法
在这里插入图片描述
@Controller等价< bean name=“mc” class=“black.controller.MyController”> 调用时用类名
@Autowired 适用于没有get/set方法
等价< property name=“bd” ref=“bdi”>
5.创建业务层接口,声明方法
在这里插入图片描述
创建业务层实现类,实现方法**
在这里插入图片描述
@Service 等价< bean name=“bsi” class=“black.service.BookServiceImpl”>

**6.创建dao层接口,声明方法
在这里插入图片描述

创建dao层实现类,实现方法**
在这里插入图片描述
@Repository 相当于< bean name=“bdi” class=“black.dao.BookDaoImpl”>

7.test
加载applicationContex

在这里插入图片描述
getBean方法中MyController 改为myController

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值