添加图书
操作步骤:
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