Repository: mafly/SpringDemo
Branch: master
Commit: 852a6e8e295e
Files: 100
Total size: 86.7 KB
Directory structure:
gitextract_vs5nz4fg/
├── .classpath
├── .gitignore
├── .project
├── .settings/
│ ├── .jsdtscope
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.wst.common.component
│ ├── org.eclipse.wst.common.project.facet.core.xml
│ ├── org.eclipse.wst.jsdt.ui.superType.container
│ └── org.eclipse.wst.jsdt.ui.superType.name
├── WebContent/
│ ├── META-INF/
│ │ └── MANIFEST.MF
│ ├── WEB-INF/
│ │ ├── applicationContext.xml
│ │ ├── lib/
│ │ │ ├── AXMLPrinter2.jar
│ │ │ ├── activemq-broker-5.13.0.jar
│ │ │ ├── activemq-client-5.13.0.jar
│ │ │ ├── activemq-console-5.13.0.jar
│ │ │ ├── activemq-jaas-5.13.0.jar
│ │ │ ├── activemq-pool-5.13.0.jar
│ │ │ ├── activemq-protobuf-1.1.jar
│ │ │ ├── activemq-spring-5.13.0.jar
│ │ │ ├── activemq-web-5.13.0.jar
│ │ │ ├── aopalliance.jar
│ │ │ ├── aspectjweaver-1.6.9.jar
│ │ │ ├── commons-beanutils.jar
│ │ │ ├── commons-collections.jar
│ │ │ ├── commons-fileupload-1.3.1.jar
│ │ │ ├── commons-io-2.4.jar
│ │ │ ├── commons-lang.jar
│ │ │ ├── commons-logging-1.1.3.jar
│ │ │ ├── dom4j-1.6.1.jar
│ │ │ ├── druid-1.0.9.jar
│ │ │ ├── freemarker.jar
│ │ │ ├── geronimo-j2ee-management_1.1_spec-1.0.1.jar
│ │ │ ├── geronimo-jms_1.1_spec-1.1.1.jar
│ │ │ ├── geronimo-jta_1.0.1B_spec-1.0.1.jar
│ │ │ ├── gson-2.5.jar
│ │ │ ├── httpclient-4.5.2.jar
│ │ │ ├── httpcore-4.4.4.jar
│ │ │ ├── jaxen-1.1-beta-6.jar
│ │ │ ├── jdom.jar
│ │ │ ├── jpush-client-3.2.9.jar
│ │ │ ├── jstl-1.2.1.jar
│ │ │ ├── jstl-api-1.2.1.jar
│ │ │ ├── log4j-1.2.17.jar
│ │ │ ├── mchange-commons-java-0.2.3.1.jar
│ │ │ ├── mysql-connector-java-5.1.18.jar
│ │ │ ├── okhttp-2.7.2.jar
│ │ │ ├── okio-1.6.0.jar
│ │ │ ├── poi-3.9-20121203.jar
│ │ │ ├── poi-ooxml-3.9-20121203.jar
│ │ │ ├── poi-ooxml-schemas-3.9-20121203.jar
│ │ │ ├── servlet-api.jar
│ │ │ ├── slf4j-api-1.7.13.jar
│ │ │ ├── slf4j-log4j12-1.7.21.jar
│ │ │ ├── spring-aop-4.2.6.RELEASE.jar
│ │ │ ├── spring-beans-4.2.6.RELEASE.jar
│ │ │ ├── spring-context-4.2.6.RELEASE.jar
│ │ │ ├── spring-context-support-4.2.6.RELEASE.jar
│ │ │ ├── spring-core-4.2.6.RELEASE.jar
│ │ │ ├── spring-expression-4.2.6.RELEASE.jar
│ │ │ ├── spring-jdbc-4.2.6.RELEASE.jar
│ │ │ ├── spring-jms-4.2.6.RELEASE.jar
│ │ │ ├── spring-tx-4.2.6.RELEASE.jar
│ │ │ ├── spring-web-4.2.6.RELEASE.jar
│ │ │ ├── spring-webmvc-4.2.6.RELEASE.jar
│ │ │ ├── xmemcached-1.3.8.jar
│ │ │ └── xmlbeans-2.3.0.jar
│ │ ├── springMVC-servlet.xml
│ │ └── web.xml
│ └── index.html
└── src/
├── cn/
│ └── mayongfa/
│ ├── activemq/
│ │ ├── ActiveMQTransportListener.java
│ │ ├── ConsumerMessageListener.java
│ │ └── MessageSender.java
│ ├── api/
│ │ └── controller/
│ │ └── UserController.java
│ ├── cache/
│ │ ├── MemcachedBasis.java
│ │ └── UserBasisCache.java
│ ├── common/
│ │ ├── DateUtil.java
│ │ ├── DynamicDataSource.java
│ │ ├── ExceptionHandler.java
│ │ ├── IdWorker.java
│ │ ├── IdWorkerManage.java
│ │ ├── JdbcContextHolder.java
│ │ ├── MD5Util.java
│ │ └── StrUtil.java
│ ├── controller/
│ │ └── AccountController.java
│ ├── dao/
│ │ └── UserBasisDao.java
│ ├── interceptor/
│ │ ├── Authority.java
│ │ ├── AuthorityAnnotationInterceptor.java
│ │ ├── AuthorityType.java
│ │ ├── DataSource.java
│ │ ├── DataSourceChoose.java
│ │ ├── DataSourceType.java
│ │ └── TestInterceptor.java
│ ├── model/
│ │ └── UserBasis.java
│ ├── quartz/
│ │ └── GlodQuartz.java
│ └── service/
│ ├── UserBasisService.java
│ └── imp/
│ └── UserBasisServiceImp.java
├── global.properties
├── jdbc.properties
├── log4j.properties
└── memcached.properties
================================================
FILE CONTENTS
================================================
================================================
FILE: .classpath
================================================
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-aop-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-beans-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-context-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-context-support-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-core-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-expression-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-jdbc-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-jms-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-tx-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-web-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-webmvc-4.2.6.RELEASE.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/druid-1.0.9.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/aopalliance.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/aspectjweaver-1.6.9.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/AXMLPrinter2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-beanutils.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-collections.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-fileupload-1.3.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-io-2.4.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-lang.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-logging-1.1.3.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/freemarker.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/geronimo-j2ee-management_1.1_spec-1.0.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/geronimo-jms_1.1_spec-1.1.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/geronimo-jta_1.0.1B_spec-1.0.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/gson-2.5.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpclient-4.5.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/httpcore-4.4.4.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/jaxen-1.1-beta-6.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/jdom.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/jpush-client-3.2.9.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/jstl-1.2.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/jstl-api-1.2.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/mchange-commons-java-0.2.3.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java-5.1.18.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/okhttp-2.7.2.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/okio-1.6.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-3.9-20121203.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-ooxml-3.9-20121203.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-ooxml-schemas-3.9-20121203.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/servlet-api.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-api-1.7.13.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-log4j12-1.7.21.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/xmemcached-1.3.8.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/xmlbeans-2.3.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-broker-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-client-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-console-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-jaas-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-pool-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-protobuf-1.1.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-spring-5.13.0.jar"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/activemq-web-5.13.0.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
================================================
FILE: .gitignore
================================================
/build/
================================================
FILE: .project
================================================
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SpringDemo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
================================================
FILE: .settings/.jsdtscope
================================================
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/*.min.js|**/node_modules/*|**/bower_components/*" kind="src" path="WebContent"/>
<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>
================================================
FILE: .settings/org.eclipse.jdt.core.prefs
================================================
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
================================================
FILE: .settings/org.eclipse.wst.common.component
================================================
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="SpringDemo">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="SpringDemo"/>
<property name="java-output-path" value="/SpringDemo/build/classes"/>
</wb-module>
</project-modules>
================================================
FILE: .settings/org.eclipse.wst.common.project.facet.core.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="java"/>
<fixed facet="jst.web"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
================================================
FILE: .settings/org.eclipse.wst.jsdt.ui.superType.container
================================================
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
================================================
FILE: .settings/org.eclipse.wst.jsdt.ui.superType.name
================================================
Window
================================================
FILE: WebContent/META-INF/MANIFEST.MF
================================================
Manifest-Version: 1.0
Class-Path:
================================================
FILE: WebContent/WEB-INF/applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 将多个配置文件读取到容器中,交给Spring管理 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:global.properties</value>
<value>classpath:jdbc.properties</value>
<value>classpath:memcached.properties</value>
</list>
</property>
</bean>
<!-- 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 -->
<context:component-scan base-package="cn.mayongfa.activemq" />
<context:component-scan base-package="cn.mayongfa.common" />
<context:component-scan base-package="cn.mayongfa.service" />
<context:component-scan base-package="cn.mayongfa.dao" />
<context:component-scan base-package="cn.mayongfa.cache" />
<!--master 配置数据源 -->
<bean id="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>${master.jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${master.jdbc.url}</value>
</property>
<property name="username">
<value>${master.jdbc.username}</value>
</property>
<property name="password">
<value>${master.jdbc.password}</value>
</property>
<!-- 通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall -->
<property name="filters" value="stat,log4j" />
<!-- 最大并发连接数 -->
<property name="maxActive" value="30" />
<!-- 初始化连接数量 -->
<property name="initialSize" value="5" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 最小空闲连接数 -->
<property name="minIdle" value="5" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="false" />
<property name="maxOpenPreparedStatements" value="100" />
<!-- 打开removeAbandoned功能(连接泄漏监测,怀疑存在泄漏之后再打开) -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
</bean>
<!--slave 配置数据源 -->
<bean id="slaveDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>${slave.jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${slave.jdbc.url}</value>
</property>
<property name="username">
<value>${slave.jdbc.username}</value>
</property>
<property name="password">
<value>${slave.jdbc.password}</value>
</property>
<!-- 通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall -->
<!-- <property name="filters" value="stat,log4j" /> -->
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
<ref bean="log-filter" />
</list>
</property>
<!-- 最大并发连接数 -->
<property name="maxActive" value="30" />
<!-- 初始化连接数量 -->
<property name="initialSize" value="5" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 最小空闲连接数 -->
<property name="minIdle" value="5" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="false" />
<property name="maxOpenPreparedStatements" value="100" />
<!-- 打开removeAbandoned功能(连接泄漏监测,怀疑存在泄漏之后再打开) -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
</bean>
<!--goldMaster 配置数据源 -->
<bean id="goldMasterDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>${goldMaster.jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${goldMaster.jdbc.url}</value>
</property>
<property name="username">
<value>${goldMaster.jdbc.username}</value>
</property>
<property name="password">
<value>${goldMaster.jdbc.password}</value>
</property>
<!-- 通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall -->
<!-- <property name="filters" value="stat,log4j" /> -->
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
<ref bean="log-filter" />
</list>
</property>
<!-- 最大并发连接数 -->
<property name="maxActive" value="30" />
<!-- 初始化连接数量 -->
<property name="initialSize" value="5" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 最小空闲连接数 -->
<property name="minIdle" value="5" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="false" />
<property name="maxOpenPreparedStatements" value="100" />
<!-- 打开removeAbandoned功能(连接泄漏监测,怀疑存在泄漏之后再打开) -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
</bean>
<!--goldSlave 配置数据源 -->
<bean id="goldSlaveDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>${goldSlave.jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${goldSlave.jdbc.url}</value>
</property>
<property name="username">
<value>${goldSlave.jdbc.username}</value>
</property>
<property name="password">
<value>${goldSlave.jdbc.password}</value>
</property>
<!-- 通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall -->
<!-- <property name="filters" value="stat,log4j" /> -->
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
<ref bean="log-filter" />
</list>
</property>
<!-- 最大并发连接数 -->
<property name="maxActive" value="30" />
<!-- 初始化连接数量 -->
<property name="initialSize" value="5" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 最小空闲连接数 -->
<property name="minIdle" value="5" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="poolPreparedStatements" value="false" />
<property name="maxOpenPreparedStatements" value="100" />
<!-- 打开removeAbandoned功能(连接泄漏监测,怀疑存在泄漏之后再打开) -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
</bean>
<!-- 慢SQL记录 -->
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="mergeSql" value="true" />
<!-- 3000毫秒,也就是3秒 -->
<property name="slowSqlMillis" value="3000" />
<property name="logSlowSql" value="true" />
</bean>
<bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter">
<property name="statementLogErrorEnabled" value="true" />
</bean>
<bean id="dataSource" class="cn.mayongfa.common.DynamicDataSource">
<property name="targetDataSources">
<map>
<entry key="slave" value-ref="slaveDataSource" />
<entry key="goldMaster" value-ref="goldMasterDataSource" />
<entry key="goldSlave" value-ref="goldSlaveDataSource" />
</map>
</property>
<property name="defaultTargetDataSource" ref="masterDataSource" />
</bean>
<!-- 配置Jdbc模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<!-- 数据源切换类 -->
<bean id="dataSourceChoose" class="cn.mayongfa.interceptor.DataSourceChoose" />
<!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceMethod"
expression=" execution(* cn.mayongfa.service..*(..))" />
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"
order="2" />
<aop:aspect ref="dataSourceChoose" order="1">
<aop:before method="before" pointcut-ref="serviceMethod" />
</aop:aspect>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- Memcached 配置 -->
<bean id="memcachedClientBuilder" class="net.rubyeye.xmemcached.XMemcachedClientBuilder"
p:connectionPoolSize="${memcached.connectionPoolSize}" p:failureMode="${memcached.failureMode}">
<constructor-arg>
<list>
<bean class="java.net.InetSocketAddress">
<constructor-arg>
<value>${server1.memcached.host}</value>
</constructor-arg>
<constructor-arg>
<value>${server1.memcached.port}</value>
</constructor-arg>
</bean>
<bean class="java.net.InetSocketAddress">
<constructor-arg>
<value>${server2.memcached.host}</value>
</constructor-arg>
<constructor-arg>
<value>${server2.memcached.port}</value>
</constructor-arg>
</bean>
</list>
</constructor-arg>
<constructor-arg>
<list>
<value>${server1.memcached.weight}</value>
<value>${server2.memcached.weight}</value>
</list>
</constructor-arg>
<property name="commandFactory">
<bean class="net.rubyeye.xmemcached.command.TextCommandFactory" />
</property>
<property name="sessionLocator">
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<property name="transcoder">
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
</bean>
<bean id="memcachedClient" factory-bean="memcachedClientBuilder"
factory-method="build" destroy-method="shutdown" />
<!-- Spring提供的JMS工具类,它可以进行消息发送、接收等 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<!-- 真正可以产生Connection的ConnectionFactory,由ActiveMQ提供 -->
<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:tcp://192.168.3.15:61616" />
<!-- 消息传输监听器 处理网络及服务器异常 -->
<property name="transportListener">
<bean class="cn.mayongfa.activemq.ActiveMQTransportListener" />
</property>
</bean>
<!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->
<bean id="connectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="targetConnectionFactory" />
</bean>
<!--这个是队列目的地 -->
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg>
<value>default_queue,gold_queue</value>
</constructor-arg>
</bean>
<!-- 消息监听器 -->
<bean id="consumerMessageListener" class="cn.mayongfa.activemq.ConsumerMessageListener" />
<!-- 消息监听容器 -->
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="queueDestination" />
<property name="messageListener" ref="consumerMessageListener" />
<!-- 设置固定的线程数 -->
<property name="concurrentConsumers" value="2"></property>
<!-- 设置动态的线程数 -->
<property name="concurrency" value="2-5"></property>
</bean>
</beans>
================================================
FILE: WebContent/WEB-INF/springMVC-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd ">
<!-- 使用默认的注解映射 -->
<mvc:annotation-driven />
<mvc:resources location="/" mapping="/index.html" />
<!-- 自动扫描controller包中的控制器 -->
<context:component-scan base-package="cn.mayongfa.api.controller" />
<context:component-scan base-package="cn.mayongfa.controller" />
<!-- 扫描定时作业调度包 -->
<task:annotation-driven />
<context:component-scan base-package="cn.mayongfa.quartz"/>
<!--视图解释器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html;charset=UTF-8"></property>
<property name="requestContextAttribute" value="request" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
</bean>
<!-- Freemarker配置 -->
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/view/" />
<property name="defaultEncoding" value="UTF-8" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="number_format">0.##########</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
</props>
</property>
<!-- freemark 全局变量 -->
<property name="freemarkerVariables">
<map>
<entry key="webroot" value="http://127.0.0.1:8080"></entry>
</map>
</property>
</bean>
<!-- 上传文件拦截,设置最大上传文件大小 30M=30*1024*1024(B)=31457280 bytes -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="31457280" />
</bean>
<mvc:interceptors>
<!-- 直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
<mvc:interceptor>
<!-- 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
<mvc:mapping path="/api/**" />
<bean class="cn.mayongfa.interceptor.TestInterceptor"></bean>
</mvc:interceptor>
<!-- 权限认证拦截器
<mvc:interceptor>
<mvc:mapping path="/account/**"/>
<bean class="cn.mayongfa.interceptor.AuthorityAnnotationInterceptor"></bean>
</mvc:interceptor> -->
</mvc:interceptors>
<!-- API 接口跨域配置 -->
<mvc:cors>
<mvc:mapping path="/api/**" allowed-origins="*"
allowed-methods="POST, GET, OPTIONS, DELETE, PUT"
allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
allow-credentials="true" />
</mvc:cors>
</beans>
================================================
FILE: WebContent/WEB-INF/web.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>springdemo</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
<init-param>
<param-name>methodParam</param-name>
<param-value>requestMethod</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 连接池 启用Web监控统计功能 start-->
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
<init-param>
<param-name>exclusions</param-name>
<param-value>*.js,*mp3,*.swf,*.xls,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DruidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
<init-param>
<!-- 允许清空统计数据 -->
<param-name>resetEnable</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 用户名 -->
<param-name>loginUsername</param-name>
<param-value>admin</param-value>
</init-param>
<init-param>
<!-- 密码 -->
<param-name>loginPassword</param-name>
<param-value>123456</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
<!-- 连接池 启用Web监控统计功能 end-->
</web-app>
================================================
FILE: WebContent/index.html
================================================
<html>
<head>
<title>Spring Demo</title>
</head>
<body>Spring Demo
</body>
</html>
================================================
FILE: src/cn/mayongfa/activemq/ActiveMQTransportListener.java
================================================
package cn.mayongfa.activemq;
import java.io.IOException;
import org.apache.activemq.transport.TransportListener;
import org.apache.log4j.Logger;
/**
* 消息传输监听
* @author Mafly
*
*/
public class ActiveMQTransportListener implements TransportListener {
private Logger log = Logger.getLogger(ActiveMQTransportListener.class);
/**
* 对消息传输命令进行监控
* @param command
*/
@Override
public void onCommand(Object o) {
}
/**
* 对监控到的异常进行触发
* @param error
*/
@Override
public void onException(IOException error) {
log.error("onException -> 消息服务器连接错误......", error);
}
/**
* 当failover时触发
*/
@Override
public void transportInterupted() {
log.warn("transportInterupted -> 消息服务器连接发生中断...");
//这里就可以状态进行标识了
}
/**
* 监控到failover恢复后进行触发
*/
@Override
public void transportResumed() {
log.info("transportResumed -> 消息服务器连接已恢复...");
//这里就可以进行状态标识了
}
}
================================================
FILE: src/cn/mayongfa/activemq/ConsumerMessageListener.java
================================================
package cn.mayongfa.activemq;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
/**
* 消费者监听类
*
* @author Mafly
*/
@Component
public class ConsumerMessageListener implements MessageListener {
private Logger log = Logger.getLogger(ConsumerMessageListener.class);
@Override
public void onMessage(Message arg0) {
// 监听发送到消息队列的文本消息,作强制转换。
TextMessage textMessage = (TextMessage) arg0;
try {
System.out.println("接收到的消息内容是:" + textMessage.getText());
// TODO: 你喜欢的任何事情...
} catch (JMSException e) {
log.error("", e);
}
}
}
================================================
FILE: src/cn/mayongfa/activemq/MessageSender.java
================================================
package cn.mayongfa.activemq;
import java.util.HashMap;
import java.util.Map;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import com.google.gson.Gson;
/**
* ActiveMQ 消息生产类
*
* @author Mafly
*
*/
@Component
public class MessageSender {
private Logger log = Logger.getLogger(MessageSender.class);
@Autowired
private JmsTemplate jmsTemplate;
private String Queue = "default_queue";
private String GoldQueue = "gold_queue";
private Gson gson = new Gson();
/**
* 用户登录消息
*/
public void userLogin(long id, String username) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("userid", id);
map.put("username", username);
System.out.println("发送了一条消息。");
// 发送到金币队列
sendMessage(gson.toJson(map), 1);
}
/**
* 发送到消息队列
*
* @param messgae
* @param type
* 类型,0:默认队列 1:金币队列 ...
*/
public void sendMessage(final String messgae, int type) {
try {
String destination = this.Queue;
if (type == 1) {
destination = GoldQueue;
}
jmsTemplate.send(destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage textMessage = session.createTextMessage(messgae);
return textMessage;
}
});
} catch (Exception e) {
log.error("", e);
}
}
}
================================================
FILE: src/cn/mayongfa/api/controller/UserController.java
================================================
package cn.mayongfa.api.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;
import cn.mayongfa.common.MD5Util;
import cn.mayongfa.common.StrUtil;
import cn.mayongfa.model.UserBasis;
import cn.mayongfa.service.UserBasisService;
@Controller
@RequestMapping("/api/user/*")
public class UserController {
private static Logger log = Logger.getLogger(UserController.class);
@Autowired
private UserBasisService userBasisService;
/**
* get
*
* @param oRequest
* @param oResponse
* @return
*/
@ResponseBody
@RequestMapping(value = "get", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET })
public String get(@RequestParam("id") long id) {
int code = -1;
String msg = "";
UserBasis entity = userBasisService.getEntity(id);
try {
if (entity != null && entity.getId() > 0) {
code = 1;
msg = "请求成功!";
}
} catch (Exception e) {
log.error("出错啦!", e);
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", entity);
responseMap.put("rows", "");
return new Gson().toJson(responseMap);
}
/**
* getlist
*
* @param oRequest
* @param oResponse
* @return
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@ResponseBody
@RequestMapping(value = "getlist", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET })
public String getList() {
int code = -1;
String msg = "";
List<UserBasis> userList = userBasisService.getList();
if (userList != null && userList.size() > 0) {
code = 1;
msg = "请求成功!";
}
// 演示异常
userBasisService.getListCount(null);
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", userList);
return new Gson().toJson(responseMap);
}
/**
* post
*
* @param oRequest
* @param oResponse
* @return
*/
@ResponseBody
@RequestMapping(value = "post", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST })
public String post(HttpServletRequest oRequest, HttpServletResponse oResponse) {
int code = -1;
String msg = "";
String name = oRequest.getParameter("name") != null ? oRequest.getParameter("name").toString() : "";
String password = oRequest.getParameter("password") != null ? oRequest.getParameter("password").toString() : "";
String phone = oRequest.getParameter("phone") != null ? oRequest.getParameter("phone").toString() : "";
if (StrUtil.isNullOrEmpty(name)) {
msg = "请填写用户姓名!";
} else if (StrUtil.isNullOrEmpty(password)) {
msg = "请填写密码!";
} else {
UserBasis entity = new UserBasis();
entity.setId(StrUtil.DEFAULT_NULL);
entity.setName(name);
entity.setPassword(MD5Util.GetMD5Code32(password));
entity.setPhone(phone);
entity.setStatus(1);
entity.setUpdatetime(new Date());
entity.setCreatetime(new Date());
long id = userBasisService.Save(entity);
if (id > 0) {
code = 1;
msg = "添加成功!";
}
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", "");
return new Gson().toJson(responseMap);
}
/**
* delete
*
* @param oRequest
* @param oResponse
* @return
*/
@ResponseBody
@RequestMapping(value = "delete", produces = "application/json;charset=UTF-8", method = { RequestMethod.DELETE })
public String delete(@RequestParam("id") long id) {
int code = -1;
String msg = "";
if (userBasisService.Delete(id)) {
code = 1;
msg = "删除成功!";
} else {
msg = "删除失败!";
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", "");
return new Gson().toJson(responseMap);
}
/**
* put
*
* @param oRequest
* @param oResponse
* @return
*/
@ResponseBody
@RequestMapping(value = "put", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST })
public String put(HttpServletRequest oRequest, HttpServletResponse oResponse) {
int code = -1;
String msg = "";
long id = StrUtil.toLong(oRequest.getParameter("id"), StrUtil.DEFAULT_NULL);
String name = oRequest.getParameter("name") != null ? oRequest.getParameter("name").toString() : "";
String phone = oRequest.getParameter("phone") != null ? oRequest.getParameter("phone").toString() : "";
if (id == StrUtil.DEFAULT_NULL) {
msg = "请选择用户!";
} else if (StrUtil.isNullOrEmpty(name)) {
msg = "请填写用户姓名!";
} else if (StrUtil.isNullOrEmpty(phone)) {
// msg = "请填写电话!";
} else {
UserBasis entity = userBasisService.getEntity(id);
if (entity != null && entity.getId() == id) {
entity.setName(name);
entity.setPhone(phone);
entity.setUpdatetime(new Date());
id = userBasisService.Save(entity);
if (id > 0) {
code = 1;
msg = "更新成功!";
} else {
msg = "更新失败!";
}
} else {
msg = "用户不存在!";
}
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", "");
return new Gson().toJson(responseMap);
}
}
================================================
FILE: src/cn/mayongfa/cache/MemcachedBasis.java
================================================
package cn.mayongfa.cache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import net.rubyeye.xmemcached.MemcachedClient;
@Component
public class MemcachedBasis {
@Autowired
protected MemcachedClient memcachedClient;
/**
* 失效时间(秒)3600*24 一天
*/
protected int Exptime = 3600 * 24;
/**
* 基础数据失效时间(秒)3600*24*7 一周
*/
protected int DataExptime = this.Exptime * 7;
protected String Prefix = "SPRINGDEMO:";
}
================================================
FILE: src/cn/mayongfa/cache/UserBasisCache.java
================================================
package cn.mayongfa.cache;
import java.util.concurrent.TimeoutException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import cn.mayongfa.dao.UserBasisDao;
import cn.mayongfa.model.UserBasis;
import net.rubyeye.xmemcached.exception.MemcachedException;
@Component
public class UserBasisCache extends MemcachedBasis {
private Logger log = Logger.getLogger(UserBasisCache.class);
@Autowired
private UserBasisDao userBasisDao;
/**
* 设置缓存
*
* @param model
* 用户model
* @return
*/
public Boolean set(UserBasis model) {
Boolean result = false;
try {
result = memcachedClient.set(getCacheKey(model.getId()), super.Exptime, model);
} catch (TimeoutException | InterruptedException | MemcachedException e) {
log.error("", e);
}
return result;
}
/**
* 获取缓存
*
* @param id
* 用户ID
* @return
*/
public UserBasis get(long id) {
UserBasis entity = new UserBasis();
try {
entity = memcachedClient.get(getCacheKey(id));
if (entity == null || entity.getId() <= 0) {
entity = userBasisDao.getEntity(id);
this.set(entity);
}
} catch (TimeoutException | InterruptedException | MemcachedException e) {
log.error("", e);
entity = userBasisDao.getEntity(id);
}
return entity;
}
/**
* 删除缓存
*
* @param id
* 用户ID
* @return
*/
public Boolean delete(long id) {
try {
return memcachedClient.delete(getCacheKey(id));
} catch (TimeoutException | InterruptedException | MemcachedException e) {
log.error("", e);
}
return false;
}
/**
* 获取缓存 Key
*
* @param id
* 用户ID
* @return
*/
private String getCacheKey(long id) {
return super.Prefix + "UserBasis:" + id;
}
}
================================================
FILE: src/cn/mayongfa/common/DateUtil.java
================================================
package cn.mayongfa.common;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
public class DateUtil {
private static Logger log = Logger.getLogger(DateUtil.class);
/**
* date类型转换为String类型
* @param data Date类型的时间
* @param formatType 格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
* @return
*/
public static String dateToString(Date date, String formatType) {
SimpleDateFormat sdf=new SimpleDateFormat(formatType);
//java.util.Date date=new java.util.Date();
return sdf.format(date);
}
/**
* long类型转换为String类型
* @param currentTime 要转换的long类型的时间
* @param formatType 要转换的string类型的时间格式
* @return
* @throws ParseException
*/
public static String longToString(long currentTime, String formatType){
/*SimpleDateFormat sf = new SimpleDateFormat(formatType);
Date date = new Date(currentTime);
return sf.format(date);*/
SimpleDateFormat oldFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat newFormat = new SimpleDateFormat(formatType);
Date date = null;
try {
date = oldFormat.parse(currentTime+"");
} catch (Exception e) {
log.error("", e);
date = new Date();
e.printStackTrace();
}
return newFormat.format(date);
}
/**
* long类型转换为String类型
* @param currentTime 要转换的long类型的时间
* @param formatType 要转换的string类型的时间格式
* @return
* @throws ParseException
*/
public static String longToString(long currentTime, String oldFormatType, String formatType)
throws ParseException {
String strTime = StrUtil.toStr(currentTime, StrUtil.DEFAULT_DATE); // long类型转成String
Date date = stringToDate(strTime, oldFormatType);
return dateToString(date, formatType);
}
/**
* string类型转换为date类型
* @param strTime 的时间格式必须要与formatType的时间格式相同
* @param formatType 要转换的string类型的时间,formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日HH时mm分ss秒
* @return
* @throws ParseException
*/
public static Date stringToDate(String strTime, String formatType) {
try {
SimpleDateFormat formatter = new SimpleDateFormat(formatType);
Date date = null;
date = formatter.parse(strTime);
return date;
} catch (Exception e) {
log.error("", e);
return new Date();
}
}
/**
* long转换为Date类型
* @param currentTime 要转换的long类型的时间
* @param formatType 要转换的时间格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
* @return
* @throws ParseException
*/
public static Date longToDate(long currentTime, String formatType) {
try {
Date dateOld = new Date(currentTime); // 根据long类型的毫秒数生命一个date类型的时间
String sDateTime = dateToString(dateOld, formatType); // 把date类型的时间转换为string
Date date = stringToDate(sDateTime, formatType); // 把String类型转换为Date类型
return date;
} catch (Exception e) {
log.error("", e);
return new Date();
}
}
/**
* string类型转换为long类型
* @param strTime 要转换的String类型的时间
* @param formatType 时间格式的时间格式和formatType的时间格式必须相同
* @return
* @throws ParseException
*/
public static long stringToLong(String strTime, String formatType) {
try {
Date date = stringToDate(strTime, formatType); // String类型转成date类型
if (date == null) {
return 0;
} else {
long currentTime = dateToLong(date); // date类型转成long类型
return currentTime;
}
} catch (Exception e) {
log.error("", e);
return 0;
}
}
/**
* date类型转换为long类型
* @param date 要转换的date类型的时间
* @return
*/
public static long dateToLong(Date date) {
return StrUtil.toLong(dateToString(date,"yyyyMMddHHmmss"), StrUtil.DEFAULT_ALL);
}
/**
* 获取龙long类型时间
* @return yyyyMMddHHmmss
*/
public static long dateToLong() {
return StrUtil.toLong(dateToString(new Date(),"yyyyMMddHHmmss"), StrUtil.DEFAULT_ALL);
}
/**
* 时间戳转Long类型时间
* @param unix 时间戳
* @return 若转换失败,返回当前时间
*/
public static long unixToLong(long unix){
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
try{
return Long.parseLong(format.format(unix));
}catch(Exception e){
log.error("", e);
return DateUtil.dateToLong();
}
}
/**
* 分析Long类型的时间距离当前时间多久
* @param time Long类型的时间。yyyyMMddHHmmss
* @return 若转换异常,返回DateUtil.longToString(time, "yyyy-MM-dd")
*/
public static String getTimePosition(long time){
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date;
try {
date = format.parse(time + "");
long conversionTime = date.getTime();
long currentTime = System.currentTimeMillis();
long relativeTime = currentTime - conversionTime;
if(relativeTime < 30*60*1000){
return "刚刚";
}else if(relativeTime < 60*60*1000){
return "30分钟前";
}else{
return DateUtil.longToString(time, "yyyy-MM-dd");
}
} catch (ParseException e) {
log.error("", e);
return DateUtil.longToString(time, "yyyy-MM-dd");
}
}
}
================================================
FILE: src/cn/mayongfa/common/DynamicDataSource.java
================================================
package cn.mayongfa.common;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import cn.mayongfa.common.JdbcContextHolder;
public class DynamicDataSource extends AbstractRoutingDataSource {
@Override
protected Object determineCurrentLookupKey() {
// 获取当前数据源连接
return JdbcContextHolder.getJdbcType();
}
}
================================================
FILE: src/cn/mayongfa/common/ExceptionHandler.java
================================================
package cn.mayongfa.common;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import com.google.gson.Gson;
@Component
public class ExceptionHandler implements HandlerExceptionResolver {
private static Logger log = Logger.getLogger(ExceptionHandler.class);
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception exception) {
log.error("ExceptionHandler 捕获的异常:", exception);
String requestType = request.getHeader("X-Requested-With");
String type = "api"; //TODO:
if (!type.equals("api") && StrUtil.isNullOrEmpty(requestType)) {
// 非API请求
return new ModelAndView("redirect:/500.html");
} else {// JSON格式返回
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", -1);
responseMap.put("msg", "系统异常,请稍后重试!");
responseMap.put("params", "");
responseMap.put("rows", "");
String json = new Gson().toJson(responseMap);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
try {
response.getWriter().write(json);
response.getWriter().flush();
return null;
} catch (IOException e) {
log.error("", e);
}
}
return new ModelAndView("redirect:/500.html");
}
}
================================================
FILE: src/cn/mayongfa/common/IdWorker.java
================================================
package cn.mayongfa.common;
import org.apache.log4j.Logger;
/**
*
* 以后,根据数据id,即可计算出该数据,产自哪个数据中心的.
*
* @author Administrator
*
*/
public class IdWorker {
/**
* 下面3个参数,不同部署的地方,系统,都要修改为不同的参数值.
*/
private long datacenterId = 1;
private long workerId = 1;
private static final String USERAGENT = "springdemo";
private long sequence = 0L;
private static final Logger logger = Logger.getLogger(IdWorker.class);
/**
*
*/
private final long twepoch = 1288834974657L;
// 机器标识位数
private final long workerIdBits = 5L;
// 数据中心标识位数
private final long datacenterIdBits = 5L;
// 机器ID最大值
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
// 数据中心ID最大值
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
// 毫秒内自增位
private final long sequenceBits = 12L;
// 机器ID偏左移12位
private final long workerIdShift = sequenceBits;
// 数据中心ID左移17位
private final long datacenterIdShift = sequenceBits + workerIdBits;
// 时间毫秒左移22位
private final long timestampLeftShift = sequenceBits + workerIdBits
+ datacenterIdBits;
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
private long lastTimestamp = -1L;
/**
*
* @param workerId
* @param datacenterId
*/
public IdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format(
"workerId can't be greater than %d or less than 0.",
maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format(
"datacenterId can't be greater than %d or less than 0.",
maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
public IdWorker() {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format(
"workerId can't be greater than %d or less than 0.",
maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format(
"datacenterId can't be greater than %d or less than 0.",
maxDatacenterId));
}
//this.workerId = workerId;
//this.datacenterId = datacenterId;
}
/**
*
* @return
*/
protected synchronized long nextId() {
long id = 0L;
long timestamp = timeGen();
// 时间错误
if (timestamp < lastTimestamp) {
throw new RuntimeException(
String.format(
"clock moved backwards. refusing to generate id for %d milliseconds.",
lastTimestamp - timestamp));
}
if (timestamp == lastTimestamp) {
// 当前毫秒内,则+1
sequence = (1 + sequence) & sequenceMask;
if (0 == sequence) {
// 当前毫秒内计数满了,则等待下一秒
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0;
}
lastTimestamp = timestamp;
// ID偏移组合生成最终的ID,并返回ID
id = ((timestamp - twepoch) << timestampLeftShift)
| (datacenterId << datacenterIdShift)
| (workerId << workerIdShift) | sequence;
return id;
}
/**
* 等待下一个毫秒的到来
*
* @param lastTimestamp
* @return
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
*
* @return
*/
protected long timeGen() {
return System.currentTimeMillis();
}
public long get_worker_id() throws Exception {
return workerId;
}
public long get_timestamp() throws Exception {
return System.currentTimeMillis();
}
public long get_id(String useragent) throws Exception {
if (!USERAGENT.equals(useragent)) {
throw new Exception("invalid useragent.");
}
long id = nextId();
logger.info(String.format("id: %s user_agent: %s worker_id: %s data_center_id: %s",id, useragent, workerId, datacenterId));
return id;
}
public long get_datacenter_id() throws Exception {
return datacenterId;
}
}
================================================
FILE: src/cn/mayongfa/common/IdWorkerManage.java
================================================
package cn.mayongfa.common;
public class IdWorkerManage {
private static IdWorker IdWorkerInstance = null;
static {
IdWorkerManage.IdWorkerInstance = new IdWorker();
}
/**
* single 单例模式
*
* @return
*/
private static IdWorker getIdWorkerInstance() {
if (IdWorkerManage.IdWorkerInstance == null) {
IdWorkerManage.IdWorkerInstance = new IdWorker();
}
return IdWorkerManage.IdWorkerInstance;
}
/**
* single 单例模式
*
* @return
*/
public static long getId() throws Exception {
return IdWorkerManage.getIdWorkerInstance().get_id("springdemo");
}
/*
public static void main(String[] args) {
for (int i = 0; i < 101; i++) {
try {
System.out.println(IdWorkerManage.getId());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}*/
}
================================================
FILE: src/cn/mayongfa/common/JdbcContextHolder.java
================================================
package cn.mayongfa.common;
public class JdbcContextHolder {
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
public static void setJdbcType(String jdbcType) {
contextHolder.set(jdbcType);
}
public static void setSlave() {
setJdbcType("slave");
}
public static void setMaster() {
clearJdbcType();
}
public static String getJdbcType() {
return (String) contextHolder.get();
}
public static void clearJdbcType() {
contextHolder.remove();
}
}
================================================
FILE: src/cn/mayongfa/common/MD5Util.java
================================================
package cn.mayongfa.common;
import java.security.MessageDigest;
import org.apache.log4j.Logger;
public class MD5Util {
private static Logger log = Logger.getLogger(MD5Util.class);
public static String GetMD5Code16(String strObj) {
return GetMD5Code32(strObj).substring(8, 24);
}
public static String GetMD5Code32(String strObj) {
String resultString = null;
try {
resultString = new String(strObj);
MessageDigest md = MessageDigest.getInstance("MD5");
// md.digest() 该函数返回值为存放哈希值结果的byte数组
resultString = byteToString(md.digest(strObj.getBytes("UTF-8")));
} catch (Exception ex) {
log.error("", ex);
}
return resultString;
}
// 转换字节数组为16进制字串
private static String byteToString(byte[] bByte) {
StringBuffer sBuffer = new StringBuffer();
for (int i = 0; i < bByte.length; i++) {
sBuffer.append(byteToArrayString(bByte[i]));
}
return sBuffer.toString();
}
// 返回形式为数字跟字符串
private static String byteToArrayString(byte bByte) {
int iRet = bByte;
// System.out.println("iRet="+iRet);
if (iRet < 0) {
iRet += 256;
}
int iD1 = iRet / 16;
int iD2 = iRet % 16;
return strDigits[iD1] + strDigits[iD2];
}
private final static String[] strDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d",
"e", "f" };
}
================================================
FILE: src/cn/mayongfa/common/StrUtil.java
================================================
package cn.mayongfa.common;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
* 字符串处理类
*
* @Version 1.0
* @Remark
*/
public final class StrUtil {
/** 7位ASCII字符,也叫作ISO646-US、Unicode字符集的基本拉丁块 */
private static final String US_ASCII = "US-ASCII";
/** ISO 拉丁字母表 No.1,也叫作 ISO-LATIN-1 */
private static final String ISO_8859_1 = "ISO-8859-1";
/** 8 位 UCS 转换格式 */
private static final String UTF_8 = "UTF-8";
/** 16 位 UCS 转换格式,Big Endian(最低地址存放高位字节)字节顺序 */
private static final String UTF_16BE = "UTF-16BE";
/** 16 位 UCS 转换格式,Little-endian(最高地址存放低位字节)字节顺序 */
private static final String UTF_16LE = "UTF-16LE";
/** 16 位 UCS 转换格式,字节顺序由可选的字节顺序标记来标识 */
private static final String UTF_16 = "UTF-16";
/** 中文超大字符集 */
private static final String GBK = "GBK";
/** 默认全部值 1111 */
public static final long DEFAULT_ALL = (long) 1111;// 如下拉选择的全部 选项
public static final int DEFAULT_ALL_Int = 1111;// 如下拉选择的全部
/** 默认空值 0001 */
public static final long DEFAULT_NULL = (long) 0001;// 在值转换时候,如 字符转为
// long类型时候,先判断字符是否为空,如果为空返回这个
// ,或者转换异常时候。
/** 默认值 9999 */
public static final long DEFAULT_VALUE = (long) 9999;// 如数据库非null字段情况下,给一个默认值
/** 默认值 0001-01-01 */
public static final String DEFAULT_DATE = "0001-01-01";// 日期为空的时候默认值,给一个默认值
/**
* 将字符编码转换成GBK码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toGBK(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, GBK);
}
/**
* 将字符编码转换成UTF-8码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toUTF8(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, UTF_8);
}
/**
* 将字符编码转换成US-ASCII码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toASCII(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, US_ASCII);
}
/**
* 将字符编码转换成UTF-16码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toUTF16(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, UTF_16);
}
/**
* 字符串编码转换的实现方法
*
* @param sStr
* 待转换编码的字符串
* @param sNewCharset
* 目标编码
* @return String
* @throws UnsupportedEncodingException
*/
public final static String changeCharset(String sStr, String sNewCharset) throws UnsupportedEncodingException {
// 用默认字符编码解码字符串。
byte[] aBits = sStr.getBytes();
// 用新的字符编码生成字符串
return new String(aBits, sNewCharset);
}
/**
* 将字符编码转换成ISO-8859-1码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toISO_8859_1(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, ISO_8859_1);
}
/**
* 将字符编码转换成UTF-16BE码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toUTF16BE(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, UTF_16BE);
}
/**
* 将字符编码转换成UTF-16LE码
*
* @param sStr
* @return String
* @throws UnsupportedEncodingException
*/
public final static String toUTF16LE(String sStr) throws UnsupportedEncodingException {
return changeCharset(sStr, UTF_16LE);
}
/**
* 字符串编码转换的实现方法
*
* @param sStr
* 待转换编码的字符串
* @param sOldCharset
* 原编码
* @param sNewCharset
* 目标编码
* @return String
* @throws UnsupportedEncodingException
*/
public final static String changeCharset(String sStr, String sOldCharset, String sNewCharset)
throws UnsupportedEncodingException {
// 用旧的字符编码解码字符串。解码可能会出现异常。
byte[] aBits = sStr.getBytes(sOldCharset);
// 用新的字符编码生成字符串
return new String(aBits, sNewCharset);
}
/**
* 返回正则表达式的结果集
*
* @param sStr
* @param sPattern
* @return List<String>
*/
public final static List<String> getRegexResult(String sStr, String sPattern) {
ArrayList<String> aList = new ArrayList<String>();
Pattern oPattern = Pattern.compile(sPattern);
Matcher oMatcher = oPattern.matcher(sStr);
while (oMatcher.find()) {
for (int i = 1, nTotal = oMatcher.groupCount(); i <= nTotal; i++) {
aList.add(oMatcher.group(i));
}
}
return aList;
}
/**
* 字符串正则表达式替换
*
* @param sSource
* @param sReplace
* @param sPattern
* @return String
*/
public final static String getRegexReplaceResult(String sSource, String sReplace, String sPattern) {
Pattern oPattern = Pattern.compile(sPattern);
Matcher oMatcher = oPattern.matcher(sSource);
return oMatcher.replaceAll(sReplace);
}
/**
* 正则表达式检查结果
*
* @param sStr
* @param sPattern
* @return boolean
*/
public final static boolean checkMather(String sStr, String sPattern) {
Pattern oPattern = Pattern.compile(sPattern);
Matcher oMather = oPattern.matcher(sStr);
return oMather.matches();
}
/**
* 如果字符串为空则用默认值
*
* @param sStr
* @param sDefault
* @return String
*/
public final static String toStr(Object sStr, String sDefault) {
return sStr == null ? sDefault : sStr.toString().trim();
}
/**
* 如果字符串为空则用默认值
*
* @param sStr
* @param sDefault
* @return String
*/
public final static String toStrNOTrim(Object sStr, String sDefault) {
return sStr == null ? sDefault : sStr.toString();
}
/**
* 把字符串转换成整数
*
* @param sValue
* @param nDefault
* @return int
*/
public final static int toInt(String sValue, int nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
try {
return Integer.valueOf(sValue);
} catch (Exception ex) {
return nDefault;
}
}
/**
* 把字符串转换成Long数
*
* @param sValue
* @param nDefault
* @return int
*/
public final static Long toLong(String sValue, Long nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
try {
return Long.valueOf(sValue);
} catch (Exception ex) {
return nDefault;
}
}
/**
* 把字符串转换成小数
*
* @param sValue
* @param nDefault
* @return Float
*/
public final static Float toFloat(String sValue, Float nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
return Float.valueOf(sValue);
}
/**
* 把字符串转换成双精度小数
*
* @param sValue
* @param nDefault
* @return Double
*/
public final static Double toDouble(String sValue, Double nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
return Double.valueOf(sValue);
}
/**
* 把字符串转换成浮点
*
* @param sValue
* @param nDefault
* @return float
*/
public final static float toFloat(String sValue, float nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
return Float.valueOf(sValue);
}
/**
* 把字符串转换成 布尔型
*
* @param sValue
* @param nDefault
* @return boolean
*/
public final static boolean toBoolean(String sValue, boolean nDefault) {
if (sValue == null || sValue.isEmpty())
return nDefault;
return Boolean.valueOf(sValue);
}
/**
* 数据显示小数点问题
*
* @param d
* @return
*/
public final static String doubleToStr(Double dd) {
if (null == dd) {
return "";
}
double d = dd;
double c = d - (int) d;
if (c == 0)
return (int) d + "";
else {
BigDecimal b = new BigDecimal(d);
BigDecimal one = new BigDecimal("1");
c = b.divide(one, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
return String.valueOf(c);
}
}
public final static String floatToStr(float d) {
if (Math.round(d) - d == 0) {
return String.valueOf((long) d);
}
return String.valueOf(d);
}
/**
* 字符串 : 解决数据库入库时候的非法符号 转 HTML 符号
*
* @param sStr
* @param sDefault
* @return
*/
public final static String toHtml(Object sStr, String sDefault) {
String sValue = sStr == null ? sDefault : sStr.toString();
sValue = sValue.replaceAll("<", "<");
sValue = sValue.replaceAll(">", ">");
sValue = sValue.replaceAll("&", "&");
return sValue;
}
/**
* 获取八位不重复随机码(取当前时间戳转化为16进制)
*
* @param time
* @return
*/
public final static String toHex(long time) {
return Integer.toHexString((int) time);
}
public static String getVerificationCode(int count, Boolean isLetter) {
String[] beforeLetterShuffle = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
String[] beforeNumberShuffle = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "8" };
List<String> list = Arrays.asList(isLetter ? beforeLetterShuffle : beforeNumberShuffle);
Collections.shuffle(list);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
}
String afterShuffle = sb.toString();
String result = afterShuffle.substring(0, count);
return result;
}
/**
* 检测字符串是否为空(null,"","null")
*
* @param value
* @return 为空则返回true,否则返回false
*/
public final static boolean isNullOrEmpty(String value) {
return value == null || "".equals(value.trim()) || "null".equals(value.trim());
}
/**
* 判断在values数组中是否存在value元素
*
* @param values
* 数组
* @param value
* 字符串
* @return 存在,返回true。反之,false。
*/
public static boolean contains(String[] values, String value) {
if (values != null && values.length > 0) {
for (String s : values) {
if (s != null) {
if (s.equals(value)) {
return true;
}
}
}
}
return false;
}
/**
* json字符串转换为List<Map<String, Object>>
*
* @param jsonString
* @return
*/
public final static List<Map<String, Object>> toMapList(String jsonString) {
List<Map<String, Object>> mapList = new ArrayList<>();
if (!StrUtil.isNullOrEmpty(jsonString)) {
mapList = new Gson().fromJson(jsonString, new TypeToken<ArrayList<Map<String, Object>>>() {
}.getType());
}
return mapList;
}
/**
* json字符串转换为Map<String, Object>
*
* @param jsonString
* @return
*/
public final static Map<String, Object> toMap(String jsonString) {
Map<String, Object> map = new HashMap<>();
if (!StrUtil.isNullOrEmpty(jsonString)) {
map = new Gson().fromJson(jsonString, new TypeToken<Map<String, Object>>() {
}.getType());
}
return map;
}
}
================================================
FILE: src/cn/mayongfa/controller/AccountController.java
================================================
package cn.mayongfa.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;
import cn.mayongfa.activemq.MessageSender;
import cn.mayongfa.common.MD5Util;
import cn.mayongfa.common.StrUtil;
import cn.mayongfa.interceptor.Authority;
import cn.mayongfa.interceptor.AuthorityType;
import cn.mayongfa.model.UserBasis;
import cn.mayongfa.service.UserBasisService;
@Controller
@Authority(AuthorityType.NoValidate)
@RequestMapping("/account/*")
public class AccountController {
@Autowired
private UserBasisService userBasisService;
@Autowired
private MessageSender messageSender;
/**
* login
*
*/
@Authority(AuthorityType.Validate)
@ResponseBody
@RequestMapping(value = "login", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST })
public String login(@RequestParam("phone") String phone, @RequestParam("password") String password) {
int code = -1;
String msg = "";
if (StrUtil.isNullOrEmpty(phone)) {
msg = "请填写用户帐号!";
} else if (StrUtil.isNullOrEmpty(password)) {
msg = "请填写密码!";
} else {
UserBasis entity = userBasisService.getEntity(phone);
if (entity != null && entity.getId() > 0) {
if (entity.getPassword().equals(MD5Util.GetMD5Code32(password))) {
code = 1;
msg = "登录成功!";
messageSender.userLogin(entity.getId(), entity.getName());
// TODO:
} else {
msg = "用户密码错误!";
}
} else {
msg = "用户不存在!";
}
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", "");
return new Gson().toJson(responseMap);
}
}
================================================
FILE: src/cn/mayongfa/dao/UserBasisDao.java
================================================
package cn.mayongfa.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import cn.mayongfa.common.DateUtil;
import cn.mayongfa.common.IdWorkerManage;
import cn.mayongfa.common.StrUtil;
import cn.mayongfa.model.UserBasis;
@Repository
public class UserBasisDao {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 保存
*
* @param entity
* ID=0 新增
* @return
*/
public long Save(UserBasis entity) {
long ID = 0;
try {
if (entity.getId() == StrUtil.DEFAULT_NULL) {
// 新增
entity.setId(IdWorkerManage.getId());
String strSql = "insert into userbasis (id,name,password,phone,status,createtime,updatetime) values (?,?,?,?,?,?,?)";
Object obj[] = { entity.getId(), entity.getName(), entity.getPassword(), entity.getPhone(),
entity.getStatus(), entity.getCreatetime(), entity.getUpdatetime() };
int ret = jdbcTemplate.update(strSql, obj);
if (ret > 0) {
ID = entity.getId();
}
} else {
// 修改
String strSql = "update userbasis set id=?,name=?,password=?,phone=?,status=?,updatetime=? where id=?";
Object obj[] = { entity.getId(), entity.getName(), entity.getPassword(), entity.getPhone(),
entity.getStatus(), entity.getUpdatetime(), entity.getId() };
int ret = jdbcTemplate.update(strSql, obj);
if (ret > 0) {
ID = entity.getId();
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return ID;
}
/**
* 删除
*
* @param ID
* @return
*/
public Boolean Delete(long ID) {
String strSql = "delete from userbasis where id=?";
Object obj[] = { DateUtil.dateToLong(), ID };
int ret = jdbcTemplate.update(strSql, obj);
return ret > 0;
}
/**
* 获取
*
* @param ID
* @return
*/
public UserBasis getEntity(long ID) {
final UserBasis entity = new UserBasis();
String strSql = "select id,name,password,phone,status,createtime,updatetime from userbasis where id=?";
jdbcTemplate.query(strSql, new Object[] { ID }, new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
entity.setId(rs.getLong("id"));
entity.setName(rs.getString("name"));
entity.setPassword(rs.getString("password"));
entity.setPhone(rs.getString("phone"));
entity.setStatus(rs.getInt("status"));
entity.setCreatetime(rs.getDate("createtime"));
entity.setUpdatetime(rs.getDate("updatetime"));
}
});
return entity;
}
/**
* 获取
*
* @param ID
* @return
*/
public UserBasis getEntity(String phone) {
final UserBasis entity = new UserBasis();
String strSql = "select id,name,password,phone,status,createtime,updatetime from userbasis where phone=?";
jdbcTemplate.query(strSql, new Object[] { phone }, new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
entity.setId(rs.getLong("id"));
entity.setName(rs.getString("name"));
entity.setPassword(rs.getString("password"));
entity.setPhone(rs.getString("phone"));
entity.setStatus(rs.getInt("status"));
entity.setCreatetime(rs.getDate("createtime"));
entity.setUpdatetime(rs.getDate("updatetime"));
}
});
return entity;
}
/**
* 根据条件获取
*
* @return
*/
public List<UserBasis> getList(Map<String, Object> whereMap, String OrderBy, int nStart, int nLimit) {
final ArrayList<UserBasis> list = new ArrayList<UserBasis>();
String basisSql = "select id,name,password,phone,status,createtime,updatetime from userbasis ";
String strSql = "select id from userbasis where 1=1";
StringBuffer whereSql = new StringBuffer();
List<Object> whereobj = new ArrayList<Object>();
if (whereMap.containsKey("id")) {
long id = (long) whereMap.get("id");
whereSql.append(" and id=?");
whereobj.add(id);
}
if (whereMap.containsKey("name")) {
String name = (String) whereMap.get("name");
whereSql.append(" and name=?");
whereobj.add(name);
}
if (whereMap.containsKey("password")) {
String password = (String) whereMap.get("password");
whereSql.append(" and password=?");
whereobj.add(password);
}
if (whereMap.containsKey("phone")) {
String phone = (String) whereMap.get("phone");
whereSql.append(" and phone=?");
whereobj.add(phone);
}
if (whereMap.containsKey("status")) {
int status = (int) whereMap.get("status");
whereSql.append(" and status=?");
whereobj.add(status);
}
if (OrderBy == "")
OrderBy = "createtime asc";
whereSql.append(" order by " + OrderBy + " limit " + nStart + "," + nLimit);
strSql = strSql + whereSql;
Object obj[] = whereobj.toArray(new Object[whereobj.size()]);
basisSql += " INNER JOIN (" + strSql + ") userbasis_id USING (id)";
jdbcTemplate.query(basisSql, obj, new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
UserBasis entity = new UserBasis();
entity.setId(rs.getLong("id"));
entity.setName(rs.getString("name"));
entity.setPassword(rs.getString("password"));
entity.setPhone(rs.getString("phone"));
entity.setStatus(rs.getInt("status"));
entity.setCreatetime(rs.getDate("createtime"));
entity.setUpdatetime(rs.getDate("updatetime"));
list.add(entity);
}
});
return list;
}
/**
* 根据条件获取数据条数
*
* @return
*/
public int getListCount(Map<String, Object> whereMap) {
String strSql = "select count(id) from userbasis where 1=1";
StringBuffer whereSql = new StringBuffer();
List<Object> whereobj = new ArrayList<Object>();
if (whereMap.containsKey("id")) {
long id = (long) whereMap.get("id");
whereSql.append(" and id=?");
whereobj.add(id);
}
if (whereMap.containsKey("name")) {
String name = (String) whereMap.get("name");
whereSql.append(" and name=?");
whereobj.add(name);
}
if (whereMap.containsKey("password")) {
String password = (String) whereMap.get("password");
whereSql.append(" and password=?");
whereobj.add(password);
}
if (whereMap.containsKey("phone")) {
String phone = (String) whereMap.get("phone");
whereSql.append(" and phone=?");
whereobj.add(phone);
}
if (whereMap.containsKey("status")) {
int status = (int) whereMap.get("status");
whereSql.append(" and status=?");
whereobj.add(status);
}
strSql = strSql + whereSql;
Object obj[] = whereobj.toArray(new Object[whereobj.size()]);
return jdbcTemplate.queryForObject(strSql, obj, Integer.class);
}
/**
* 获取所有
*
* @return
*/
public List<UserBasis> getList() {
final ArrayList<UserBasis> list = new ArrayList<UserBasis>();
String strSql = "select id,name,password,phone,status,createtime,updatetime from userbasis ";
jdbcTemplate.query(strSql, new Object[] {}, new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
UserBasis entity = new UserBasis();
entity.setId(rs.getLong("id"));
entity.setName(rs.getString("name"));
entity.setPassword(rs.getString("password"));
entity.setPhone(rs.getString("phone"));
entity.setStatus(rs.getInt("status"));
entity.setCreatetime(rs.getDate("createtime"));
entity.setUpdatetime(rs.getDate("updatetime"));
list.add(entity);
}
});
return list;
}
}
================================================
FILE: src/cn/mayongfa/interceptor/Authority.java
================================================
package cn.mayongfa.interceptor;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.METHOD, ElementType.TYPE })
@Documented
public @interface Authority {
// 默认验证
AuthorityType value() default AuthorityType.Validate;
}
================================================
FILE: src/cn/mayongfa/interceptor/AuthorityAnnotationInterceptor.java
================================================
package cn.mayongfa.interceptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.google.gson.Gson;
/**
* 权限认证拦截器
*
*/
public class AuthorityAnnotationInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod) handler;
Class<?> clazz = hm.getBeanType();
Method m = hm.getMethod();
try {
if (clazz != null && m != null) {
boolean isClzAnnotation = clazz.isAnnotationPresent(Authority.class);
boolean isMethondAnnotation = m.isAnnotationPresent(Authority.class);
Authority authority = null;
// 如果方法和类声明中同时存在这个注解,那么方法中的会覆盖类中的设定。
if (isMethondAnnotation) {
authority = m.getAnnotation(Authority.class);
} else if (isClzAnnotation) {
authority = clazz.getAnnotation(Authority.class);
}
int code = -1;
String msg = "";
if (authority != null) {
if (AuthorityType.NoValidate == authority.value()) {
// 标记为不验证,放行
return true;
} else if (AuthorityType.NoAuthority == authority.value()) {
// 不验证权限,验证是否登录
// TODO:
return true;
} else {
// 验证登录及权限
// TODO:
code = 1;
msg = "验证成功!";
return true;
}
}
// //跳转
// String url = "";
// response.getWriter().write("<script>top.location.href='"
// + url + "'</script>");
// return false;
// 未通过验证,返回提示json
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("code", code);
responseMap.put("msg", msg);
responseMap.put("params", "");
responseMap.put("rows", "");
String json = new Gson().toJson(responseMap);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.getWriter().write(json);
return false;
}
} catch (Exception e) {
}
}
return false;
}
}
================================================
FILE: src/cn/mayongfa/interceptor/AuthorityType.java
================================================
package cn.mayongfa.interceptor;
public enum AuthorityType {
// 登录和权限都验证 默认
Validate,
// 不验证
NoValidate,
// 不验证权限
NoAuthority;
}
================================================
FILE: src/cn/mayongfa/interceptor/DataSource.java
================================================
package cn.mayongfa.interceptor;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public @interface DataSource {
DataSourceType value() default DataSourceType.Master;
}
================================================
FILE: src/cn/mayongfa/interceptor/DataSourceChoose.java
================================================
package cn.mayongfa.interceptor;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import cn.mayongfa.common.JdbcContextHolder;
public class DataSourceChoose {
//方法执行前
public void before(JoinPoint point){
Object target = point.getTarget();
String method = point.getSignature().getName();
Class<?>[] classz = target.getClass().getInterfaces();
MethodSignature methodSignature = (MethodSignature)point.getSignature();
Class<?>[] parameterTypes = methodSignature.getMethod().getParameterTypes();
try {
Method m = classz[0].getMethod(method, parameterTypes);
if (m!=null && m.isAnnotationPresent(DataSource.class)) {
DataSource data = m.getAnnotation(DataSource.class);
JdbcContextHolder.clearJdbcType();
JdbcContextHolder.setJdbcType(data.value().getName());
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
================================================
FILE: src/cn/mayongfa/interceptor/DataSourceType.java
================================================
package cn.mayongfa.interceptor;
public enum DataSourceType {
// 主库
Master("master"),
// 从库
Slave("slave"),
// 金币主库
GoldMaster("master"),
// 金币从库
GoldSlave("slave");
private DataSourceType(String name) {
this.name = name;
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
================================================
FILE: src/cn/mayongfa/interceptor/TestInterceptor.java
================================================
package cn.mayongfa.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class TestInterceptor extends HandlerInterceptorAdapter {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// 请求处理完成之后
System.out.println("请求处理完成啦!");
super.afterCompletion(request, response, handler, ex);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// 处理器执行完毕之后
System.out.println("处理器执行完毕啦!");
super.postHandle(request, response, handler, modelAndView);
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
// 处理器实际执行之前
System.out.println("处理器执行之前!");
return super.preHandle(request, response, handler);
}
}
================================================
FILE: src/cn/mayongfa/model/UserBasis.java
================================================
package cn.mayongfa.model;
import java.io.Serializable;
@SuppressWarnings("serial")
public class UserBasis implements Serializable{
private long id;
private String name;
private String password;
private String phone;
private int status;
private java.util.Date createtime;
private java.util.Date updatetime;
public void setId(long value) {
this.id = value;
}
public long getId() {
return this.id;
}
public void setName(String value) {
this.name = value;
}
public String getName() {
return this.name;
}
public void setPassword(String value) {
this.password = value;
}
public String getPassword() {
return this.password;
}
public void setPhone(String value) {
this.phone = value;
}
public String getPhone() {
return this.phone;
}
public void setStatus(int value) {
this.status = value;
}
public int getStatus() {
return this.status;
}
public void setCreatetime(java.util.Date value) {
this.createtime = value;
}
public java.util.Date getCreatetime() {
return this.createtime;
}
public void setUpdatetime(java.util.Date value) {
this.updatetime = value;
}
public java.util.Date getUpdatetime() {
return this.updatetime;
}
}
================================================
FILE: src/cn/mayongfa/quartz/GlodQuartz.java
================================================
package cn.mayongfa.quartz;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 业务相关的作业调度
*
字段 允许值 允许的特殊字符
秒 0-59 , - * /
分 0-59 , - * /
小时 0-23 , - * /
日期 1-31 , - * ? / L W C
月份 1-12 或者 JAN-DEC , - * /
星期 1-7 或者 SUN-SAT , - * ? / L C #
年(可选) 留空, 1970-2099 , - * /
* 字符代表所有可能的值
/ 字符用来指定数值的增量
L 字符仅被用于天(月)和天(星期)两个子表达式,表示一个月的最后一天或者一个星期的最后一天
6L 可以表示倒数第6天
*
*/
@Component
public class GlodQuartz {
/**
* 用户自动加金币
* 每天凌晨一点执行一次
*/
@Scheduled(cron = "0 0 1 * * ? ")
public void addUserGold() {
System.out.println("凌晨一点了,你睡了么?");
}
/**
* 每隔5秒定时清理缓存
*/
@Scheduled(cron = "*/5 * * * * ? ")
public void cacheClear() {
//System.out.println("时间又过去5秒了,真令人伤感...");
}
}
================================================
FILE: src/cn/mayongfa/service/UserBasisService.java
================================================
package cn.mayongfa.service;
import java.util.List;
import java.util.Map;
import cn.mayongfa.interceptor.DataSource;
import cn.mayongfa.interceptor.DataSourceType;
import cn.mayongfa.model.UserBasis;
public interface UserBasisService {
/**
* 保存
* @param entity
* @return
*/
@DataSource
public long Save(UserBasis entity);
/**
* 删除
* @param ID
* @return
*/
@DataSource
public Boolean Delete(long ID);
/**
* 获取信息
* @param ID
* @return
*/
@DataSource(DataSourceType.Slave)
public UserBasis getEntity(long ID);
/**
* 获取信息
* @param phone
* @return
*/
@DataSource(DataSourceType.Slave)
public UserBasis getEntity(String phone);
/**
* 根据条件获取
* @return
*/
@DataSource(DataSourceType.Slave)
public List<UserBasis> getList(Map<String, Object> whereMap, String OrderBy, int nStart, int nLimit);
/**
* 根据条件获取数据条数
* @return
*/
@DataSource(DataSourceType.Slave)
public int getListCount(Map<String, Object> whereMap);
/**
* 获取所有
* @return
*/
@DataSource(DataSourceType.Slave)
public List<UserBasis> getList();
}
================================================
FILE: src/cn/mayongfa/service/imp/UserBasisServiceImp.java
================================================
package cn.mayongfa.service.imp;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.mayongfa.cache.UserBasisCache;
import cn.mayongfa.dao.UserBasisDao;
import cn.mayongfa.model.UserBasis;
import cn.mayongfa.service.UserBasisService;
@Service
public class UserBasisServiceImp implements UserBasisService {
@Autowired
private UserBasisDao UserBasisdao;
@Autowired
private UserBasisCache UserBasiscache;
@Override
public long Save(UserBasis entity) {
long id = UserBasisdao.Save(entity);
if (id > 0) {
UserBasiscache.set(entity);
}
return id;
}
@Override
public Boolean Delete(long ID) {
boolean result = UserBasisdao.Delete(ID);
if (result) {
UserBasiscache.delete(ID);
}
return result;
}
@Override
public UserBasis getEntity(long ID) {
return UserBasiscache.get(ID);
}
@Override
public UserBasis getEntity(String phone) {
return UserBasisdao.getEntity(phone);
}
@Override
public int getListCount(Map<String, Object> whereMap) {
throw new RuntimeException();
// return UserBasisdao.getListCount(whereMap);
}
@Override
public List<UserBasis> getList(Map<String, Object> whereMap, String OrderBy, int nStart, int nLimit) {
return UserBasisdao.getList(whereMap, OrderBy, nStart, nLimit);
}
@Override
public List<UserBasis> getList() {
return UserBasisdao.getList();
}
}
================================================
FILE: src/global.properties
================================================
jxb.global.defaultavatar=
jxb.global.defaultphoto=
================================================
FILE: src/jdbc.properties
================================================
master.jdbc.driverClassName=com.mysql.jdbc.Driver
master.jdbc.url=jdbc:mysql://127.0.0.1:3306/springdemo?useUnicode=true&characterEncoding=UTF-8
master.jdbc.username=root
master.jdbc.password=123456
slave.jdbc.driverClassName=com.mysql.jdbc.Driver
slave.jdbc.url=jdbc:mysql://172.16.100.222:3306/springdemo?useUnicode=true&characterEncoding=UTF-8
slave.jdbc.username=read
slave.jdbc.password=123456
goldMaster.jdbc.driverClassName=com.mysql.jdbc.Driver
goldMaster.jdbc.url=jdbc:mysql://127.0.0.1:3306/springdemo?useUnicode=true&characterEncoding=UTF-8
goldMaster.jdbc.username=root
goldMaster.jdbc.password=123456
goldSlave.jdbc.driverClassName=com.mysql.jdbc.Driver
goldSlave.jdbc.url=jdbc:mysql://172.16.100.222:3306/springdemo?useUnicode=true&characterEncoding=UTF-8
goldSlave.jdbc.username=read
goldSlave.jdbc.password=123456
================================================
FILE: src/log4j.properties
================================================
# Priorities are: DEBUG, INFO, WARN, ERROR, or FATAL.
log4j.rootCategory=INFO, CONSOLE,Druid
#log4j.rootCategory=INFO, FILE
#log4j.logger.cn.com.pkit=DEBUG
logs.dir=${catalina.base}/logs/xdjxb/
logs.filename=logs
fileBufferSize=20480
#log to File
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${logs.dir}/${logs.filename}
log4j.appender.FILE.encoding=UTF-8
log4j.appender.FILE.Append=true
log4j.appender.FILE.LocationInfo=true
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%-5p] %d(%r) --> %l: %m %x %n
log4j.appender.FILE.bufferSize=${fileBufferSize}
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=DEBUG
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
#Druid log to File
log4j.logger.druid.sql=warn,Druid
log4j.logger.druid.sql.DataSource=warn,Druid
log4j.logger.druid.sql.Connection=warn,Druid
log4j.logger.druid.sql.Statement=warn,Druid
log4j.logger.druid.sql.ResultSet=warn,Druid
log4j.appender.Druid=org.apache.log4j.DailyRollingFileAppender
log4j.appender.Druid.File=${logs.dir}/slowsql
log4j.appender.Druid.encoding=UTF-8
log4j.appender.Druid.Append=true
log4j.appender.Druid.LocationInfo=true
log4j.appender.Druid.Threshold=warn
log4j.appender.Druid.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.Druid.layout=org.apache.log4j.PatternLayout
log4j.appender.Druid.layout.ConversionPattern=[%-5p] %d(%r) - %m %n
log4j.appender.Druid.bufferSize=${fileBufferSize}
================================================
FILE: src/memcached.properties
================================================
#\u8FDE\u63A5\u6C60\u5927\u5C0F\u5373\u5BA2\u6237\u7AEF\u4E2A\u6570
memcached.connectionPoolSize=10
memcached.failureMode=true
#server1
server1.memcached.host=127.0.0.1
server1.memcached.port=11211
server1.memcached.weight=4
#server2
server2.memcached.host=127.0.0.1
server2.memcached.port=11211
server2.memcached.weight=6
gitextract_vs5nz4fg/
├── .classpath
├── .gitignore
├── .project
├── .settings/
│ ├── .jsdtscope
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.wst.common.component
│ ├── org.eclipse.wst.common.project.facet.core.xml
│ ├── org.eclipse.wst.jsdt.ui.superType.container
│ └── org.eclipse.wst.jsdt.ui.superType.name
├── WebContent/
│ ├── META-INF/
│ │ └── MANIFEST.MF
│ ├── WEB-INF/
│ │ ├── applicationContext.xml
│ │ ├── lib/
│ │ │ ├── AXMLPrinter2.jar
│ │ │ ├── activemq-broker-5.13.0.jar
│ │ │ ├── activemq-client-5.13.0.jar
│ │ │ ├── activemq-console-5.13.0.jar
│ │ │ ├── activemq-jaas-5.13.0.jar
│ │ │ ├── activemq-pool-5.13.0.jar
│ │ │ ├── activemq-protobuf-1.1.jar
│ │ │ ├── activemq-spring-5.13.0.jar
│ │ │ ├── activemq-web-5.13.0.jar
│ │ │ ├── aopalliance.jar
│ │ │ ├── aspectjweaver-1.6.9.jar
│ │ │ ├── commons-beanutils.jar
│ │ │ ├── commons-collections.jar
│ │ │ ├── commons-fileupload-1.3.1.jar
│ │ │ ├── commons-io-2.4.jar
│ │ │ ├── commons-lang.jar
│ │ │ ├── commons-logging-1.1.3.jar
│ │ │ ├── dom4j-1.6.1.jar
│ │ │ ├── druid-1.0.9.jar
│ │ │ ├── freemarker.jar
│ │ │ ├── geronimo-j2ee-management_1.1_spec-1.0.1.jar
│ │ │ ├── geronimo-jms_1.1_spec-1.1.1.jar
│ │ │ ├── geronimo-jta_1.0.1B_spec-1.0.1.jar
│ │ │ ├── gson-2.5.jar
│ │ │ ├── httpclient-4.5.2.jar
│ │ │ ├── httpcore-4.4.4.jar
│ │ │ ├── jaxen-1.1-beta-6.jar
│ │ │ ├── jdom.jar
│ │ │ ├── jpush-client-3.2.9.jar
│ │ │ ├── jstl-1.2.1.jar
│ │ │ ├── jstl-api-1.2.1.jar
│ │ │ ├── log4j-1.2.17.jar
│ │ │ ├── mchange-commons-java-0.2.3.1.jar
│ │ │ ├── mysql-connector-java-5.1.18.jar
│ │ │ ├── okhttp-2.7.2.jar
│ │ │ ├── okio-1.6.0.jar
│ │ │ ├── poi-3.9-20121203.jar
│ │ │ ├── poi-ooxml-3.9-20121203.jar
│ │ │ ├── poi-ooxml-schemas-3.9-20121203.jar
│ │ │ ├── servlet-api.jar
│ │ │ ├── slf4j-api-1.7.13.jar
│ │ │ ├── slf4j-log4j12-1.7.21.jar
│ │ │ ├── spring-aop-4.2.6.RELEASE.jar
│ │ │ ├── spring-beans-4.2.6.RELEASE.jar
│ │ │ ├── spring-context-4.2.6.RELEASE.jar
│ │ │ ├── spring-context-support-4.2.6.RELEASE.jar
│ │ │ ├── spring-core-4.2.6.RELEASE.jar
│ │ │ ├── spring-expression-4.2.6.RELEASE.jar
│ │ │ ├── spring-jdbc-4.2.6.RELEASE.jar
│ │ │ ├── spring-jms-4.2.6.RELEASE.jar
│ │ │ ├── spring-tx-4.2.6.RELEASE.jar
│ │ │ ├── spring-web-4.2.6.RELEASE.jar
│ │ │ ├── spring-webmvc-4.2.6.RELEASE.jar
│ │ │ ├── xmemcached-1.3.8.jar
│ │ │ └── xmlbeans-2.3.0.jar
│ │ ├── springMVC-servlet.xml
│ │ └── web.xml
│ └── index.html
└── src/
├── cn/
│ └── mayongfa/
│ ├── activemq/
│ │ ├── ActiveMQTransportListener.java
│ │ ├── ConsumerMessageListener.java
│ │ └── MessageSender.java
│ ├── api/
│ │ └── controller/
│ │ └── UserController.java
│ ├── cache/
│ │ ├── MemcachedBasis.java
│ │ └── UserBasisCache.java
│ ├── common/
│ │ ├── DateUtil.java
│ │ ├── DynamicDataSource.java
│ │ ├── ExceptionHandler.java
│ │ ├── IdWorker.java
│ │ ├── IdWorkerManage.java
│ │ ├── JdbcContextHolder.java
│ │ ├── MD5Util.java
│ │ └── StrUtil.java
│ ├── controller/
│ │ └── AccountController.java
│ ├── dao/
│ │ └── UserBasisDao.java
│ ├── interceptor/
│ │ ├── Authority.java
│ │ ├── AuthorityAnnotationInterceptor.java
│ │ ├── AuthorityType.java
│ │ ├── DataSource.java
│ │ ├── DataSourceChoose.java
│ │ ├── DataSourceType.java
│ │ └── TestInterceptor.java
│ ├── model/
│ │ └── UserBasis.java
│ ├── quartz/
│ │ └── GlodQuartz.java
│ └── service/
│ ├── UserBasisService.java
│ └── imp/
│ └── UserBasisServiceImp.java
├── global.properties
├── jdbc.properties
├── log4j.properties
└── memcached.properties
SYMBOL INDEX (148 symbols across 25 files)
FILE: src/cn/mayongfa/activemq/ActiveMQTransportListener.java
class ActiveMQTransportListener (line 13) | public class ActiveMQTransportListener implements TransportListener {
method onCommand (line 21) | @Override
method onException (line 30) | @Override
method transportInterupted (line 38) | @Override
method transportResumed (line 48) | @Override
FILE: src/cn/mayongfa/activemq/ConsumerMessageListener.java
class ConsumerMessageListener (line 16) | @Component
method onMessage (line 21) | @Override
FILE: src/cn/mayongfa/activemq/MessageSender.java
class MessageSender (line 25) | @Component
method userLogin (line 42) | public void userLogin(long id, String username) {
method sendMessage (line 59) | public void sendMessage(final String messgae, int type) {
FILE: src/cn/mayongfa/api/controller/UserController.java
class UserController (line 27) | @Controller
method get (line 42) | @ResponseBody
method getList (line 72) | @CrossOrigin(origins = "*", maxAge = 3600)
method post (line 102) | @ResponseBody
method delete (line 146) | @ResponseBody
method put (line 173) | @ResponseBody
FILE: src/cn/mayongfa/cache/MemcachedBasis.java
class MemcachedBasis (line 8) | @Component
FILE: src/cn/mayongfa/cache/UserBasisCache.java
class UserBasisCache (line 13) | @Component
method set (line 27) | public Boolean set(UserBasis model) {
method get (line 44) | public UserBasis get(long id) {
method delete (line 66) | public Boolean delete(long id) {
method getCacheKey (line 82) | private String getCacheKey(long id) {
FILE: src/cn/mayongfa/common/DateUtil.java
class DateUtil (line 9) | public class DateUtil {
method dateToString (line 18) | public static String dateToString(Date date, String formatType) {
method longToString (line 31) | public static String longToString(long currentTime, String formatType){
method longToString (line 55) | public static String longToString(long currentTime, String oldFormatTy...
method stringToDate (line 69) | public static Date stringToDate(String strTime, String formatType) {
method longToDate (line 89) | public static Date longToDate(long currentTime, String formatType) {
method stringToLong (line 108) | public static long stringToLong(String strTime, String formatType) {
method dateToLong (line 129) | public static long dateToLong(Date date) {
method dateToLong (line 137) | public static long dateToLong() {
method unixToLong (line 146) | public static long unixToLong(long unix){
method getTimePosition (line 161) | public static String getTimePosition(long time){
FILE: src/cn/mayongfa/common/DynamicDataSource.java
class DynamicDataSource (line 7) | public class DynamicDataSource extends AbstractRoutingDataSource {
method determineCurrentLookupKey (line 9) | @Override
FILE: src/cn/mayongfa/common/ExceptionHandler.java
class ExceptionHandler (line 17) | @Component
method resolveException (line 22) | @Override
FILE: src/cn/mayongfa/common/IdWorker.java
class IdWorker (line 12) | public class IdWorker {
method IdWorker (line 52) | public IdWorker(long workerId, long datacenterId) {
method IdWorker (line 68) | public IdWorker() {
method nextId (line 88) | protected synchronized long nextId() {
method tilNextMillis (line 125) | protected long tilNextMillis(long lastTimestamp) {
method timeGen (line 140) | protected long timeGen() {
method get_worker_id (line 145) | public long get_worker_id() throws Exception {
method get_timestamp (line 149) | public long get_timestamp() throws Exception {
method get_id (line 153) | public long get_id(String useragent) throws Exception {
method get_datacenter_id (line 162) | public long get_datacenter_id() throws Exception {
FILE: src/cn/mayongfa/common/IdWorkerManage.java
class IdWorkerManage (line 3) | public class IdWorkerManage {
method getIdWorkerInstance (line 17) | private static IdWorker getIdWorkerInstance() {
method getId (line 30) | public static long getId() throws Exception {
FILE: src/cn/mayongfa/common/JdbcContextHolder.java
class JdbcContextHolder (line 3) | public class JdbcContextHolder {
method setJdbcType (line 7) | public static void setJdbcType(String jdbcType) {
method setSlave (line 11) | public static void setSlave() {
method setMaster (line 15) | public static void setMaster() {
method getJdbcType (line 19) | public static String getJdbcType() {
method clearJdbcType (line 23) | public static void clearJdbcType() {
FILE: src/cn/mayongfa/common/MD5Util.java
class MD5Util (line 7) | public class MD5Util {
method GetMD5Code16 (line 11) | public static String GetMD5Code16(String strObj) {
method GetMD5Code32 (line 15) | public static String GetMD5Code32(String strObj) {
method byteToString (line 29) | private static String byteToString(byte[] bByte) {
method byteToArrayString (line 38) | private static String byteToArrayString(byte bByte) {
FILE: src/cn/mayongfa/common/StrUtil.java
class StrUtil (line 23) | public final class StrUtil {
method toGBK (line 67) | public final static String toGBK(String sStr) throws UnsupportedEncodi...
method toUTF8 (line 78) | public final static String toUTF8(String sStr) throws UnsupportedEncod...
method toASCII (line 89) | public final static String toASCII(String sStr) throws UnsupportedEnco...
method toUTF16 (line 100) | public final static String toUTF16(String sStr) throws UnsupportedEnco...
method changeCharset (line 114) | public final static String changeCharset(String sStr, String sNewChars...
method toISO_8859_1 (line 128) | public final static String toISO_8859_1(String sStr) throws Unsupporte...
method toUTF16BE (line 139) | public final static String toUTF16BE(String sStr) throws UnsupportedEn...
method toUTF16LE (line 150) | public final static String toUTF16LE(String sStr) throws UnsupportedEn...
method changeCharset (line 166) | public final static String changeCharset(String sStr, String sOldChars...
method getRegexResult (line 181) | public final static List<String> getRegexResult(String sStr, String sP...
method getRegexReplaceResult (line 202) | public final static String getRegexReplaceResult(String sSource, Strin...
method checkMather (line 216) | public final static boolean checkMather(String sStr, String sPattern) {
method toStr (line 229) | public final static String toStr(Object sStr, String sDefault) {
method toStrNOTrim (line 240) | public final static String toStrNOTrim(Object sStr, String sDefault) {
method toInt (line 251) | public final static int toInt(String sValue, int nDefault) {
method toLong (line 269) | public final static Long toLong(String sValue, Long nDefault) {
method toFloat (line 287) | public final static Float toFloat(String sValue, Float nDefault) {
method toDouble (line 300) | public final static Double toDouble(String sValue, Double nDefault) {
method toFloat (line 313) | public final static float toFloat(String sValue, float nDefault) {
method toBoolean (line 326) | public final static boolean toBoolean(String sValue, boolean nDefault) {
method doubleToStr (line 338) | public final static String doubleToStr(Double dd) {
method floatToStr (line 354) | public final static String floatToStr(float d) {
method toHtml (line 368) | public final static String toHtml(Object sStr, String sDefault) {
method toHex (line 382) | public final static String toHex(long time) {
method getVerificationCode (line 386) | public static String getVerificationCode(int count, Boolean isLetter) {
method isNullOrEmpty (line 407) | public final static boolean isNullOrEmpty(String value) {
method contains (line 420) | public static boolean contains(String[] values, String value) {
method toMapList (line 439) | public final static List<Map<String, Object>> toMapList(String jsonStr...
method toMap (line 454) | public final static Map<String, Object> toMap(String jsonString) {
FILE: src/cn/mayongfa/controller/AccountController.java
class AccountController (line 23) | @Controller
method login (line 37) | @Authority(AuthorityType.Validate)
FILE: src/cn/mayongfa/dao/UserBasisDao.java
class UserBasisDao (line 19) | @Repository
method Save (line 32) | public long Save(UserBasis entity) {
method Delete (line 68) | public Boolean Delete(long ID) {
method getEntity (line 81) | public UserBasis getEntity(long ID) {
method getEntity (line 104) | public UserBasis getEntity(String phone) {
method getList (line 126) | public List<UserBasis> getList(Map<String, Object> whereMap, String Or...
method getListCount (line 184) | public int getListCount(Map<String, Object> whereMap) {
method getList (line 223) | public List<UserBasis> getList() {
FILE: src/cn/mayongfa/interceptor/AuthorityAnnotationInterceptor.java
class AuthorityAnnotationInterceptor (line 19) | public class AuthorityAnnotationInterceptor extends HandlerInterceptorAd...
method preHandle (line 21) | @Override
FILE: src/cn/mayongfa/interceptor/AuthorityType.java
type AuthorityType (line 3) | public enum AuthorityType {
FILE: src/cn/mayongfa/interceptor/DataSourceChoose.java
class DataSourceChoose (line 10) | public class DataSourceChoose {
method before (line 13) | public void before(JoinPoint point){
FILE: src/cn/mayongfa/interceptor/DataSourceType.java
type DataSourceType (line 3) | public enum DataSourceType {
method DataSourceType (line 17) | private DataSourceType(String name) {
method getName (line 23) | public String getName() {
method setName (line 27) | public void setName(String name) {
FILE: src/cn/mayongfa/interceptor/TestInterceptor.java
class TestInterceptor (line 9) | public class TestInterceptor extends HandlerInterceptorAdapter {
method afterCompletion (line 11) | @Override
method postHandle (line 19) | @Override
method preHandle (line 27) | @Override
FILE: src/cn/mayongfa/model/UserBasis.java
class UserBasis (line 5) | @SuppressWarnings("serial")
method setId (line 23) | public void setId(long value) {
method getId (line 26) | public long getId() {
method setName (line 30) | public void setName(String value) {
method getName (line 33) | public String getName() {
method setPassword (line 37) | public void setPassword(String value) {
method getPassword (line 40) | public String getPassword() {
method setPhone (line 44) | public void setPhone(String value) {
method getPhone (line 47) | public String getPhone() {
method setStatus (line 51) | public void setStatus(int value) {
method getStatus (line 54) | public int getStatus() {
method setCreatetime (line 58) | public void setCreatetime(java.util.Date value) {
method getCreatetime (line 61) | public java.util.Date getCreatetime() {
method setUpdatetime (line 65) | public void setUpdatetime(java.util.Date value) {
method getUpdatetime (line 68) | public java.util.Date getUpdatetime() {
FILE: src/cn/mayongfa/quartz/GlodQuartz.java
class GlodQuartz (line 25) | @Component
method addUserGold (line 32) | @Scheduled(cron = "0 0 1 * * ? ")
method cacheClear (line 39) | @Scheduled(cron = "*/5 * * * * ? ")
FILE: src/cn/mayongfa/service/UserBasisService.java
type UserBasisService (line 10) | public interface UserBasisService {
method Save (line 17) | @DataSource
method Delete (line 25) | @DataSource
method getEntity (line 33) | @DataSource(DataSourceType.Slave)
method getEntity (line 41) | @DataSource(DataSourceType.Slave)
method getList (line 48) | @DataSource(DataSourceType.Slave)
method getListCount (line 55) | @DataSource(DataSourceType.Slave)
method getList (line 62) | @DataSource(DataSourceType.Slave)
FILE: src/cn/mayongfa/service/imp/UserBasisServiceImp.java
class UserBasisServiceImp (line 14) | @Service
method Save (line 22) | @Override
method Delete (line 31) | @Override
method getEntity (line 40) | @Override
method getEntity (line 45) | @Override
method getListCount (line 50) | @Override
method getList (line 56) | @Override
method getList (line 61) | @Override
Condensed preview — 100 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (108K chars).
[
{
"path": ".classpath",
"chars": 5187,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"con\" "
},
{
"path": ".gitignore",
"chars": 8,
"preview": "/build/\n"
},
{
"path": ".project",
"chars": 1043,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<projectDescription>\r\n\t<name>SpringDemo</name>\r\n\t<comment></comment>\r\n\t<projects"
},
{
"path": ".settings/.jsdtscope",
"chars": 567,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<classpath>\r\n\t<classpathentry excluding=\"**/*.min.js|**/node_modules/*|**/bower_"
},
{
"path": ".settings/org.eclipse.jdt.core.prefs",
"chars": 364,
"preview": "eclipse.preferences.version=1\r\norg.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r\norg.eclipse.jdt.core.com"
},
{
"path": ".settings/org.eclipse.wst.common.component",
"chars": 482,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><project-modules id=\"moduleCoreId\" project-version=\"1.5.0\">\r\n <wb-module deploy"
},
{
"path": ".settings/org.eclipse.wst.common.project.facet.core.xml",
"chars": 254,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<faceted-project>\n <fixed facet=\"java\"/>\n <fixed facet=\"jst.web\"/>\n <fixed fac"
},
{
"path": ".settings/org.eclipse.wst.jsdt.ui.superType.container",
"chars": 49,
"preview": "org.eclipse.wst.jsdt.launching.baseBrowserLibrary"
},
{
"path": ".settings/org.eclipse.wst.jsdt.ui.superType.name",
"chars": 6,
"preview": "Window"
},
{
"path": "WebContent/META-INF/MANIFEST.MF",
"chars": 39,
"preview": "Manifest-Version: 1.0\r\nClass-Path: \r\n\r\n"
},
{
"path": "WebContent/WEB-INF/applicationContext.xml",
"chars": 13848,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<beans xmlns=\"http://www.springframework.org/schema/beans\"\n\txmlns:xsi=\"http://ww"
},
{
"path": "WebContent/WEB-INF/springMVC-servlet.xml",
"chars": 3792,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<beans xmlns=\"http://www.springframework.org/schema/beans\"\n\txmlns:xsi=\"http://www"
},
{
"path": "WebContent/WEB-INF/web.xml",
"chars": 3280,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<web-app xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txmlns=\"http://jav"
},
{
"path": "WebContent/index.html",
"chars": 88,
"preview": "<html>\r\n<head>\r\n<title>Spring Demo</title>\r\n</head>\r\n<body>Spring Demo\r\n</body>\r\n</html>"
},
{
"path": "src/cn/mayongfa/activemq/ActiveMQTransportListener.java",
"chars": 1033,
"preview": "package cn.mayongfa.activemq;\n\nimport java.io.IOException;\n\nimport org.apache.activemq.transport.TransportListener;\nimpo"
},
{
"path": "src/cn/mayongfa/activemq/ConsumerMessageListener.java",
"chars": 705,
"preview": "package cn.mayongfa.activemq;\n\nimport javax.jms.JMSException;\nimport javax.jms.Message;\nimport javax.jms.MessageListener"
},
{
"path": "src/cn/mayongfa/activemq/MessageSender.java",
"chars": 1624,
"preview": "package cn.mayongfa.activemq;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport javax.jms.JMSException;\nimport ja"
},
{
"path": "src/cn/mayongfa/api/controller/UserController.java",
"chars": 6012,
"preview": "package cn.mayongfa.api.controller;\n\nimport java.util.Date;\nimport java.util.HashMap;\nimport java.util.List;\nimport java"
},
{
"path": "src/cn/mayongfa/cache/MemcachedBasis.java",
"chars": 490,
"preview": "package cn.mayongfa.cache;\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.st"
},
{
"path": "src/cn/mayongfa/cache/UserBasisCache.java",
"chars": 1809,
"preview": "package cn.mayongfa.cache;\n\nimport java.util.concurrent.TimeoutException;\n\nimport org.apache.log4j.Logger;\nimport org.sp"
},
{
"path": "src/cn/mayongfa/common/DateUtil.java",
"chars": 4972,
"preview": "package cn.mayongfa.common;\r\n\r\nimport java.text.ParseException;\r\nimport java.text.SimpleDateFormat;\r\nimport java.util.Da"
},
{
"path": "src/cn/mayongfa/common/DynamicDataSource.java",
"chars": 342,
"preview": "package cn.mayongfa.common;\n\nimport org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\n\nimport cn.may"
},
{
"path": "src/cn/mayongfa/common/ExceptionHandler.java",
"chars": 1615,
"preview": "package cn.mayongfa.common;\n\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport javax.s"
},
{
"path": "src/cn/mayongfa/common/IdWorker.java",
"chars": 4039,
"preview": "package cn.mayongfa.common;\r\n\r\nimport org.apache.log4j.Logger;\r\n\r\n/**\r\n * \r\n * 以后,根据数据id,即可计算出该数据,产自哪个数据中心的.\r\n * \r\n * @a"
},
{
"path": "src/cn/mayongfa/common/IdWorkerManage.java",
"chars": 877,
"preview": "package cn.mayongfa.common;\r\n\r\npublic class IdWorkerManage {\r\n\r\n\tprivate static IdWorker IdWorkerInstance = null;\r\n\r\n\tst"
},
{
"path": "src/cn/mayongfa/common/JdbcContextHolder.java",
"chars": 504,
"preview": "package cn.mayongfa.common;\n\npublic class JdbcContextHolder {\n\t\n\tprivate static final ThreadLocal<String> contextHolder "
},
{
"path": "src/cn/mayongfa/common/MD5Util.java",
"chars": 1349,
"preview": "package cn.mayongfa.common;\r\n\r\nimport java.security.MessageDigest;\r\n\r\nimport org.apache.log4j.Logger;\r\n\r\npublic class MD"
},
{
"path": "src/cn/mayongfa/common/StrUtil.java",
"chars": 11057,
"preview": "package cn.mayongfa.common;\r\n\r\nimport java.io.UnsupportedEncodingException;\r\nimport java.math.BigDecimal;\r\nimport java.u"
},
{
"path": "src/cn/mayongfa/controller/AccountController.java",
"chars": 2061,
"preview": "package cn.mayongfa.controller;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport org.springframework.beans.facto"
},
{
"path": "src/cn/mayongfa/dao/UserBasisDao.java",
"chars": 7689,
"preview": "package cn.mayongfa.dao;\r\n\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\nimport java.util.ArrayList;\r\nimpo"
},
{
"path": "src/cn/mayongfa/interceptor/Authority.java",
"chars": 439,
"preview": "package cn.mayongfa.interceptor;\n\nimport java.lang.annotation.Documented;\nimport java.lang.annotation.ElementType;\nimpor"
},
{
"path": "src/cn/mayongfa/interceptor/AuthorityAnnotationInterceptor.java",
"chars": 2311,
"preview": "package cn.mayongfa.interceptor;\n\nimport java.lang.reflect.Method;\nimport java.util.HashMap;\nimport java.util.Map;\n\nimpo"
},
{
"path": "src/cn/mayongfa/interceptor/AuthorityType.java",
"chars": 152,
"preview": "package cn.mayongfa.interceptor;\r\n\r\npublic enum AuthorityType {\r\n\r\n\t// 登录和权限都验证 默认\r\n\tValidate,\r\n\r\n\t// 不验证\r\n\tNoValidate,\r"
},
{
"path": "src/cn/mayongfa/interceptor/DataSource.java",
"chars": 434,
"preview": "package cn.mayongfa.interceptor;\r\n\r\nimport java.lang.annotation.Documented;\r\nimport java.lang.annotation.ElementType;\r\ni"
},
{
"path": "src/cn/mayongfa/interceptor/DataSourceChoose.java",
"chars": 1062,
"preview": "package cn.mayongfa.interceptor;\n\nimport java.lang.reflect.Method;\n\nimport org.aspectj.lang.JoinPoint;\nimport org.aspect"
},
{
"path": "src/cn/mayongfa/interceptor/DataSourceType.java",
"chars": 373,
"preview": "package cn.mayongfa.interceptor;\n\npublic enum DataSourceType {\n\n\t// 主库\n\tMaster(\"master\"),\n\n\t// 从库\n\tSlave(\"slave\"),\n\n\t// "
},
{
"path": "src/cn/mayongfa/interceptor/TestInterceptor.java",
"chars": 1097,
"preview": "package cn.mayongfa.interceptor;\n\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletRes"
},
{
"path": "src/cn/mayongfa/model/UserBasis.java",
"chars": 1285,
"preview": "package cn.mayongfa.model;\r\n\r\nimport java.io.Serializable;\r\n\r\n@SuppressWarnings(\"serial\")\r\npublic class UserBasis implem"
},
{
"path": "src/cn/mayongfa/quartz/GlodQuartz.java",
"chars": 844,
"preview": "package cn.mayongfa.quartz;\n\nimport org.springframework.scheduling.annotation.Scheduled;\nimport org.springframework.ster"
},
{
"path": "src/cn/mayongfa/service/UserBasisService.java",
"chars": 1146,
"preview": "package cn.mayongfa.service;\r\n\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\nimport cn.mayongfa.interceptor.DataSour"
},
{
"path": "src/cn/mayongfa/service/imp/UserBasisServiceImp.java",
"chars": 1451,
"preview": "package cn.mayongfa.service.imp;\n\nimport java.util.List;\nimport java.util.Map;\n\nimport org.springframework.beans.factory"
},
{
"path": "src/global.properties",
"chars": 55,
"preview": "\r\njxb.global.defaultavatar=\r\njxb.global.defaultphoto=\r\n"
},
{
"path": "src/jdbc.properties",
"chars": 833,
"preview": "master.jdbc.driverClassName=com.mysql.jdbc.Driver\nmaster.jdbc.url=jdbc:mysql://127.0.0.1:3306/springdemo?useUnicode=true"
},
{
"path": "src/log4j.properties",
"chars": 1736,
"preview": "# Priorities are: DEBUG, INFO, WARN, ERROR, or FATAL.\r\nlog4j.rootCategory=INFO, CONSOLE,Druid\r\n#log4j.rootCategory=INFO,"
},
{
"path": "src/memcached.properties",
"chars": 334,
"preview": "#\\u8FDE\\u63A5\\u6C60\\u5927\\u5C0F\\u5373\\u5BA2\\u6237\\u7AEF\\u4E2A\\u6570 \nmemcached.connectionPoolSize=10 \nmemcached.failur"
}
]
// ... and 55 more files (download for full content)
About this extraction
This page contains the full source code of the mafly/SpringDemo GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 100 files (86.7 KB), approximately 27.9k tokens, and a symbol index with 148 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.