Skip to content

Instantly share code, notes, and snippets.

Avatar

arganzheng arganzheng

View GitHub Profile
View Import an existing repository to Bitbucket
如果你本地工程已经是一个Git Repository(已经执行过[Import an existing, unversioned code project to an empty repository]),那么可以这样把它加入你在Bitbucket创建的远程仓库中:
cd /path/to/my/repo
# Creates a remote named "origin" pointing at your GitHub/Bitbucket repository (设置远程仓库地址)
git remote add origin ssh://git@bitbucket.org/arganzheng/remote-terminator.git
# Sends your commits in the "master" branches to GitHub/Bitbucket
git push -u origin master
当然在你能push之前必须先设置你的账号信息,并且最好使用Password Caching或者SSH key避免每次提交代码都要提示输入密码。
@arganzheng
arganzheng / 开放平台鉴权学习.md
Last active Nov 28, 2017
开放平台点滴积累
View 开放平台鉴权学习.md

鉴权学习

对于一个API请求,开发平台一般需要知道下面几件事情:

  1. 哪个应用发起这个请求(Which application is making the request)
  2. 这个请求是为哪个用户发起的(Which user the request is posting on behalf of)
  3. 用户是否对这个请求进行授权(Whether the user has granted the application authorization to post on the user's behalf)
  4. 请求是否在传输过程中被篡改(Whether the request has been tampered by a third party while in transit)
View lottery_create.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>微生活抽奖模块管理后台</title>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/static/css/datetimepicker.css" rel="stylesheet" media="screen">
</head>
<body>
@arganzheng
arganzheng / ok.jsp
Created Jul 11, 2013
可以使用这个ok.jsp检查应用是否正常启动
View ok.jsp
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.support.XmlWebApplicationContext"%>
<%
XmlWebApplicationContext context = (XmlWebApplicationContext)WebApplicationContextUtils.getWebApplicationContext(application);
try{
if(!context.isActive()){
context.refresh();
}
View MappingJsonpHttpMessageConverter.java
package me.arganzheng.study;
import java.io.IOException;
import java.io.PrintStream;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
View redirect-with-js-after-some-time.md

JS实现一段时间后自动调转页面

setTimeout(function(){
	window.location.href="./modules.xhtml?source=${source}";
	}, 2000
);
View config-log4j-for-ibatis-to-print-sql.md

如何打印ibatis拼凑的动态SQL语句

log4j.logger.java.sql.PreparedStatement=debug
log4j.logger.java.sql.Connection=debug

将打印出Connection和Statement信息:

[DEBUG] 11:48:17 Connection - {conn-100000} Connection
[DEBUG] 11:48:17 Connection - {conn-100000} Preparing Statement:    select api.id   from t_api_metadata_api api,   t_api_metadata_module module   where api.module_id=module.id   and api.source = ?   and api.name = ?       and     api.module_id = ?        and     module.name = ?         
View XmlFileApiMetadataDao.java
package me.arganzheng.study.metadata.dao;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
import javax.xml.bind.JAXBContext;
@arganzheng
arganzheng / ApiDao.java
Last active Dec 19, 2015
如何autowired sqlMapClient到Dao对象中,解决这个问题`java.lang.IllegalArgumentException: Property 'sqlMapClient' is required`。参考文章: 1. http://edwin.baculsoft.com/2010/08/yet-another-simple-swing-spring-and-ibatis-integration-example/ 2. http://stackoverflow.com/questions/3807707/injecting-derived-property-for-repository-bean-without-autowired-in-super-clas
View ApiDao.java
@Repository
public class ApiDao extends SqlMapClientDaoSupport {
// empty constructor
public ApiDao() {
}
// autowired constructor
// i dont know why, but i cant autowired sqlMapClient directly
// it will cause java.lang.IllegalArgumentException: Property 'sqlMapClient' is required
View spring-interceptor.md

Spring interceptor

配置

<!-- Configures Handler Interceptors --> 
<mvc:interceptors>  
    <!-- This bit of XML will intercept all URLs - which is what you want in a web app -->
    <bean class="me.arganzheng.study.api.container.interceptor.AuthorizationInterceptor" />