在spring IOC容器的配置文件applicationContext.xml里,有一些配置细节值得一提。我们将一些问题归结为以下几个专题。

 

专题一:字面值问题

配置的bean节点中的值,我们提出一个概念——字面值。

字面值:可用字符串表示的值.

字面值可以通过 <value> 元素标签或 value 属性进行注入。

基本数据类型及其封装类、String 等类型都可以采取字面值注入的方式

若字面值中包含特殊字符,可以使用 <![CDATA[]]> 把字面值包裹起来。

例如:(本文出自:http://my.oschina.net/happyBKs/blog/478074)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="car_value_id" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg name="price1">
<value>200000</value>
</constructor-arg>
<constructor-arg name="name1">
<value><![CDATA[<BM>]]></value>
</constructor-arg>
</bean>
<!-- 如果字面值包括特殊字符,可以用<![CDATA[ ]]>括起来 --> </beans>

Car定义:

package com.happBKs.spring.iocaop.beans;

public class Car {
String name;
double price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Car() {
super();
}
public Car(String name1, double price1) {
super();
this.name = name1;
this.price = price1;
}
@Override
public String toString() {
return "Car [name=" + name + ", price=" + price + "]";
}
}

测试代码:

@Test
public void test8()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
Car cBean=(Car)ctx.getBean("car_value_id");
//调用对象方法
System.out.println(cBean);
}

结果输出:

Car [name=<BM>, price=200000.0]

在上例中,属性值可以使用value子节点进行配置。

专题二:bean的属性是另一个bean

在bean类的定义中往往存在这样的情况, 另类的某个属性是另一个bean对象。这样的情况,要使得容器能够在自动生成相应对象,应该怎么做的呢。

首先我们定义一个Person类,每个Person有一个Car类型属性。

package com.happBKs.spring.iocaop.beans;

public class Person {

    String username;
Car userCar; public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Car getUserCar() {
return userCar;
}
public void setUserCar(Car userCar) {
this.userCar = userCar;
}
public Person(String username, Car userCar) {
super();
this.username = username;
this.userCar = userCar;
}
public Person() {
super();
}
@Override
public String toString() {
return "Person [username=" + username + ", userCar=" + userCar + "]";
} }

容器配制文件:我们使用property的ref属性来引用属性类型,即建立bean之间的引用关系。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="car_id" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
</bean> <bean id="caruser" class="com.happBKs.spring.iocaop.beans.Person">
<property name="username" value="HappyBKs"></property>
<property name="userCar" ref="car_id"></property>
</bean> </beans>

测试代码:

@Test
public void test9()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
Person pBean=(Person)ctx.getBean("caruser");
//调用对象方法
System.out.println(pBean);
}

运行结果:

Person [username=HappyBKs, userCar=Car [name=BM, price=500000.0]]

组成应用程序的 Bean 经常需要相互协作以完成应用程序的功能. 要使 Bean 能够相互访问, 就必须在 Bean 配置文件中指定对 Bean 的引用

在 Bean 的配置文件中, 可以通过 <ref> 元素或 ref  属性为 Bean 的属性或构造器参数指定对 Bean 的引用.

也就是说,刚才的容器配制还可以写成:

<bean id="caruser" class="com.happBKs.spring.iocaop.beans.Person">
<property name="username" value="HappyBKs"></property>
<property name="userCar">
    <ref bean="car_id"/>
</property>
</bean>

也可以在属性或构造器里包含 Bean 的声明, 这样的 Bean 称为内部 Bean。

如,上面的例子可以写成另一种内部bean的形式。这种内部bean的形式,不用再有id属性,因为它不可能被外部引用。

<bean id="caruserB" class="com.happBKs.spring.iocaop.beans.Person">
<property name="username" value="HappyBKs"></property>
<property name="userCar">
<bean class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="450000" index="1"></constructor-arg>
<constructor-arg value="Volvo" index="0"></constructor-arg>
</bean>
</property>
</bean>

测试代码:

@Test
public void test10()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
Person pBean=(Person)ctx.getBean("caruserB");
//调用对象方法
System.out.println(pBean);
}

输出结果:

Person [username=HappyBKs, userCar=Car [name=Volvo, price=450000.0]]

当 Bean 实例仅仅给一个特定的属性使用时, 可以将其声明为内部 Bean. 内部 Bean 声明直接包含在 <property> 或 <constructor-arg> 元素里, 不需要设置任何 id 或 name 属性。

内部 Bean 不能使用在任何其他地方。

专题三:特殊注入参数:null 值

我们有时需要将bean的某个属性设置为null,这在spring容器的配置文件里面怎么描述呢?

这就要用到一个特殊的标签<null/>

<bean id="caruserB" class="com.happBKs.spring.iocaop.beans.Person">
<property name="username" value="HappyBKs"></property>
<property name="userCar">
<bean class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="450000" index="1"></constructor-arg>
<constructor-arg index="0"><null/></constructor-arg>
</bean>
</property>
</bean>

运行刚才的test10方法,输出结果:

Person [username=HappyBKs, userCar=Car [name=null, price=450000.0]]

专题四:特殊注入参数:级联属性

另一种bean中比较特殊的赋值是级联属性。什么叫级联属性呢?其实你一看就明白了,就是对象的属性子对象的属性。

配置文件中配置bean的属性时,property标签不仅能直接配置该bean对应的类自身的属性,而且还可以直接配置该类的属性对象向的属性,即级联属性。

<bean id="caruserC" class="com.happBKs.spring.iocaop.beans.Person">
<property name="username" value="HappyBKs"/>
<property name="userCar" ref="car_id"/>
<property name="userCar.price" value="350000"/>
</bean>

测试代码:

@Test
public void test11()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
Person pBean=(Person)ctx.getBean("caruserC");
//调用对象方法
System.out.println(pBean);
}

输出结果:

Person [username=HappyBKs, userCar=Car [name=BM, price=350000.0]]

当然,如果配置的bean中前面用构造器注入,也可以同时使用级联属性赋值。

<bean id="caruserC" class="com.happBKs.spring.iocaop.beans.Person">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
<property name="userCar.price" value="350000"/>
</bean>

但是有一个十分需要注意的问题:这里的级联属性被赋值的前提是级联属性所属的对象属性已经被属性注入或构造器注入赋值,否则会报异常。这一点与struts2不同,struts2这种情况会为级联属性所属对象自动生成实例,而spring不行。

专题五:集合属性

在类的属性中往往又一些属性是集合性质的类型,如List、Set、Map等,或者是一个数组类型。

在Spring中,这样的类在容器中应该如何配置呢?

在 Spring中可以通过一组内置的 xml 标签(例如: <list>, <set> 或 <map>) 来配置集合属性.

配置 java.util.List 类型的属性, 需要指定 <list>  标签, 在标签里包含一些元素. 这些标签可以通过 <value> 指定简单的常量值, 通过 <ref> 指定对其他 Bean 的引用. 通过<bean> 指定内置 Bean 定义. 通过 <null/> 指定空元素. 甚至可以内嵌其他集合。

数组的定义和 List 一样, 都使用 <list>。

配置 java.util.Set 需要使用 <set> 标签, 定义元素的方法与 List 一样。

List集合属性

那我们现在来看一个List的例子。

我们定义一个RichPerson类:它有一个userCars属性是List类型。

package com.happBKs.spring.iocaop.beans;

import java.util.List;

public class RichPerson {

    String username;
List<Car> userCars;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public List<Car> getUserCars() {
return userCars;
}
public void setUserCars(List<Car> userCars) {
this.userCars = userCars;
}
public RichPerson(String username, List<Car> userCars) {
super();
this.username = username;
this.userCars = userCars;
}
public RichPerson() {
super();
}
@Override
public String toString() {
return "RichPerson [username=" + username + ", userCars=" + userCars
+ "]";
}
}

在applicationContext.xml中,配置如下信息:

我们将对应userCars的property标签里加入<list>标签

在<list>标签里我们逐个加入bean。

加入方法有多种,这里使用了两种:

一种是ref,引用外部的bean。如前三个单元的bean。

另一种是自己定义内部bean,与前面介绍的内部bean类似。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="privateCar1" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="800000"></constructor-arg>
</bean>
<bean id="privateCar2" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Volvo"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
</bean> <bean id="richPerson1" class="com.happBKs.spring.iocaop.beans.RichPerson">
<property name="username" value="HappyBKs" />
<property name="userCars">
<list>
<ref bean="privateCar1" />
<ref bean="privateCar1" />
<ref bean="privateCar2" />
<bean id="privateCarSecret" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Tank"></constructor-arg>
<constructor-arg value="100000000000"></constructor-arg>
</bean>
</list>
</property>
</bean>
</beans>

测试方法:

@Test
public void test12()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
RichPerson pBean=(RichPerson)ctx.getBean("richPerson1");
//调用对象方法
System.out.println(pBean);
}

输出结果:

RichPerson [username=HappyBKs, userCars=[Car [name=BM, price=800000.0], Car [name=BM, price=800000.0], Car [name=Volvo, price=500000.0], Car [name=Tank, price=1.0E11]]]

Map的集合属性

我们再看一个Map的集合属性的例子。

package com.happBKs.spring.iocaop.beans;

import java.util.Map;

public class RichMapPerson {

    String username;
Map<String,Car> userCars;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Map<String, Car> getUserCars() {
return userCars;
}
public void setUserCars(Map<String, Car> userCars) {
this.userCars = userCars;
}
public RichMapPerson(String username, Map<String, Car> userCars) {
super();
this.username = username;
this.userCars = userCars;
}
public RichMapPerson() {
super();
}
@Override
public String toString() {
return "RichMapPerson [username=" + username + ", userCars=" + userCars
+ "]";
} }

配置容器:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="privateCar1" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="800000"></constructor-arg>
</bean>
<bean id="privateCar2" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Volvo"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
</bean> <bean id="richMapPerson1" class="com.happBKs.spring.iocaop.beans.RichMapPerson">
<property name="username" value="HappyBKs" />
<property name="userCars">
<map>
<entry key="WorkCar" value-ref="privateCar1"></entry>
<entry key="ShoppingCar" value-ref="privateCar2"></entry>
</map>
</property>
</bean>
</beans>

不过很可惜的是entry貌似不支持内部bean的定义,即一下情况是报错的,提示不支持此处以bean开头。

<bean id="richMapPerson1" class="com.happBKs.spring.iocaop.beans.RichMapPerson">
<property name="username" value="HappyBKs" />
<property name="userCars">
<map>
<entry key="WorkCar" value-ref="privateCar1"></entry>
<entry key="ShoppingCar" value-ref="privateCar2"></entry>
<entry key="OXOXCar">
<value type="com.happBKs.spring.iocaop.beans.Car"> <property name="name" value="taxi"></property>
<property name="price" value="50000"></property>
</value>
</entry>
</map>
</property>
</bean>

回到刚才,测试方法:

@Test
public void test13()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
RichMapPerson pBean=(RichMapPerson)ctx.getBean("richMapPerson1");
//调用对象方法
System.out.println(pBean);
}

运行结果:

RichMapPerson [username=HappyBKs, userCars={WorkCar=Car [name=BM, price=800000.0], ShoppingCar=Car [name=Volvo, price=500000.0]}]

Properties类的属性

Properties类型其实可以算Map类型的子类型:它是HashTable类型的子类噢!

现在我们来定义一个bean,用来记录数据库配置信息:

package com.happBKs.spring.iocaop.beans;

import java.util.Properties;

public class DataSourceBean {

    Properties propertiesInfo;

    public Properties getPropertiesInfo() {
return propertiesInfo;
} public void setPropertiesInfo(Properties propertiesInfo) {
this.propertiesInfo = propertiesInfo;
} public DataSourceBean(Properties propertiesInfo) {
super();
this.propertiesInfo = propertiesInfo;
} public DataSourceBean() {
super();
} @Override
public String toString() {
return "DataSourceBean [propertiesInfo=" + propertiesInfo + "]";
} }

spring IOC容器配置:

<bean id="DataSourceId" class="com.happBKs.spring.iocaop.beans.DataSourceBean">
<property name="propertiesInfo">
<props>
<prop key="user">root</prop>
<prop key="password"></prop>
<prop key="jdbcUrl">jdbc:mysql:///test</prop>
<prop key="driverClass">com.mysql.jdbc.Driver</prop>
</props>
</property>
</bean>

测试方法:

@Test
public void test14()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
DataSourceBean dBean=(DataSourceBean)ctx.getBean("DataSourceId");
//调用对象方法
System.out.println(dBean);
}

输出结果:

DataSourceBean [propertiesInfo={driverClass=com.mysql.jdbc.Driver, user=root, password=, jdbcUrl=jdbc:mysql:///test}]

集合类型可以外置(使用 utility scheme 定义集合)

前面提到的这些集合属性在spring ioc容器配置时,都是可以作为外部单元存在的,就像bean存在外部bean和内部bean一样。

使用基本的集合标签定义集合时, 不能将集合作为独立的 Bean 定义, 导致其他 Bean 无法引用该集合, 所以无法在不同 Bean 之间共享集合.

可以使用 util schema 里的集合标签定义独立的集合 Bean. 需要注意的是, 必须在 <beans> 根元素里添加 util schema 定义。

我们以List为例,看下面例子:

首先我们需要给applicationContext.xml加入一个命名空间:

可以用STS、eclipse的编辑工具选择下面的NameSpace编辑视图,直接勾选util命名空间。

配置文件Source如下:

<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd"> <bean id="privateCar1" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="800000"></constructor-arg>
</bean>
<bean id="privateCar2" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Volvo"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
</bean> <util:list id="carsList">
<ref bean="privateCar1" />
<ref bean="privateCar2" />
<bean class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Audi"></constructor-arg>
<constructor-arg value="700000"></constructor-arg>
</bean>
</util:list> <bean id="richPerson2" class="com.happBKs.spring.iocaop.beans.RichPerson">
<property name="username" value="happyBKs"/>
<property name="userCars" ref="carsList"></property>
</bean> </beans>

除了util:list标签,spring-util-4.1命名空间中还有其他集合标签:

输出结果:

RichPerson [username=happyBKs, userCars=[Car [name=BM, price=800000.0], Car [name=Volvo, price=500000.0], Car [name=Audi, price=700000.0]]]

专题六:方便的p命名空间

为了简化 XML 文件的配置,越来越多的 XML 文件采用属性而非子元素配置信息。

Spring 从 2.5 版本开始引入了一个新的 p 命名空间,可以通过 <bean> 元素属性的方式配置 Bean 的属性。

使用 p 命名空间后,基于 XML 的配置方式将进一步简化

首先,我们需要按照之前的方法导入命名空间。

之后,我们在最后加入一个bean,id为richPerson3,你发现依赖于p命名空间,现在这个bean只有一行了,十分简洁。

<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd"> <bean id="privateCar1" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="BM"></constructor-arg>
<constructor-arg value="800000"></constructor-arg>
</bean>
<bean id="privateCar2" class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Volvo"></constructor-arg>
<constructor-arg value="500000"></constructor-arg>
</bean> <util:list id="carsList">
<ref bean="privateCar1" />
<ref bean="privateCar2" />
<bean class="com.happBKs.spring.iocaop.beans.Car">
<constructor-arg value="Audi"></constructor-arg>
<constructor-arg value="700000"></constructor-arg>
</bean>
</util:list> <bean id="richPerson3" class="com.happBKs.spring.iocaop.beans.RichPerson" p:username="happyBKs" p:userCars-ref="carsList"/> </beans>

测试方法:

@Test
public void test16()
{
//创建spring IOC容器对象。ClassPathXmlApplicationContext表示配置文件在类路径下,它是接口ApplicationContext的一个实现类。
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
//从IOC容器中获取Bean实例
RichPerson pBean=(RichPerson)ctx.getBean("richPerson3");
//调用对象方法
System.out.println(pBean);
}

运行结果:

RichPerson [username=happyBKs, userCars=[Car [name=BM, price=800000.0], Car [name=Volvo, price=500000.0], Car [name=Audi, price=700000.0]]]

Spring容器的属性配置详解的六个专题的更多相关文章

  1. Spring学习 6- Spring MVC (Spring MVC原理及配置详解)

    百度的面试官问:Web容器,Servlet容器,SpringMVC容器的区别: 我还写了个文章,说明web容器与servlet容器的联系,参考:servlet单实例多线程模式 这个文章有web容器与s ...

  2. Spring 入门 web.xml配置详解

    Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...

  3. spring sessionFactory 属性配置详解,applicationContext中各种属性详解

    1.Bean的id为sessionFactory,对应的类为AnnotationSessionFactory,即采用注解的形式实现hibernate. 2.hibernateProperties,配置 ...

  4. 电商网站开发记录(三) Spring的引入,以及配置详解

    1.web.xml配置注解<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=& ...

  5. spring中bean的配置详解--定义parent

    在工作中碰到了好多的配置文件,具体来说是spring 中bean配置的parent的配置,搞的我一头雾水,仔细看一下spring中有关bean的配置,剖析一下,具体什么含义! 一.Spring IoC ...

  6. 《Java Spring框架》SpringXML配置详解

    Spring框架作为Bean的管理容器,其最经典最基础的Bean配置方式就是纯XML配置,这样做使得结构清晰明了,适合大型项目使用.Spring的XML配置虽然很繁琐,而且存在简洁的注解方式,但读懂X ...

  7. spring再学习之配置详解

    applicationContext.xml文件配置: bean元素: <?xml version="1.0" encoding="UTF-8"?> ...

  8. spring security 3.2 配置详解(结合数据库)

    没事就来了解下spring security.网上找了很多资料.有过时的,也有不是很全面的.各种问题也算是让我碰了个遍.这样吧.我先把整个流程写下来,之后在各个易混点分析吧. 1.建立几个必要的页面. ...

  9. Spring声明式事务配置详解

    Spring支持编程式事务管理和声明式的事务管理. 编程式事务管理 将事务管理代码嵌到业务方法中来控制事务的提交和回滚 缺点:必须在每个事务操作业务逻辑中包含额外的事务管理代码 声明式事务管理 一般情 ...

随机推荐

  1. luogu P3375 【模板】KMP字符串匹配

    题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next.如果你不知道这是什么意思也不要问,去百度搜[ ...

  2. AC自动机及KMP练习

    好久都没敲过KMP和AC自动机了.以前只会敲个kuangbin牌板子套题.现在重新写了自己的板子加深了印象.并且刷了一些题来增加自己的理解. KMP网上教程很多,但我的建议还是先看AC自动机(Trie ...

  3. 【动态规划技巧题】POJ2229-Sumsets

    [题目大意] 把一个数n分成2的指数幂相加的形式,问有几种情况. [思路] 如果当前i为奇数,则必定有至少一个1,可以看作i-1的情形再加上一个1.即f[i]=f[i-1]. 如果当前i为偶数,假设没 ...

  4. 使用CURL抓取淘宝页面

    /** * 根据地址抓取淘宝页面html代码 * @param type $url 地址 * @return boolean */ public function getTaoBaoHtml($url ...

  5. Inno Setup入门(二十二)——Inno Setup类参考(8)

    http://379910987.blog.163.com/blog/static/33523797201121331832201/ 列表框 列表框(ListBox)是Windows应用程序中重要的输 ...

  6. (转)探索C++的秘密之详解extern "C",这就是为什么很多.lib被我们正确调用确总是无法解析的。

    (转载,绝对的有用) lib被我们正确调用确总是无法解析.这是C++编译和C编译的区别 时常在cpp的代码之中看到这样的代码: #ifdef __cplusplus extern "C&qu ...

  7. Linux设备文件简介

    转:http://www.360doc.com/content/11/0418/00/5087210_110410837.shtml 版权声明 本 文作者是一位自由软件爱好者,所以本文虽然不是软件,但 ...

  8. 【FTP】使用org.apache.commons.net.ftp.FTPClient 实现FTP的上传下载

    在此之前,在项目中加上FTP的架包 第一步:配置FTP服务器的相关配置 FtpConfig.java  实体类(配置类) package com.sxd.ftp; public class FtpCo ...

  9. php判断手机客户端

    <?php // check if wap function check_wap(){ if(stristr($_SERVER['HTTP_VIA'],"wap")){// ...

  10. mybatis批量操作-xml方式

    在实际项目中,我们一般都会用到批量insert.delete.update等操作,由于使用频率还是蛮高的,这里就做个简单的记录,供以后学习和参考. 批量insert 在数据库中,批量插入可以是多条in ...