java中用spring实现数组类型输出
java 中的几个数组类型
1、Department类
package com.yy.collection; import java.util.List;
import java.util.Map;
import java.util.Set; public class Department {
private String name;
private String [] empName;
private List<Employee> empList;
private Set<Employee> empsets;
private Map<String,Employee> empMaps; public Map<String, Employee> getEmpMaps() {
return empMaps;
}
public void setEmpMaps(Map<String, Employee> empMaps) {
this.empMaps = empMaps;
}
public Set<Employee> getEmpsets() {
return empsets;
}
public void setEmpsets(Set<Employee> empsets) {
this.empsets = empsets;
}
public List<Employee> getEmpList() {
return empList;
}
public void setEmpList(List<Employee> empList) {
this.empList = empList;
}
public String[] getEmpName() {
return empName;
}
public void setEmpName(String[] empName) {
this.empName = empName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }
2.Employee类
package com.yy.collection;
public class Employee {
private String name;
private int id;
public String getName() {
return name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}
3.beans.xml配置文件
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- 在容器文件中配置bean(service/dao/domain/action/数据源) -->
<bean id="department" class="com.yy.collection.Department">
<property name ="name" value="财务部"></property> <!-- 给list注入值 --> <property name="empName">
<list>
<value>小明</value>
<value>小小明</value>
<value>迷你明</value>
</list> </property>
<!-- 给list注入值 -->
<property name="empList">
<list>
<ref bean="emp1"/>
<ref bean="emp2"/> </list>
</property>
<!-- 给set注入值 -->
<property name="empsets">
<set>
<ref bean="emp2"/>
<ref bean="emp1"/>
</set>
</property>
<!-- 给map注入值 只要map不一样,就可以显示 -->
<property name="empMaps">
<map>
<entry key="11" value-ref="emp1" />
<entry key="22" value-ref="emp2"/>
</map>
</property>
</bean>
<bean id="emp1" class="com.yy.collection.Employee">
<property name="name" value="地址1" />
<property name="id" value="1" />
</bean>
<bean id="emp2" class="com.yy.collection.Employee">
<property name="name" value="地址2"/>
<property name="id" value="2" />
</bean>
</beans>
4.应用App1类
package com.yy.collection; import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class App1 { public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx=new ClassPathXmlApplicationContext("com/yy/collection/beans.xml");
Department department=(Department) ctx.getBean("department");
System.out.println(department.getName());
for (String emName:department.getEmpName()){
System.out.println(emName); }
System.out.println("******通过list集合取出数据*****");
for(Employee array:department.getEmpList()){
System.out.println( "name="+array.getName()+""+array.getId()); }
System.out.println("******通过set集合取出数据*****");
for(Employee array:department.getEmpsets()){
System.out.println( "name="+array.getName()); } System.out.println("*****通过map集合取出数据*****");
//1.迭代器
Map<String,Employee>empmaps=department.getEmpMaps();
Iterator it=empmaps.keySet().iterator();
while(it.hasNext()){
String key=(String) it.next();
Employee emp=empmaps.get(key);
System.out.println("key="+key+""+emp.getName()); } //2、简洁方法 for( Entry<String, Employee> entry1:department.getEmpMaps().entrySet()){
System.out.println(entry1.getKey()+""+entry1.getValue().getName());
}
} }
java中用spring实现数组类型输出的更多相关文章
- java plsql 调用oracle数组类型
首先当然是在oracle中建立type CREATE OR REPLACE TYPE cux_proxy_bid_award_rec IS OBJECT ( trading_partner_id NU ...
- JAVA获取文件byte数组并输出进行展示和文件下载
/** * 文件下载 */ @GetMapping(value = "/download") public void download(HttpServletResponse re ...
- Java BasicNameValuePair怎么传数组类型的参数?
BasicNameValuePair 传数组的话可以这样传 map.put("ids[]", 1); map.put("ids[]", 2);
- Java基础_0306:数组的定义与使用
数组 数组指的就是一组相关变量的集合.例如:如果说现在要想定义100个整型变量,按照传统的思路,可能这样定义: int i1,i2 ,... i100,一共写100个变量. 以上的形式的确可以满足技术 ...
- java基础(十) 数组类型
1. 数组类简介 在java中,数组也是一种引用类型,即是一种类. 我们来看一个例子,理解一下数组类: public static void main(String[] args) { Class ...
- Java 学习(6):java Number & Math & String & 数组...常用类型
目录 --- Number & Math类 --- Character 类 --- String 类 --- StringBuffer 类 --- 数组 Number & Math类: ...
- Java之数组类型
如果我们有一组类型相同的变量.例如,5位同学的成绩,可以这么写 public class Main { public static void main(String[] args) { // 5位同学 ...
- java—数组乘积输入: 一个长度为n的整数数组input 输出: 一个长度为n的数组result,满足result[i] = input数组中,除了input[i] 之外的所有数的乘积,不用考虑溢出例如 input {2, 3, 4, 5} output: {60, 40, 30, 24}
/** * 小米关于小米笔试题 数组乘积输入: 一个长度为n的整数数组input 输出: 一个长度为n的数组result,满足result[i] = * input数组中,除了input[i] 之外的 ...
- Java 基础类型转换byte数组, byte数组转换基础类型
Java 基础类型转换byte数组, byte数组转换基础类型 Java类型转换 java类对象转化为byte数组
随机推荐
- 通过sqoop来传输mysql/oracle/vertica数据至HBASE
首先要注意将连接用的jar包,放到sqoop目录下,我的是/var/lib/sqoop 如果没有主键,则要加上-m 1 export正确的jdk目录 当做key的列必须唯一存在,不然报错 --mysq ...
- GPON和820.1p学习及资料(zt)
1)hw的两个PPT不错,GPON技术基础.ppt和10G-GPON技术基础.ppt, 介绍了GPON的知识背景,标准的名称,帧协议. 尤其是详细对比了10G-PON和G-PON的区别,以及演进的道路 ...
- Android-monkey稳定性测试(多台设备同时进行)
1.目的(原创文章,转载请注明出处-) 主要为指引开展android平台应用的稳定性测试,尽可能地在应用发布前发现crash及an ...
- python基础知识8——模块1——自定义模块和第三方开源模块
模块的认识 模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需 ...
- [Tomcat 源码分析系列] (二) : Tomcat 启动脚本-catalina.bat
概述 Tomcat 的三个最重要的启动脚本: startup.bat catalina.bat setclasspath.bat 上一篇咱们分析了 startup.bat 脚本 这一篇咱们来分析 ca ...
- FreeMaker实现变量求和
今天在项目上遇到统计分页页面的某个字段的总和,前台页面是使用FreeMaker实现的,记录一下: <#assign tprice = 0 > <#list orderlist ...
- Qt窗口添加鼠标移动拖拽事件
1. .h文件中添加 private: QPoint dragPosition; 2. 在cpp文件中重写鼠标点击和拖拽函数 void ShapeWidget::mousePressEvent( ...
- php的进制转换
学习了php的进制转换,有很多的知识点,逻辑,也有最原始的笔算,但是我们还是习惯使用代码来实现进制的转换,进制的转换代码有如下:二进制(bin)八进制( oct)十进制( dec)十六进制( hex) ...
- wcf用svcutil导出泛型的元数据
D:\aaa>svcutil net.tcp://192.168.1.110:44444/TradingsService.svc/mex /ct:System.Collections.Gener ...
- jQuery插件制作方法
html页面:<h1>Hello My name is Alex,i from china.</h1> 1.无参数实现文字阴影效果 测试代码: $("h1" ...