杂记

  1. java实现字符串的字符集转换
new String(new String("张三".getBytes("utf-8"),"ISO-8859-1").getBytes("ISO-8859-1"),"utf-8")
CSS hack
#test{      
   width:300px;      
   height:300px;      
             
   background-color:blue;      /*firefox*/  
   background-color:red\9;      /*all ie*/  
   background-color:yellow\0;    /*ie8*/  
   +background-color:pink;        /*ie7*/  
   _background-color:orange;       /*ie6*/    
}
:root #test { background-color:purple\9; }  /*ie9*/  
@media all and (min-width:0px){ #test {background-color:black\0;} }  /*opera*/  
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;}}/*chrome and safari*/
@-moz-document url-prefix() {
	#test{
		height: 800px;
	}
}/*ff hack*/
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
	#test{
		height: 815px;
	}
}/*ie10及以上*/
Spring JavaConfig用法

a、在beans文件头中配置

xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=" http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd"

b、在beans文件中申明导入properties文件

<util:properties id="jdbcProperties" location="classpath:applicationl.properties"/>

c、编写applicationl.properties文件,并放入对应的目录中

url=test.jdbc
username=test
password=123456

注意:键值对不能写成中间包含"."的格式(jdbc.url=testurl)

d、在class中使用

package org.example.config;

@Configuration
public class AppConfig {
    private @Value("#{jdbcProperties.url}") String jdbcUrl;
    private @Value("#{jdbcProperties.username}") String username;
    private @Value("#{jdbcProperties.password}") String password;
    
    @Bean
    public FooService fooService() {
        return new FooServiceImpl(fooRepository());
    }
    @Bean
    public FooRepository fooRepository() {
        return new HibernateFooRepository(sessionFactory());
    }
    
    @Bean
    public SessionFactory sessionFactory() {
        // wire up a session factory
        AnnotationSessionFactoryBean asFactoryBean =new AnnotationSessionFactoryBean();
        asFactoryBean.setDataSource(dataSource());
        // additional config
        return asFactoryBean.getObject();
    }
    
    @Bean
    public DataSource dataSource() {
        return new DriverManagerDataSource(jdbcUrl, username, password);
    }
}
关于Object的clone()方法

先看代码

Object o = new Object();
Test t = new Test();
o.clone();//不能通过编译,无此方法
t.clone();//能正常调用

在这段代码中,o对象的clone()方法调用不能通过编译,因为在Object中的clone()方法签名是这样的

    protected native Object clone() throws CloneNotSupportedException;

此方法被protected修饰,被protected修饰的方法类内部,本包和子类调用,而不能被外包调用,o.clone()是在Object类外包调用,所以不能编译成功。t.clone()能调用成功是因为t是Object的子类。

各修饰符的作用如下图:

170715_OChG_1457082.png

java反射


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;


public class Test {

	public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Test test = new Test();
		Method method = test.getClass().getDeclaredMethod("method", new Class<?>[] {String.class,List.class});
		String name = (String) method.invoke(test, new Object[] {"xiubu",new ArrayList<String>()});
		System.out.println(name);
	}

	public String method(String name , List<String> a){
		System.out.println("反射方法:两个参数");
		method(name,0, a);
		return name;
	}

	public void method(String name, int num, List<String> a) {
		System.out.println("反射方法:三个参数");
		System.out.println("name:"+name+" num:"+num);
	}
}


转载于:https://my.oschina.net/u/1457082/blog/499421

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值