Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions struts2/struts2/src/util/BeanToMapUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* javabean和map相互转换
*
*/
public class BeanToMapUtil {

/**
* 将一个 Map 对象转化为一个 JavaBean
* @param type 要转化的类型
* @param map 包含属性值的 map
* @return 转化出来的 JavaBean 对象
* @throws IntrospectionException
* 如果分析类属性失败
* @throws IllegalAccessException
* 如果实例化 JavaBean 失败
* @throws InstantiationException
* 如果实例化 JavaBean 失败
* @throws InvocationTargetException
* 如果调用属性的 setter 方法失败
*/
public static Object convertMap(Class type, Map map)
throws IntrospectionException, IllegalAccessException,
InstantiationException, InvocationTargetException {
BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性
Object obj = type.newInstance(); // 创建 JavaBean 对象

// 给 JavaBean 对象的属性赋值
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i< propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();

if (map.containsKey(propertyName)) {
// 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。
Object value = map.get(propertyName);

Object[] args = new Object[1];
args[0] = value;

descriptor.getWriteMethod().invoke(obj, args);
}
}
return obj;
}

/**
* 将一个 JavaBean 对象转化为一个 Map
* @param bean 要转化的JavaBean 对象
* @return 转化出来的 Map 对象
* @throws IntrospectionException 如果分析类属性失败
* @throws IllegalAccessException 如果实例化 JavaBean 失败
* @throws InvocationTargetException 如果调用属性的 setter 方法失败
*/
public static Map convertBean(Object bean)
throws IntrospectionException, IllegalAccessException, InvocationTargetException {
Class type = bean.getClass();
Map returnMap = new HashMap();
BeanInfo beanInfo = Introspector.getBeanInfo(type);

PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i< propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (!propertyName.equals("class")) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean, new Object[0]);
if (result != null) {
returnMap.put(propertyName, result);
} else {
returnMap.put(propertyName, "");
}
}
}
return returnMap;
}
}
33 changes: 33 additions & 0 deletions struts3/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.generic_5.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.jstl_1.2">
<attributes>
<attribute name="owner.project.facets" value="jst.web.jstl"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-fileupload-1.2.1.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/freemarker-2.3.13.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jcommon-1.0.12.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfreechart-1.0.9.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-5.0.8-bin.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/ognl-2.6.11.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts2-core-2.1.6.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts2-jfreechart-plugin-2.1.6.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/xwork-2.1.2.jar"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>
13 changes: 13 additions & 0 deletions struts3/.mymetadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-module
type="WEB"
name="struts2"
id="myeclipse.1464226976646"
context-root="/struts2"
j2ee-spec="5.0"
archive="struts2.war">
<attributes>
<attribute name="webrootdir" value="WebRoot" />
</attributes>
</project-module>

58 changes: 58 additions & 0 deletions struts3/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>struts3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions struts3/.settings/.jsdtscope
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="WebRoot"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
5 changes: 5 additions & 0 deletions struts3/.settings/com.genuitec.eclipse.migration.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
performed.operation.me.create.deploymentAssembly=1.0
performed.operation.me.create.deploymentAssembly.fixBuildPathEntries=1.0
performed.operation.me.install.jstl=1.0
performed.operation.migrate.container.ids=1.0
8 changes: 8 additions & 0 deletions struts3/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Thu May 26 09:42:57 CST 2016
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
9 changes: 9 additions & 0 deletions struts3/.settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="struts2">
<wb-resource deploy-path="/" source-path="/WebRoot" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="java-output-path" value="/struts2/WebRoot/WEB-INF/classes"/>
<property name="me-merge-utility-modules" value="true"/>
<property name="context-root" value="/struts3"/>
</wb-module>
</project-modules>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>

<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web.jstl" version="1.2"/>
</faceted-project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
1 change: 1 addition & 0 deletions struts3/.settings/org.eclipse.wst.jsdt.ui.superType.name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Window
3 changes: 3 additions & 0 deletions struts3/WebRoot/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

53 changes: 53 additions & 0 deletions struts3/WebRoot/NewFile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row-fluid">
<div class="span6">
<form action="login" method="post" namespace="/">
<div class="control-group">
<label class="control-label" for="inputEmail">账号</label>
<div class="controls">
<input name="username" id="username" type="text" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">密码</label>
<div class="controls">
<input name="userpwd" id="userpwd" type="password" />
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox"><input type="checkbox" /> Remember me</label> <button type="submit" class="btn">登陆</button>
</div>
</div>
</form>
</div>
<div class="span6">
</div>
</div>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions struts3/WebRoot/WEB-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/classes/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added struts3/WebRoot/WEB-INF/lib/jcommon-1.0.12.jar
Binary file not shown.
Binary file added struts3/WebRoot/WEB-INF/lib/jfreechart-1.0.9.jar
Binary file not shown.
Binary file not shown.
Binary file added struts3/WebRoot/WEB-INF/lib/ognl-2.6.11.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added struts3/WebRoot/WEB-INF/lib/xwork-2.1.2.jar
Binary file not shown.
26 changes: 26 additions & 0 deletions struts3/WebRoot/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>Struts Blank</display-name>

<filter>
<!-- 配置Struts2核心Filter的名字 -->
<filter-name>struts2</filter-name>
<!-- 配置Struts2核心Filter的实现类 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>
<!-- 配置Filter拦截的URL -->
<filter-mapping>
<!-- 配置Struts2的核心FilterDispatcher拦截所有用户请求 -->
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>

</web-app>
Loading