Skip to content

Instantly share code, notes, and snippets.

View arganzheng's full-sized avatar

arganzheng arganzheng

View GitHub Profile
@arganzheng
arganzheng / Import an existing repository to Bitbucket
Last active December 19, 2015 03:59
Git常用命令备忘录
如果你本地工程已经是一个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://[email protected]/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 November 28, 2017 16:07
开放平台点滴积累

鉴权学习

对于一个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)
<%@ 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 July 11, 2013 08:30
可以使用这个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();
}
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;

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

setTimeout(function(){
	window.location.href="./modules.xhtml?source=${source}";
	}, 2000
);

如何打印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 = ?

@arganzheng
arganzheng / XmlFileApiMetadataDao.java
Last active December 19, 2015 23:59
JAXB序列化
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 December 19, 2015 23:59
如何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
@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

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" />