当前位置:网站首页>三层项目的架构分析及构造方法的参数名称注入
三层项目的架构分析及构造方法的参数名称注入
2022-07-29 05:07:00 【是庸医啊】
目录
三层项目的架构分析
使用三层架构进行用户的插入操作
界面层,业务逻辑层,数据访问层(模拟)
Spring会接管三层架构中哪些对象的创建?界面层的对象,业务逻辑层的对象,数据访问层的对象。
非Spring接管下的三层项目构建:
实体类
com.bjpowernode.pojo Users
数据访问层
com.bjpowernode.dao UsersMapper.java(接口)
UsersMapperImpl.java(实现类)
业务逻辑层
com.bjpowernode.service UsersService.java(接口)
UsersServiceImpl.java(实现类 )
界面层
com.bjpowernode.controller UsersController.java
接下里我们继续搭建一个框架



然后创建一个新的实体类


实体类里面的set、get方法都要加!(Alt+Insert)



spring接管三层对象的创建
数据访问层的逻辑对象

业务逻辑层
界面层

最后一步就是测试
测试的三个步骤要搞得明明白白!一定!
使用构造方法参数名称注入值
使用构造方法的参数名称进行注入值
Student stu = new Student("张三",22);
a.使用构造方法的参数名称进行注入值
<bean id="school" class="com.bjpowernode.pojo3.School">
<constructor-arg name="name1" value="清华大学"></constructor-arg>
<constructor-arg name="address1" value="海淀区"></constructor-arg>
</bean>
c.使用默认的构造方法的参数的顺序注入值
<bean id="stuSequence" class="com.bjpowernode.pojo3.Student">
<constructor-arg value="陈十"></constructor-arg>
<constructor-arg value="22"></constructor-arg>
<constructor-arg ref="school"></constructor-arg>
</bean>

然后我们测试一下
构造方法的名称作为注入值

使用构造方法参数的下标进行注入值
b.使用构造方法参数的下标注入值
<bean id="stu" class="com.bjpowernode.pojo3.Student">
<constructor-arg index="0" value="钱七"></constructor-arg>
<constructor-arg index="1" value="22"></constructor-arg>
<constructor-arg index="2" ref="school"></constructor-arg>
</bean>



使用构造方法默认的参数进行赋值



边栏推荐
- MySQL定时调用预置函数完成数据更新
- Conv2d of torch
- Vivo market API event reporting and docking
- How to install Office2010 installation package? How to install Office2010 installation package on computer
- 力扣------对奇偶下标分别排序
- 【2022新生学习】第三周要点
- 网安学习-内网安全1
- Big silent event Google browser has no title
- Simple user-defined authentication interface rules
- Google GTEST event mechanism
猜你喜欢

The method and detailed code of automatically pop-up and QQ group when players visit the website

How to install Office2010 installation package? How to install Office2010 installation package on computer
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Solution to the fourth game of 2022 Hangzhou Electric Multi school league

【无标题】

1 sentence of code, get asp Net core binds multiple sources to the same class

What if excel is stuck and not saved? The solution of Excel not saved but stuck

【2022新生学习】第三周要点

Sparksql inserts or updates in batches and saves data to MySQL

How is the entered query SQL statement executed?
随机推荐
PHP determines whether the user has logged in. If logged in, the home page will be displayed. If not, enter the login page or registration page
What if the office prompts that the system configuration cannot run?
ThreadPoolExecutor simple to use
How does word view document modification traces? How word views document modification traces
TCP three handshakes and four waves
P1009 [noip1998 popularization group] sum of factorials
How to install Office2010 installation package? How to install Office2010 installation package on computer
JS daily question (12)
"Invisible Bridge" built in the free trade economy: domestic products and Chinese AI power
Diagram of odoo development tutorial
JS daily question (10)
学习数据库的第一个程序
How to debug UDP port
JS (in ES6) sync & await understanding
Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
Conv1d of torch
Excel卡住了没保存怎么办?Excel还没保存但是卡住了的解决方法
IDEA中使用注解Test
tmux随笔
stack和queue和优先级队列(大堆和小堆)模拟实现和仿函数讲解