增加从数据库获取数据

master
wu ming 9 years ago
parent 16299374c6
commit 4dc7174746

@ -34,14 +34,28 @@
</layout>
</appender>
<!-- 输出日志到文件 -->
<appender name="file" class="org.apache.log4j.FileAppender">
<param name="File" value="d:/logs/file.log"></param>
<param name="Threshold" value="info"></param>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}-%m%n"></param>
</layout>
</appender>
<logger name="com.ibatis" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.Connection" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.Statement" additivity="true">
<level value="DEBUG" />
</logger>
<logger name="java.sql.PreparedStatement" additivity="true">
<level value="DEBUG" />
<appender-ref ref="IBatis" />
</logger>
<logger name="java.sql.ResultSet" additivity="true">
<level value="DEBUG" />
<appender-ref ref="IBatis" />
</logger>
<!-- 定义全局的日志输出级别,但是在输出目的地的配置中配置的具体输出级别优先级高于全局定义的优先级。 如果在railyFile中定义<param
name="Threshold" value="info"></param>那么将会把info以上级别的信息输出 -->
<root>

@ -4,8 +4,11 @@
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="EncodedInfoEntity" type="com.platform.beans.EncodedInfoEntity"/>
<typeAlias alias="EncodedInfoEntity" type="com.platform.entities.EncodedInfoEntity" />
<typeAlias alias="DataInfoEntity" type="com.platform.entities.DataInfoEntity" />
<typeAlias alias="PagerOptions" type="com.platform.entities.PagerOptions"/>
</typeAliases>
<mappers>
<mapper resource="com/dao/mapper/data-detaisl-mapper.xml" />
</mappers>
</configuration>

@ -24,26 +24,16 @@
<property name="url" value="${jdbc.mysql.url}" />
<property name="username" value="${jdbc.mysql.username}" />
<property name="password" value="${jdbc.mysql.password}" />
<property name="initialSize" value="${jdbc.initialSize}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}" />
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
</bean>
<bean id="mySQLSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="WEB-INF/config/mybatis-applicationConfig.xml" />
<property name="dataSource" ref="mySQLDataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.platform.dao" />
<property name="basePackage" value="com.platform.dao,com.dao.mapper" />
</bean>
<!-- 配置声明式事物 事物管理器 -->
<!-- 配置声明式事物 -->
<bean id="mySQLTxManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="mySQLDataSource" />
@ -53,37 +43,30 @@
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="get*" read-only="true" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="pointcut"
expression="execution(* com.platform.service.*.*(..))" />
<aop:pointcut expression="execution(* com.platform.service.*.*(..))"
id="pointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config>
<!-- 连接oracle数据库 -->
<!-- <bean id="oracleDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.oracle.driver}" />
<property name="url" value="${jdbc.oracle.url}" />
<property name="username" value="${jdbc.oracle.username}" />
<property name="password" value="${jdbc.oracle.password}" />
<property name="initialSize" value="${jdbc.initialSize}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}" />
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
</bean> -->
<!-- <bean id="oracleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close"> <property name="driverClassName" value="${jdbc.oracle.driver}"
/> <property name="url" value="${jdbc.oracle.url}" /> <property name="username"
value="${jdbc.oracle.username}" /> <property name="password" value="${jdbc.oracle.password}"
/> <property name="initialSize" value="${jdbc.initialSize}" /> <property
name="minIdle" value="${jdbc.minIdle}" /> <property name="maxIdle" value="${jdbc.maxIdle}"
/> <property name="maxActive" value="${jdbc.maxActive}" /> <property name="maxWait"
value="${jdbc.maxWait}" /> <property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"
/> <property name="removeAbandoned" value="${jdbc.removeAbandoned}" /> <property
name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" /> <property
name="testWhileIdle" value="${jdbc.testWhileIdle}" /> <property name="timeBetweenEvictionRunsMillis"
value="${jdbc.timeBetweenEvictionRunsMillis}" /> <property name="numTestsPerEvictionRun"
value="${jdbc.numTestsPerEvictionRun}" /> <property name="minEvictableIdleTimeMillis"
value="${jdbc.minEvictableIdleTimeMillis}" /> </bean> -->
<context:component-scan base-package="com.platform.*">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.DataInfoDao">
<resultMap id="getEntityByText" type="DataInfoEntity">
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
<result property="regionalismCode" column="regionalism_code"
javaType="string" jdbcType="VARCHAR" />
<result property="cityName" column="city_name" javaType="string"
jdbcType="VARCHAR" />
<result property="districtName" column="district_name"
javaType="string" jdbcType="VARCHAR" />
<result property="systemCode" column="system_code" javaType="int"
jdbcType="INTEGER" />
<result property="systemName" column="system_name" javaType="string"
jdbcType="VARCHAR" />
<result property="dataType" column="data_type" javaType="string"
jdbcType="VARCHAR" />
<result property="dataVersion" column="data_version" javaType="int"
jdbcType="INTEGER" />
<result property="submittedBatch" column="submitted_batch"
javaType="string" jdbcType="VARCHAR" />
<result property="dataPath" column="data_path" javaType="string"
jdbcType="VARCHAR" />
<result property="charset" column="data_charset" javaType="string"
jdbcType="VARCHAR" />
<result property="collectingTime" column="collection_time"
javaType="string" jdbcType="DATE" />
<result property="collectorContacts" column="collector_contacts"
javaType="string" jdbcType="VARCHAR" />
<result property="collectorName" column="collector_name"
javaType="string" jdbcType="VARCHAR" />
<result property="year" column="data_year" javaType="string"
jdbcType="VARCHAR" />
</resultMap>
<sql id="conditionsFilters">
<if test="PagerOptions!=null">
<where>
<if test="PagerOptions.dataType!=null">
and data_details.data_type=#{PagerOptions.dataType}
</if>
<if test="PagerOptions.submittedBatch!=null">
and
data_details.submitted_batch=#{PagerOptions.submittedBatch}
</if>
<if test="PagerOptions.cityName!=null">
and data_details.city_name=#{PagerOptions.cityName}
</if>
<if test="PagerOptions.districtName!=null">
and
data_details.district_name=#{PagerOptions.districtName}
</if>
<if test="PagerOptions.dataVersion">
and
data_details.data_version=#{PagerOptions.dataVersion}
</if>
<if test="PagerOptions.systemName">
and data_details=#{PagerOptions.systemName}
</if>
<if test="PagerOptions.dataYear">
and data_details.data_year=#{PagerOptions.dataYear}
</if>
<choose>
<when test="PagerOptions.idIndex>0">
and data_details.id>=#{idIndex}
</when>
<otherwise>
and data_details.id>=0
</otherwise>
</choose>
</where>
ORDER BY data_details.id
<if test="PagerOptions.limit">LIMIT #{PagerOptions.limit}</if>
</if>
</sql>
<select id="getLimitedDataInfoEntities" parameterType="PagerOptions"
resultMap="getEntityByText">
SELECT
id,regionalism_code,city_name,district_name,system_code,system_name,data_type,data_version,submitted_batch,data_path,data_charset,collection_time,collector_name,collector_contacts,data_year
FROM data_details
<include refid="conditionsFilters" />
</select>
<select id="getLimitedDataCount" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT COUNT(id) FROM data_details
<include refid="conditionsFilters" />
</select>
</mapper>

@ -26,6 +26,7 @@
<property name="password" value="${jdbc.mysql.password}" />
</bean>
<bean id="mySQLSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="/WebContent/WEB-INF/config/mybatis-applicationConfig.xml" />
<property name="dataSource" ref="mySQLDataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.DataInfoDao">
<resultMap id="getEntityByText" type="DataInfoEntity">
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
<result property="regionalismCode" column="regionalism_code"
javaType="string" jdbcType="VARCHAR" />
<result property="cityName" column="city_name" javaType="string"
jdbcType="VARCHAR" />
<result property="districtName" column="district_name"
javaType="string" jdbcType="VARCHAR" />
<result property="systemCode" column="system_code" javaType="int"
jdbcType="INTEGER" />
<result property="systemName" column="system_name" javaType="string"
jdbcType="VARCHAR" />
<result property="dataType" column="data_type" javaType="string"
jdbcType="VARCHAR" />
<result property="dataVersion" column="data_version" javaType="int"
jdbcType="INTEGER" />
<result property="submittedBatch" column="submitted_batch"
javaType="string" jdbcType="VARCHAR" />
<result property="dataPath" column="data_path" javaType="string"
jdbcType="VARCHAR" />
<result property="charset" column="data_charset" javaType="string"
jdbcType="VARCHAR" />
<result property="collectingTime" column="collection_time"
javaType="string" jdbcType="DATE" />
<result property="collectorContacts" column="collector_contacts"
javaType="string" jdbcType="VARCHAR" />
<result property="collectorName" column="collector_name"
javaType="string" jdbcType="VARCHAR" />
<result property="year" column="data_year" javaType="string"
jdbcType="VARCHAR" />
</resultMap>
<sql id="conditionsFilters">
<if test="PagerOptions!=null">
<where>
<if test="PagerOptions.dataType!=null">
and data_details.data_type=#{PagerOptions.dataType}
</if>
<if test="PagerOptions.submittedBatch!=null">
and
data_details.submitted_batch=#{PagerOptions.submittedBatch}
</if>
<if test="PagerOptions.cityName!=null">
and data_details.city_name=#{PagerOptions.cityName}
</if>
<if test="PagerOptions.districtName!=null">
and
data_details.district_name=#{PagerOptions.districtName}
</if>
<if test="PagerOptions.dataVersion">
and
data_details.data_version=#{PagerOptions.dataVersion}
</if>
<if test="PagerOptions.systemName">
and data_details=#{PagerOptions.systemName}
</if>
<if test="PagerOptions.dataYear">
and data_details.data_year=#{PagerOptions.dataYear}
</if>
<choose>
<when test="PagerOptions.idIndex>0">
and data_details.id>=#{idIndex}
</when>
<otherwise>
and data_details.id>=0
</otherwise>
</choose>
</where>
ORDER BY data_details.id
<if test="PagerOptions.limit">LIMIT #{PagerOptions.limit}</if>
</if>
</sql>
<select id="getLimitedDataInfoEntities" parameterType="PagerOptions"
resultMap="getEntityByText">
SELECT
id,regionalism_code,city_name,district_name,system_code,system_name,data_type,data_version,submitted_batch,data_path,data_charset,collection_time,collector_name,collector_contacts,data_year
FROM data_details
<include refid="conditionsFilters" />
</select>
<select id="getLimitedDataCount" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT COUNT(id) FROM data_details
<include refid="conditionsFilters" />
</select>
</mapper>

@ -0,0 +1,38 @@
package com.platform.controller;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.platform.entities.PagerOptions;
import com.platform.service.DataInfoService;
import com.platform.utils.UtilsHelper;
@Controller
public class DataModelController {
@Resource(name = "dataInfoService")
private DataInfoService dfs;
public void setDfsImp(DataInfoService dfs) {
this.dfs = dfs;
}
@RequestMapping("/data.json")
@ResponseBody
public ModelMap getAllDataToJson(HttpServletRequest res, HttpServletResponse req) {
Map<String, String[]> paramMap = res.getParameterMap();
Set<String> keySet= paramMap.keySet();
for(String str: keySet){
System.out.println(str+":"+paramMap.get(str));
}
return dfs.getPagerTableData((PagerOptions) UtilsHelper.newObjAndSetAttrsByClass(PagerOptions.class, res));
}
}

@ -0,0 +1,31 @@
package com.platform.dao;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.platform.entities.DataInfoEntity;
import com.platform.entities.PagerOptions;
@Repository(value = "dataInfoDao")
public interface DataInfoDao {
public List<DataInfoEntity> getLimitedDataInfoEntities(
@Param(value = "PagerOptions") PagerOptions pagerOptions);
public int getLimitedDataCount(
@Param(value = "PagerOptions") PagerOptions pagerOptions);
@Insert("INSERT INTO data_info(regionalism_code, system_code, data_type, data_version, submitted_batch, data_path, collection_time, data_charset)"
+ " values(#{regionalismCcode},#{systemCcode},#{dataType},#{dataVersion},#{submittedBbatch},#{dataPath},#{collectionTime},#{dataCharset})")
public int inserRecode(@Param("regionalismCcode") String regionalismCcode,
@Param("systemCcode") int systemCcode,
@Param("dataType") String dataType,
@Param("dataVersion") int dataVersion,
@Param("submittedBbatch") String submittedBbatch,
@Param("dataPath") String dataPath,
@Param("collectionTime") String collectionTime,
@Param("dataCharset") String dataCharset);
}

@ -0,0 +1,48 @@
package com.platform.entities;
import java.util.Date;
public enum BasedType {
STRING("java.lang.String", String.class), INTEGER("java.lang.Integer",
Integer.class), SHORT("java.lang.Short", Short.class), LONG(
"java.lang.Long", Long.class), DATE("java.util.Date", Date.class);
private String type;
private Class<?> clazz;
private BasedType(String type, Class<?> clazz) {
this.type = type;
this.clazz = clazz;
}
public static Class<?> getTypeClass(String type) {
for (BasedType bt : BasedType.values()) {
if (bt.equals(type))
return bt.clazz;
}
return null;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Class<?> getClazz() {
return clazz;
}
public void setClazz(Class<?> clazz) {
this.clazz = clazz;
}
@Override
public String toString() {
return this.type;
}
}

@ -0,0 +1,186 @@
package com.platform.entities;
/**
*
*
* @author wuming
*
*/
public class DataInfoEntity {
private int id;
private String regionalismCode; // 行政区划编码
private String cityName; // 市
private String districtName; // 区县
private int systemCode; // 系统编码
private String systemName; // 系统名称
private String dataType; // 数据类型:财政\社保\...
private int dataVersion; // 数据版本
private String submittedBatch; // 上报批次
private String dataPath; // 数据路径
private String collectingTime; // 采集时间
private String collectorContacts; // 采集人的联系
private String charset; // 数据的字符编码
private String collectorName; // 采集人姓名
private String year; // 数据年度
public DataInfoEntity() {
}
public DataInfoEntity(int id, String regionalismCode, String cityName,
String districtName, int systemCode, String systemName,
String dataType, int dataVersion, String submittedBatch,
String dataPath, String collectingTime, String collectorContacts,
String charset, String collectorName, String year) {
super();
this.id = id;
this.regionalismCode = regionalismCode;
this.cityName = cityName;
this.districtName = districtName;
this.systemCode = systemCode;
this.systemName = systemName;
this.dataType = dataType;
this.dataVersion = dataVersion;
this.submittedBatch = submittedBatch;
this.dataPath = dataPath;
this.collectingTime = collectingTime;
this.collectorContacts = collectorContacts;
this.charset = charset;
this.collectorName = collectorName;
this.year = year;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRegionalismCode() {
return regionalismCode;
}
public void setRegionalismCode(String regionalismCode) {
this.regionalismCode = regionalismCode;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getDistrictName() {
return districtName;
}
public void setDistrictName(String districtName) {
this.districtName = districtName;
}
public int getSystemCode() {
return systemCode;
}
public void setSystemCode(int systemCode) {
this.systemCode = systemCode;
}
public String getSystemName() {
return systemName;
}
public void setSystemName(String systemName) {
this.systemName = systemName;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public int getDataVersion() {
return dataVersion;
}
public void setDataVersion(int dataVersion) {
this.dataVersion = dataVersion;
}
public String getSubmittedBatch() {
return submittedBatch;
}
public void setSubmittedBatch(String submittedBatch) {
this.submittedBatch = submittedBatch;
}
public String getDataPath() {
return dataPath;
}
public void setDataPath(String dataPath) {
this.dataPath = dataPath;
}
public String getCollectingTime() {
return collectingTime;
}
public void setCollectingTime(String collectingTime) {
this.collectingTime = collectingTime;
}
public String getCollectorContacts() {
return collectorContacts;
}
public void setCollectorContacts(String collectorContacts) {
this.collectorContacts = collectorContacts;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public String getCollectorName() {
return collectorName;
}
public void setCollectorName(String collectorName) {
this.collectorName = collectorName;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
@Override
public String toString() {
return "id=" + this.id + " ,regionalismCode=" + this.regionalismCode
+ " ,cityName=" + this.cityName + " ,districtName="
+ this.districtName + " ,systemCode=" + this.systemCode
+ " ,systemName" + this.systemName + " ,dataType="
+ this.dataType + " ,dataVersion=" + this.dataVersion
+ " ,submittedBatch=" + this.submittedBatch + " ,dataPath="
+ this.dataPath + " ,collectingTime=" + this.collectingTime
+ " ,collectorContacts=" + this.collectorContacts
+ " ,charset=" + this.charset + " ,collectorName="
+ this.collectorName + " ,year=" + this.year + "";
}
}

@ -0,0 +1,94 @@
package com.platform.entities;
public class PagerOptions {
private int idIndex;
private String dataType;
private String submittedBatch;
private String cityName;
private String districtName;
private int dataVersion;
private String systemName;
private String dataYear;
private int limit;
public int getIdIndex() {
return idIndex;
}
public void setIdIndex(int idIndex) {
this.idIndex = idIndex;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getSubmittedBatch() {
return submittedBatch;
}
public void setSubmittedBatch(String submittedBatch) {
this.submittedBatch = submittedBatch;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public String getDistrictName() {
return districtName;
}
public void setDistrictName(String districtName) {
this.districtName = districtName;
}
public int getDataVersion() {
return dataVersion;
}
public void setDataVersion(int dataVersion) {
this.dataVersion = dataVersion;
}
public String getSystemName() {
return systemName;
}
public void setSystemName(String systemName) {
this.systemName = systemName;
}
public String getDataYear() {
return dataYear;
}
public void setDataYear(String dataYear) {
this.dataYear = dataYear;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
}

@ -0,0 +1,9 @@
package com.platform.service;
import org.springframework.ui.ModelMap;
import com.platform.entities.PagerOptions;
public interface DataInfoService {
public ModelMap getPagerTableData(PagerOptions pagerOptions);
}

@ -0,0 +1,34 @@
package com.platform.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import com.platform.dao.DataInfoDao;
import com.platform.entities.DataInfoEntity;
import com.platform.entities.PagerOptions;
@Service(value = "dataInfoService")
public class DataInfoServiceImp implements DataInfoService {
@Resource(name = "dataInfoDao")
private DataInfoDao dfdDao;
public void setDfdDao(DataInfoDao dfdDao) {
this.dfdDao = dfdDao;
}
@Override
public ModelMap getPagerTableData(PagerOptions pagerOptions) {
// TODO Auto-generated method stub
ModelMap modelMap = new ModelMap();
List<DataInfoEntity> result = dfdDao
.getLimitedDataInfoEntities(pagerOptions);
int count = dfdDao.getLimitedDataCount(pagerOptions);
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", count);
return modelMap;
}
}

@ -41,7 +41,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService {
public int deleteEncodeByCode(String code, String tableName) {
// TODO Auto-generated method stub
int cursor = eiDao.deleteEncodeByCode(code, tableName);
cursor = cursor / 0;
//cursor = cursor / 0;
return cursor;
}

@ -0,0 +1,90 @@
package com.platform.utils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import com.platform.entities.BasedType;
public class UtilsHelper {
public static Logger logger = Logger.getLogger(UtilsHelper.class);
/**
*
* @param clazz
* @param req
* @return
*/
public static Object newObjAndSetAttrsByClass(Class<?> clazz,
HttpServletRequest req) {
Object object = null;
try {
Class<?> cls = Class.forName(clazz.getName());
object = cls.newInstance();
Field[] fileds = clazz.getDeclaredFields();
for (Field fs : fileds) {
String fieldName = fs.getName();
String fieldType = fs.getGenericType().toString();
Object value = req.getAttribute(fieldName);
if (null != value) {
Method method = cls.getDeclaredMethod(
getAttributeSetName(fs),
BasedType.getTypeClass(fieldType));
method.invoke(object, value);
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return object;
};
/**
*
* @param object
* @param req
* @return
*/
public static Object newObjAndSetAttrsByInstance(Object object,
HttpServletRequest req) {
return newObjAndSetAttrsByClass(object.getClass(), req);
}
/**
* {@fs}set
*
* @param fs
*
* @return set
*/
private static String getAttributeSetName(Field fs) {
String fieldName = fs.getName();
char[] cs = fieldName.toCharArray();
cs[0] -= 32;
return "set" + String.valueOf(cs);
}
}

@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.platform.entities.EncodedInfoEntity;
import com.platform.service.EncodeInfoService;
@Controller
@ -24,9 +25,10 @@ public class TestController {
}
@RequestMapping("/hello")
public String hello(String name, HttpServletResponse res) {
@ResponseBody
public List<EncodedInfoEntity> hello(String name, HttpServletResponse res) {
System.out.println(name);
return "index.html";
return eis.getAllEncodeInfo("system_info");
}
@RequestMapping("/json")
@ -42,4 +44,10 @@ public class TestController {
public void testLog(HttpServletResponse res) {
System.out.println(eis.getEncodeNameByCode("1", "system_info"));
}
@RequestMapping("/data111.json")
public void test(String name, HttpServletResponse res){
}
}

@ -0,0 +1,50 @@
package com.platform.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
import org.junit.Before;
import org.junit.Test;
import com.platform.dao.DataInfoDao;
import com.platform.entities.DataInfoEntity;
import com.platform.entities.PagerOptions;
public class testSystemInfoDao extends SMBasedTest {
private DataInfoDao dfDao;
@Before
public void initBeforeFunction() {
dfDao = (DataInfoDao) this.applicationContext.getBean("dataInfoDao");
}
// @Test
public void testInsert() {
try {
Scanner in = new Scanner(new File(
"C:/Users/wuming/Desktop/data.txt"));
int count = 0;
while (in.hasNextLine()) {
String str = in.nextLine();
String[] values = str.split("\t");
System.out.println(values.length);
count++;
dfDao.inserRecode(values[0], Integer.parseInt(values[1]), "²ÆÕþ",
Integer.parseInt(values[3]), values[4], values[5],
values[6], values[7]);
}
System.out.println(count);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
public void test() {
//System.out.println(dfDao.getCount());
}
}

@ -26,6 +26,7 @@
<property name="password" value="${jdbc.mysql.password}" />
</bean>
<bean id="mySQLSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="/WebContent/WEB-INF/config/mybatis-applicationConfig.xml" />
<property name="dataSource" ref="mySQLDataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

Loading…
Cancel
Save