spring 注入参数时为list map写法用例
导包基础:这了让服务器支持json 需要导入下面包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
这是一个基本类,++++++++++++++++++++++++++++++++++++++++++
package com.itheima.dao;
import java.lang.reflect.Array;
import java.util.*;
public class BookDaofff {
private int[] array;
private List<String> list;
private Set<String> set;
private Map<String, String> map;
private Properties properties;
public void setArray(int[] array){this.array = array;}
public void setList(List<String> list){this.list = list;}
public void setSet(Set<String> set){this.set = set;}
public void setMap(Map<String,String> map){this.map = map;}
public void setProperties(Properties properties){this.properties = properties;}
public void save(){
System.out.println("array"+ Arrays.toString(array));
System.out.println("list"+list);
System.out.println("set"+set);
System.out.println("map"+map);
System.out.println("properties"+ properties);
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++配置类+++++++++++++++++++++++++++++++++++++++++++=
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="BookDaofff" class="com.itheima.dao.BookDaofff">
<property name="array">
<array>
<value>100</value>
<value>200</value>
<value>300</value>
</array>
</property>
<property name="list">
<list>
<value>100</value>
<value>200</value>
<value>300</value>
</list>
</property>
<property name="set">
<set>
<value>100</value>
<value>200</value>
<value>300</value>
</set>
</property>
<property name="map">
<map>
<entry key = "country" value="china"/>
<entry key = "province" value="helan"/>
<entry key = "city" value="xxxxx"/>
</map>
</property>
<property name="properties">
<props>
<prop key = "country" >url</prop>
<prop key = "province">www</prop>
<prop key = "city" >heixxx</prop>
</props>
</property>
</bean>
</beans>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++使用类+++++++++++++++++++++++++++++++++++++++++=
package com.itheima.app;
import com.itheima.dao.BooDao;
import com.itheima.dao.BookDaofff;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Appfor {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("sp.xml");
BookDaofff bookDao = (BookDaofff) ctx.getBean("BookDaofff");
bookDao.save();
}
}
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++完结演示++++++++++++++++++++++++++++++++++++++++++++++++++++++++2022-7-22
spring 注入参数时为list map写法用例的更多相关文章
- spring注入参数详解
spring注入参数详解 在Spring配置文件中, 用户不但可以将String, int等字面值注入到Bean中, 还可以将集合, Map等类型的数据注入到Bean中, 此外还可以注入配置文件中定义 ...
- 关于Spring注入参数到static静态参数失败问题处理。解决Autowired annotation is not supported on static fields的问题
直接贴代码 把注入参数的注解加到set方法上面去即可. 因为这是一个工具类用到的config,所以一开始没有加@Component,还是依然为空,加上之后就正常能注入了
- FlushMode属性与transaction(spring注入的事务)
一.参见hibernate的api http://tool.oschina.net/apidocs/apidoc?api=hibernate-3.6.10 http://tool.oschina.ne ...
- mybatis中collection子查询注入参数为null
具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...
- spring mvc 3.1的自动注入参数遇到的问题
在网上下载了xheditor作为页面的编辑器,编辑内容后post到后台保存,后台方法用spring mvc的自动注入的方式接收参数. 这种方式在各个浏览器下运行良好,但是在ie11下发现,从word. ...
- MyBatis传入参数为list、数组、map写法(转载)
MyBatis传入参数为list.数组.map写法 1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item ...
- Spring属性注入、构造方法注入、工厂注入以及注入参数(转)
Spring 是一个开源框架. Spring 为简化企业级应用开发而生(对比EJB2.0来说). 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能.Spring ...
- Spring 依赖注入(二、注入参数)
注入参数基本分7类: 1.基本类型值 2.注入bean 3.内部bean 4.注入null值 5.级联属性 6.List,Set,Map集合的注入 7.properties文件的注入(和集合注入基本是 ...
- MyBatis传入参数为list、数组、map写法
1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item,index,collection,open,sep ...
- Spring中注入List,Set,Map,Properties的xml文件配置方法
下面的例子展示了如何注入 List – <list/> Set – <set/> Map – <map/> Properties – <props/> ...
随机推荐
- vs不同版本支持的c++版本和PlatformToolset,及在vs中切换c++版本
找c++资料从网上找确实更快速,但要想深入地理解vc++建议看msdn文档. vs不同版本支持的c++版本 C++17: vs2017基本支持,vs2015部分支持. C++14: vs2017就可以 ...
- 4.基于Label studio的训练数据标注指南:情感分析任务观点词抽取、属性抽取
情感分析任务Label Studio使用指南 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取).文本分类等 2.基于Label studio的训练数据标注指南:(智能文档) ...
- VUE3子表格嵌套分页查询互相干扰的问题解决
VUE3在表格中嵌套子表格子表格的分页查询互相干扰的问题解决 简单嵌套 如果不需要做子表格的分页查询,那么可以直接在主表格中嵌套子表格,有两种方式:一种是主表格加载的同时加载子表格数据,另一种是点击展 ...
- 解决.netWebAPI输出时间格式带T问题
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add( new Ne ...
- 一篇带你掌握cmake入门|了解cmake|掌握cmake基本操作
一篇带你掌握cmake入门 内容出处: 作者: 苏丙榅 链接: https://subingwen.cn/cmake/CMake-primer/ 来源: 爱编程的大丙 著作权归作者所有.商业转载请联系 ...
- Springboot创建项目、docker安装mysql及mybatis-plus调试
Springboot创建项目及测试 1️⃣ idea构建springboot项目 2️⃣ 测试类 hello 1. 代码 RestController是ResponseBody + controlle ...
- P7167 [eJOI2020 Day1] Fountain 题解
题目链接:Fountain 很不错的基础算法组合题:单调栈+倍增 首先考虑到一个事实,就是下面第一个比当前半径大的位置会成为移动的第一次落脚点,抽象下就是下面出现的第一次比自身大的半径,这个问题显然可 ...
- shell 两个数组比较,得到元素的并集、交集等
linux shell 实现数组比较,取元素的并集.交集时,可以使用sort排序.uniq统计和awk数据过滤. shell 实现如下 file_list_1=("test1" & ...
- 洛谷P2670 扫雷游戏 关于区域搜索标记的坐标增量法
最简单的思路就是扫描一边所有节点,对每个非地雷节点,去检查一下他八个方向的元素是否有'*',有的话就加一 但是逐个写出有点麻烦,我们不妨定义两个增量数组来存储每一次的相对位移,对每次检查只需要遍历这个 ...
- 【Flink入门修炼】1-2 Mac 搭建 Flink 源码阅读环境
在后面学习 Flink 相关知识时,会深入源码探究其实现机制.因此,需要现在本地配置好源码阅读环境. 本文搭建环境: Mac M1(Apple Silicon) Java 8 IDEA Flink 官 ...