spring boot 请求处理-源码分析-Model,Map原理

无论是Map还是Model类型都是调用mavContainer.getModel(),Model全称是
 BindingAwareModelMap(不仅是model也是map).目标方法执行完后,
由于Map与Model被对应的参数解析器解析后,都变成mavContainer中的defaultModel,因此怎么将defaultModel的值放在请求域中的呢?

如果目标方法的返回值是字符串,那么就将它保存到mavContainer中.

目标方法执行完成将所有数据放在mavContainer中,在将mavContainer封装成mav.然后进行视图对象渲染,渲染的时候将参数放在请求域.

public class InternalResourceView extends AbstractUrlBasedView 
//AbstractUrlBasedView类的exposeModelAsRequestAttributes方法
protected void exposeModelAsRequestAttributes(Map<String, Object> model, HttpServletRequest request) throws Exception {
        model.forEach((name, value) -> {
            if (value != null) {
                request.setAttribute(name, value);
            } else {
                request.removeAttribute(name);
            }

        });
    }

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot中连接PostgreSQL有两种方式可以选择。第一种是使用JPA方式,需要在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> ``` 然后在application.yml文件中配置数据源和JPA相关的属性,例如: ```yaml spring: application: name: shipcenter datasource: driver-class-name: org.postgresql.Driver url: jdbc:postgresql://xxxxx:5432/leadtrans username: xxx password: xxx jpa: generate-ddl: false hibernate: ddl-auto: none naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl database: postgresql show-sql: false ``` 第二种方式是使用MyBatis-Plus,需要在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.4</version> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> ``` 然后在application.yml文件中配置数据源和MyBatis-Plus相关的属性,例如: ```yaml spring: application: name: shipcenter datasource: driver-class-name: org.postgresql.Driver url: jdbc:postgresql://xxxxx:5432/leadtrans username: xxxx password: xxxx mybatis-plus: configuration: map-underscore-to-camel-case: false global-config: db-config: update-strategy: ignored ``` 以上是两种连接PostgreSQL的方式,你可以根据自己的需求选择其中一种来配置连接。 #### 引用[.reference_title] - *1* *2* [springboot 连接 postgresql](https://blog.csdn.net/hanjun0612/article/details/124979184)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [IDEA spring boot 连接Postgresql配置 【已解决】](https://blog.csdn.net/qq_40651609/article/details/88366664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值