ITeye博客

#import ~ 青山代码

Aoyi · 共 64 篇文章

[#0x0053] 阻止 form submit 的方法

有两个地方可以可以阻止form submit,一是<form onsubmit="">,而是<form>下的<input type="submit" onclick="">,只要这两个函数有一个是return false;,那么点击这个button并不会submit form。 具体的执行流程是这样的: if (submitInput.onclick() == false) { // 不触发 form.onsubmit(); // form 不提交; } else { // 触发 form.onsubmit(); if (form.onsubmit() == false) { // form…

2011-10-18 21:21 · HTML · 评论(0)

[#0x0051] static属性的注入必须使用非static的setter

有一些util类或是config类会用到static属性,这些util类或是config类也可以通过Spring来初始化,和初始化一个POJO没什么区别,虽然实际应用中不太可能去创建一个util对象或是config对象,一般都是使用static getter而已。 但如果要使用Spring来初始化,那么这些static属性不能用static的setter来注入,否则NotWritablePropertyException。

2011-09-02 14:38 · Spring · 评论(0)

[#0x0050] "Could not resolve placeholder"解决方案

除去properites文件路径错误、拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因。 比如我有一个dao.xml读取dbConnect.properties,还有一个dfs.xml读取dfsManager.properties,然后web.xml统一load这两个xml文件 <context-param> <param-name>contextConfigLocation</param-name> <para…

2011-08-17 20:17 · Spring · 评论(3)

[#0x004E] MySQL 5.5版本下my.ini内[mysqld]项中不能再写default-character-set=utf8

RT。 原来在5.1版本时,为了解决中文乱码问题设置默认字符集为utf8时,在my.ini内的 [mysql] 和 [mysqld] 项中都是写: default-character-set=utf8 到了5.5版本, [mysql] 项内可以这么写, [mysqld] 项内不能再这么写了,而是必须写: character-set-server=utf8 否则在启动MySQL服务时会有1067错误。 目前已知5.1和5.5有这么一个不同之处,且是从5.5的安装版本自动生成的my.ini文件中看出的。配置免安装的5.5版本还需要进一步的实验。

2011-07-11 19:23 · Database · 评论(6)

[#0x004C] Java多线程:synchronized

首先明确一点,同步方法本质上也是一个同步控制块(仅针对于锁定this的情况,如果同步控制块锁定的不是this,那么它是不能直接改写为同步方法的),区别在于同步方法的粒度是整个方法,而同步控制块的粒度可以是方法的一部分。 // 同步方法示例 public class Counter { int count; static int classCount; public synchronized void bump() { System.out.println("bump() starts"); count++; try { Thread.sleep(1000); } catch (Interru…

2010-10-05 19:54 · Java · 评论(0)

[#0x004B] Java多线程:终止线程的方法

虽说Thread类提供了stop()和suspend()方法,但这两种方法过于粗暴,如果线程占用了一些资源(如打开了一个文件,建立了一个数据库连接什么的),直接stop()或是suspend()是会产生问题的。 要终止Thread,最好的方法就是让run()方法正常运行完毕,不过有的run()方法里面直接是一个while (true),这时就要使用一些特殊的手段。 1. 使用中断 基本思想就是在run()方法中的while (true)里检查线程是否中断,如果中断就退出(当然,退出之前可以做一些关闭资源的操作);这么一来在主线程中就可以调用Thread.interrupt()来中断线程,进而…

2010-10-04 21:09 · Java · 评论(1)

[#0x004A] Java多线程:Runnable接口 v.s. Thread类

public class Runner implements Runnable { @Override public void run() { for(int i = 0; i < 100; i++) { System.out.println("Runner runs to --> " + i); } } } public class MultiThreadTest { public static void main(String[] args) { Runner r = new Runner(); //r.run(); // 方法调用,没有启动新线程 Thread t = new Thre…

2010-10-04 18:39 · Java · 评论(0)

[#0x0049] Const Pointer

1. 首先确定一点,int const i;与const int i;是一样的,都是定义一个只读的int i。 2. 所以int const *p;与const int *p;也是一样的,都是定义一个只读的int *p。 但是,不管是int const *p;还是const int *p;,这里有几点需要注意。 #include <stdio.h> int main() { int i1 = 30; int i2 = 40; const int *p = &i1; p = &i2; // no problem i2 = 80; printf("%d\n", *p); // output: 8…

2010-09-26 23:29 · C Programming Language · 评论(0)

[#0x0048] hibernate延迟加载的错误

异常信息:failed to lazily initialize a collection of role: <容器类对象>, no session or session was closed 这个问题一般出现在@OneToMany的情况下,解决的方法: 1. 如果是xml配置,在hbm文件中的对应属性上配置lazy=“false” 2. 如果是用annotation,则配置如下 @OneToMany( targetEntity = CourseAuthorizationItem.class, cascade = { CascadeType.PERSIST, CascadeType.MERG…

2010-08-28 14:45 · Hibernate · 评论(0)

[#0x0047] 使用Spring TestContext测试框架需要注意的一点

例如我们有: @ContextConfiguration(locations = {"classpath:datasource.xml", "classpath:process-engine.xml"}) public class ProcessConfigurationManagerTest extends AbstractJUnit4SpringContextTests { …… } 在写@BeforeClass方法时,datasource.xml和process-engine.xml这两个文件并没有读取,所以不能实例化bean。也就是说这两个文件的读取在@BeforeClass之后。@…

2010-08-11 09:18 · Spring · 评论(0)

[#0x0046] callback释义

最近接触到了HibernateTemplate,用到了HibernateCallback,决定把callback的逻辑关系彻底搞清楚,以前总是不明白这个call到底是谁call的谁,这个back到底是从哪里back到哪里。 要搞清楚英文原文的逻辑,还是wikipedia好使,反正我关键字“回调函数”搜了半天也没搞清楚…… In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to ot…

2010-08-08 15:32 · Bullet Points · 评论(0)

[#0x0045] Spring AOP学习(四):简单XML配置

紧接着(三)中的例子。其实Spring AOP注解的概念理解了后,看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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframew…

2010-08-02 23:03 · Spring · 评论(0)

[#0x0044] Spring AOP学习(三):例子与基本概念

依旧是LogInterceptor的例子。下面是beans.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/a…

2010-08-02 20:45 · Spring · 评论(0)

[#0x0043] jBPM Tips (on updating)

1. deploymentId和definitionId应该是一对一的关系 部署的时候,deploy()返回的就是deploymentId。deploymentId虽然是个String,不过仅包含数字,目前我还不清楚它的生成策略。 每次部署,还会产生一个definitionId。definitionId的生成与process.jpdl.xml文件有关: <?xml version="1.0" encoding="UTF-8"?> <process name="ProcessName" key="ProcessKey" version="1024" xmlns="http://jbpm.org…

2010-07-29 17:37 · jBPM · 评论(0)

[#0x0042] Spring AOP学习(二):动态代理

如果系统中有500个类,每个类都要添加日志功能,此时无论是直接修改源代码、继承还是组合,都是十分巨大的工作量。此时AOP可以帮我们解决这个问题。 现在假设记录日志的功能已经单独提出来了,由LogInterceptor来完成: package com.bjsxt.aop; public class LogInterceptor { public void beforeMethod() { System.out.println("logging..."); } } 有了Spring AOP,我们就可以用配置文件来说明:“在某个类的每一个方法执行之前,都给我调用一次beforeMethod()方法…

2010-07-28 17:10 · Spring · 评论(0)