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的子类。
各修饰符的作用如下图:
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);
}
}