Skip to content

Instantly share code, notes, and snippets.

@wendal
wendal / PojoForQQ.java
Last active March 15, 2017 12:41
测试nutz json 处理getter/setter的情况
package org.nutz.json.meta;
import org.nutz.json.Json;
import org.nutz.json.JsonField;
public class PojoForQQ {
private int id;
private String code;
@JsonField
@wendal
wendal / jedis_key_expired.java
Created March 14, 2017 02:25
Jedis订阅key过期事件的示例代码
public static void main(String[] args) {
Jedis jedis = new Jedis();
jedis.setex("abc", 15, "hi");
System.out.println("time now = " + System.currentTimeMillis());
jedis.psubscribe(new JedisPubSub() {
@Override
public void onPMessage(String pattern, String channel, String message) {
System.out.println("time now = " + System.currentTimeMillis());
@wendal
wendal / test.java
Created September 10, 2015 03:00
演示如何得到NutDao生成的Sql语句
@Test
public void test_get_sql() throws Throwable {
NutDao dao = new NutDao(ioc.get(javax.sql.DataSource.class));
final List<String> sqls = new ArrayList<String>();
final Method m = NutStatement.class.getDeclaredMethod("toStatement", Object[][].class, String.class);
m.setAccessible(true);
dao.setExecutor(new DaoExecutor() {
public void exec(Connection conn, DaoStatement st) {
String psql = st.toPreparedStatement();
sqls.add(psql);
@wendal
wendal / Daos_tableName.java
Created September 7, 2015 05:38
示例获取一个动态表名
public static String getTableName(Dao dao, Class<?> klass, Object t) {
final Entity<?> en = dao.getEntity(klass);
final String[] name = new String[1];
TableName.run(t, new Runnable() {
public void run() {
name[0] = en.getTableName();
}
});
return name[0];
}
@wendal
wendal / BaseNutTest.java
Last active September 7, 2015 02:46
Nutz测试基类,供参考
package org.nutz.test;
import java.lang.reflect.Field;
import org.junit.After;
import org.junit.Before;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.annotation.Inject;
@wendal
wendal / 0_reuse_code.js
Last active August 31, 2015 19:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@wendal
wendal / BeetlViewMaker.java
Created June 16, 2015 14:11
改造版BeetlViewMaker,把方法的返回值放进req里面
package org.beetl.ext.nutz;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.WebAppResourceLoader;
@wendal
wendal / DaoHelper.java
Last active November 2, 2017 08:13
nutz中实现saveOrUpdate封装(供参考)
@SuppressWarnings("unchecked")
public static <T> T insertOrUpdate(Dao dao, T obj) {
if (obj == null)
return null;
Entity<T> en = (Entity<T>) dao.getEntity(obj.getClass());
if (en.getPkType() == PkType.UNKNOWN)
throw new IllegalArgumentException("no support , without pks");
boolean doInsert = false;
switch (en.getPkType()) {
case ID:
@wendal
wendal / ddns.go
Created January 22, 2015 08:18
golang的dns缓存, 含流量统计
package ddns
import (
"log"
"net"
"sync"
)
var (
dnsLock = &sync.Mutex{}
@wendal
wendal / IotUser.java
Created January 3, 2015 14:15
基于XML配置NutDao的Entity, 未测试代码, 正式代码会出现在nutz主库或nutzmore项目.
package org.nutz.dao.impl.entity.xml;
public class IotUser {
private long id;
private String name;
private int age;
public int getAge() {
return age;
}