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/> ...
随机推荐
- ActiveReports报表行号
=RunningValue(Fields!字段名称.Value, CountDistinct, "矩表分组名称") RunningValue(Fields!区域.Value, Co ...
- 【心理学CPCI收录,AP独立出版】 2023年应用心理学与现代化教育国际学术会议(ICAPME 2023)
[心理学CPCI收录,AP独立出版] 2023年应用心理学与现代化教育国际学术会议(ICAPME 2023) 大会官网:www.icapme.org 大会时间:2023年9月22-24日 大会地点: ...
- OpenSSH 服务配置与管理
SSH 是一种以安全的方式提供远程登陆的协议,也是目前远程管理Linux系统的首选方式,SSH由IETF的网络小组所制定,SSH为建立在应用层基础上的安全协议,SSH是目前较可靠,专为远程登录会话和其 ...
- C/C++ 实现简易HTTP服务器
#include <stdio.h> #include <stdlib.h> #include <process.h> #include <WinSock2. ...
- 3、Web前端学习规划:CSS - 学习规划系列文章
CSS作为Web前端开发的第2种重要的语言,笔者建议在学了HTML之后进行.CSS主要是对于HTML做一个渲染,其也带了一些语言语法函数,功能也非常强大. 1. 简介: CSS(层叠样式表)是一种用于 ...
- Mybatis 源码系列:领略设计模式在 Mybatis 其中的应用
目录 一.Builder模式 二.工厂模式 三.单例模式 四.代理模式 五.组合模式 六.模板方式模式 七.适配器模式 八.装饰器模式 九.迭代器模式 虽然我们都知道有23种设计模式,但是大多停留在概 ...
- ASP.NET Core分布式项目实战(Consent Controller Get请求逻辑实现)--学习笔记
任务20:Consent Controller Get请求逻辑实现 接着上一节的思路,实现一下 ConsentController 根据流程图在构造函数注入 IClientStore,IResourc ...
- 架构设计理念&模型
理念 今天我们还需要关注 DDD 吗?https://www.infoq.cn/article/should-we-focus-on-ddd 事件风暴:https://en.wikipedia.org ...
- JOISC 2022 记录
Day1 T1 Jail 操作很类似华容道.由于这题是可以树,同时每一个人走的都是最短路,这也就意味着不会出现通过好多个人一起的挪动来匀出空间. 所以如果合法,必然存在一种方案是每一次直接将一个人挪到 ...
- apache kafka-01-kafka 入门介绍
kafka 名字背后的故事 说到卡夫卡,不知道你脑海中第一个想到的是什么? 是<变形记>的作者弗兰兹·卡夫卡(Franz Kafka)?还是村上春树的<海边的卡夫卡>? 不知 ...