当前位置:网站首页>SSM 程序集
SSM 程序集
2022-07-06 02:01:00 【hjhcos】
文章目录
简介
SSM 程序集是 Spring + SpringMVC + MyBatis 框架的整合,将系统划分为视图层、控制层、服务层、数据层。
controller 控制器会去使用 service 服务;service 服务会去使用 mapper 数据映射并且将数据转化为 domain 数据对象;mapper 数据映射会去使用 domain 定义数据类型。
entity:数据对象,可以减少数据处理过程。
model:在 entity 基础上进行改进,使数据更加人性化。
domain:在 model 基础上对数据源进行扩展整合,可以丰富数据多样化。
控制器注册
通过 @Controller 和 @RestController 注解可以将控制器自动注册到项目中,这样再通过 @RequestMapping 注解就可以将请求映射,一般就可以访问到页面或数据了。
顺便说一下 @RestController = @Controller + @ResponseBody,其源码基本一样。
控制器被扫描
当类上面使用了 @Controller 来进行控制器注册且能够被 Spring 应用扫描到分两种情况:
外部依赖进行引用到项目里面
你大概可以理解为当控制器不在当前工程里面,而是在工程的依赖包里面,例如 SpringSecurity 默认的登录页面,就是通过外部模块来进行引用的。
与 Spring 应用启动类同级自动扫描
spring-boot-starter-web
文档:https://www.yiibai.com/spring-boot/spring-boot-starter-web.html
spring-boot-starter-web 集成包包括了 web、webmvc 和 tomcat 。
因此 tomcat 服务器和 Spring MVC 框架是会自动配置,极大地减少了开发量。
如果你希望自行配置服务器,也可以将 spring-boot-starter-tomcat 排除项目从而不使用 tomcat 服务器。
mybatis-spring-boot-starter
mybatis-spring-boot-starter 集成包是对 MyBatis + MyBatis-Spring + SpringBoot 的集成封装,因此依赖性比较强,但是极大地减少了开发量,你可以不用去配置 SqlSessionFactory 和事务处理。
功能
自动发现存在的数据源
利用 SqlSessionFactoryBean 创建并注册 SqlSessionFactory
创建并注册 SqlSessionTemplate
自动扫描 Mapper,并注册到 Spring 上下文环境方便程序的注入使用
默认情况会查找以 @Mapper 注解标记的映射器,除此之外其实可以通过 @MapperScan 注解来扫描包。
MyBatis
MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。
SqlSession
SqlSessions 是由 SqlSessionFactory 实例创建的。SqlSessionFactory 对象包含创建 SqlSession 实例的各种方法。而 SqlSessionFactory 本身是由 SqlSessionFactoryBuilder 创建的,它可以从 XML、注解或 Java 配置代码来创建 SqlSessionFactory。
XML 映射器
元素标签
| 标签 | 描述 |
|---|---|
| cache | 命名空间的缓存配置 |
| cache-ref | 引用其它命名空间的缓存配置 |
| resultMap | 描述如何从数据库结果集中加载对象 |
| sql | sql 语句,可被其它语句引用的可重用语句块 |
| insert | 映射插入语句 |
| update | 映射更新语句 |
| delete | 映射删除语句 |
| select | 映射查询语句 |
元素属性
| 属性 | 值 | 默认值 | 场景 | 描述 |
|---|---|---|---|---|
| id | string | —— | [select | update |
| parameterType | object | unset | [select | update |
| resultType | object | —— | [select | update |
| resultMap | object | —— | [select | update |
| flushCache | boolean | false | [select | update |
| useCache | boolean | true | select | 该语句被调用会导致会导致其结果被二级缓存缓存起来。 |
| timeout | int | unset | [select | update |
| fetchSize | int | unset | [select | update |
| resultOrdered | boolean | false | [select] | 如果为true,将会假设包含了嵌套结果集或是分组,当返回一个主结果行时,就不会产生对前面结果集的引用。这就使得在获取嵌套结果集的时候不至于内存不够用。 |
| resultSets | [object…] | —— | [select] | 这个设置仅适用于多结果集的情况。它将列出语句执行后返回的结果集并赋予每个结果集一个名称,多个名称之间以逗号分隔。 |
| useGeneratedKeys | boolean | false | [insert | update] |
| keyProperty | string | unset | [insert | update] |
| keyColumn | string | —— | [insert | update] |
\
边栏推荐
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
- 2022年PMP项目管理考试敏捷知识点(8)
- 抓包整理外篇——————状态栏[ 四]
- Gbase 8C database upgrade error
- leetcode3、實現 strStr()
- Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
- Ali test open-ended questions
- Install redis
- Use Scrollview and tabhost to realize vertical scrollbars and tabs
猜你喜欢

Open source | Ctrip ticket BDD UI testing framework flybirds

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!

Online reservation system of sports venues based on PHP

Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械

Spark accumulator

Using SA token to solve websocket handshake authentication

Prepare for the autumn face-to-face test questions

SQL statement

Overview of spark RDD
随机推荐
Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
GBase 8c数据库升级报错
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
[network attack and defense training exercises]
[depth first search notes] Abstract DFS
[coppeliasim] efficient conveyor belt
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
MySQL learning notes - subquery exercise
Extracting key information from TrueType font files
Use image components to slide through photo albums and mobile phone photo album pages
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Redis string type
[flask] official tutorial -part2: Blueprint - view, template, static file
Overview of spark RDD
Thinking about the best practice of dynamics 365 development collaboration
This time, thoroughly understand the deep copy
Reasonable and sensible