tnblog
首页
视频
资源
登录

IoC配置-读取properties文件信息 08

2803人阅读 2022/6/26 18:03 总访问:1099885 评论:0 收藏:0 手机
分类: spring


案例
1、在maven工程导入spring坐标

2、dao层的内容与结构
接口

实现类

3、server层的内容与结构

4、创建properties文件

5、配置文件样式

标签头代码:

<?xml version="1.0" encoding="UTF-8"?>
<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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">
</beans>

6、为dao层的UserDaoImpl实现类添加变量

7、在配置文件里配置properties文件的内容

编号1的代码:

 xmlns:context="http://www.springframework.org/schema/context"

编号2的代码:

 http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd

8、测试类的代码

小节

Spring读取properties文件数据

1.开启context支持

2.加载perperties文件
3.使用${}格式读取配置项${}与#{}进行区分(#{}是SQLEL表达式)


评价
没有个性,不需要签名
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术