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/> ...
随机推荐
- TienChin 活动管理-设置活动的默认状态
// 设置活动未过期,相当于新增的活动,默认都是未过期的 activity.setActivityStatus(1);
- Docker 安装 MySQL8 数据库
创建数据卷 mkdir -p /usr/mysql/conf /usr/mysql/data chmod -R 755 /usr/mysql/ 创建配置文件 vim /usr/mysql/conf/m ...
- 【Jmeter】基础介绍-详细
最近做压测时使用到Jmeter,为什么用它,之前也做过部分压测,不是很系统,使用的是Apache Bench,虽然效率高,但是功能比较简单,不太适合本次压测场景,另外Jmeter能更好的利用压测机的多 ...
- 最好的个人博客评论区实现方案推荐:waline
我的博客一直没有一个好看的评论区,自己做又不会..没错,我是个前端渣渣.调研了一下,一开始想套用一些网上的静态模板,但是改造成本还是挺大的,后来接触到了Waline,简单了解了以下,我就知道了,它就是 ...
- 零基础入门Vue之To be or not to be——条件渲染
温故 上一节:零基础入门Vue之皇帝的新衣--样式绑定 在前面的内容能了解到,Vue不仅仅能进行数据渲染还可以对样式进行绑定 并且他能随意的切换样式,但Vue的初衷就是尽量少让使用者操作dom节点 加 ...
- Python-pymysql操作MySQL数据库
一.安装pymysql py -m pip install pymysql; 二.pymysql数据库操作 1.简单示例 #coding=utf-8 import pymysql ## 打开数据库连接 ...
- 《AI驱动下的开发者新生态》-2024长沙.NET技术社区活动-诚邀大家报名
回顾 2019年初,在.NET中文社区及包括苏州.广州.深圳等地区社区等大力推动.在众多企业的大力支持下,长沙地区的开发者们发起成立了长沙.NET技术社区,并组织了<2019年长沙开发者技术大会 ...
- python实现百度贴吧页面爬取
import requests class TiebaSpider: """百度贴吧爬虫类""" def __init__(self, ti ...
- typescript 实现enum枚举值定义为对象
壹 ❀ 引 最近因为有一些闲散时间,所以一直在做将Class组件重构为typescript + hooks组件的工作,结果今天就遇到一个有趣的问题.我们知道react Class组件一般都会定义Com ...
- 从零开始的react入门教程(八),redux起源与基础用法
壹 ❀ 引 我们在从零开始的react入门教程(七),react中的状态提升,我们为什么需要使用redux一文中介绍了react的状态提升,对于不同组件之间状态需要通信时,将状态提升至两个组件共有的最 ...