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数组
随机推荐
- SpringMVC学习笔记(三)
一.SpringMVC使用注解完成 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--configure the setti ...
- My97DatePicker 日期控制,开始时间不能>结束时间,结束时间不能<开始时间
<li>日期: <input type="text" style="margin-top: 5px;" value="${begin ...
- Python语法三
1. from os.path import exists import 了又一个很好用的命令 exists.这个命令将文件名字符串作为参 数,如果文件存在的话,它将返回 True,否则将返回 Fal ...
- [delphi]SetWindowsHookExA函数入口处修改
library Project2; uses SysUtils, Classes, windows, Dialogs; {$R *.res} function GetModuleHandleA(a: ...
- ECshop 数据库表结构
-- 表的结构 `ecs_account_log`CREATE TABLE IF NOT EXISTS `ecs_account_log` (`log_id` mediumint(8) unsigne ...
- bootstrap--小李子demo
最近忙啊...看到各位冬鞋都在认真写博客,认真敲代码,认真工作,总觉得自己时间太少,总觉得时间不够,老了...... 进正题: 上次不知从哪里(忘了)下载了bootstrap的一些使用小demo,以后 ...
- 9.5.8 Optimizing InnoDB Disk I/O
如果你数据库设计以及sq操作都是最佳实践,但是你数据库仍然被较重的io活动拖累的较慢,那么试一试看看top或者windows的任务管理器,cpu使用率和工作量低于70%,那么或许是您的硬盘较慢. 1 ...
- JavaScript 中this与Dom中的注意
对于下面这段代码: <script type='text/javascript'> function testThis() { console.log(this); } </scri ...
- easyui datagrid 没数据时显示滚动条的解决方法
今天解决了一个bug,因为datagrid有多列,可是当没有数据的时候,后面的列无法通过滚动条拉动来显示,比较麻烦,而需求要求没有数据也要拉动滚动条查看后面有什么列,一开始在网上找了一些资料,发现都不 ...
- hive中分号问题
分号是sql的结束符,在hql中亦如此,但是hive对分号的识别没有那么智能,如下: select concat(';','aa') from lhc limit 1; FAILED: Parse E ...