Skip to content

Instantly share code, notes, and snippets.

View yanhua365's full-sized avatar

yanhua365 yanhua365

View GitHub Profile
@yanhua365
yanhua365 / applicationContext-security-sso.xml
Created May 16, 2014 06:47
Spring Security 集成CAS SSO单点登录功能。
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd" default-lazy-init="false">
@yanhua365
yanhua365 / tomcat-jvm-param.bat
Created May 9, 2014 09:34
启动tomcat时追加的内存参数
-server -XX:PermSize=64M -XX:MaxPermSize=128m
@yanhua365
yanhua365 / PropertiesAccessor.java
Last active August 29, 2015 14:01
访问Spring中placeholder里的属性值(也可以是任何合法的SpringEL表达式)的方法。
package cn.boxiao.bxn.common.boot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@yanhua365
yanhua365 / data.sql
Created April 30, 2014 07:39
处理sql文本,用最后一个数字排序生成sql的groovy脚本。
'4','绘画',NULL,'7','4');
'3','音乐',NULL,'7','3');
'9','其他',NULL,'7','9');
'1','唱歌',NULL,'7','1');
'8','书法',NULL,'7','8');
'5','篮球',NULL,'7','5');
'6','排球',NULL,'7','6');
'2','电脑',NULL,'7','2');
'7','摄影',NULL,'7','7');
'1','一般',NULL,'8','1');
@yanhua365
yanhua365 / spring-simple-datasource.xml
Created April 27, 2014 07:14
Spring中配置简单的JDBC连接
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/test_bxn?useUnicode=true&amp;characterEncoding=UTF-8"/>
</bean>
@yanhua365
yanhua365 / build.gradle
Created April 24, 2014 06:52
使用DbUnit来导出/导入数据的gradle脚本
import groovy.sql.Sql
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.operation.DatabaseOperation;
buildscript {
@yanhua365
yanhua365 / OrgAndUserSelectionController.java
Last active September 19, 2016 13:06
使用Mockito测试Spring MVC 的Controller
package sample.uic.web.controller;
import sample.uic.model.Organization;
import sample.uic.model.OrganizationUser;
import sample.uic.model.User;
import sample.uic.service.OrganizationService;
import sample.uic.service.UserService;
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
@yanhua365
yanhua365 / SpringMvcInitbinder.java
Created April 7, 2014 08:58
在Spring MVC的Controller里注册日期参数的转换器
@InitBinder
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) {
SimpleDateFormat dateFormat =
new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null,
new CustomDateEditor(dateFormat, true));
}
@yanhua365
yanhua365 / RetryCatchCall.java
Created April 2, 2014 09:36
实现出错后多次重新执行的java代码,可以为代码加入容错机制(比如远程调用时就很实用)。
int count = 0;
int maxTries = 3;
while(true) {
try {
// Some Code
// break out of loop, on success
} catch (SomeException e) {
// handle exception
if (++count == maxTries) throw e;
}
<mvc:annotation-driven conversion-service="conversionService" ignoreDefaultModelOnRedirect="true">
<mvc:argument-resolvers>
<bean class="org.springframework.data.web.PageableArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
<bean class="org.springframework.data.repository.support.DomainClassConverter">
<constructor-arg ref="conversionService"/>
</bean>