<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
beans
PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd"
>
<
beans
>
<
bean
id
=
"dataSource"
class
=
"org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<
property
name
=
"driverClassName"
>
<
value
>
com.mysql.jdbc.Driver
</
value
>
</
property
>
<
property
name
=
"url"
>
<
value
>
jdbc:mysql:///students
</
value
>
</
property
>
<
property
name
=
"username"
>
<
value
>
root
</
value
>
</
property
>
<
property
name
=
"password"
>
<
value
></
value
>
</
property
>
</
bean
>
<
bean
id
=
"jdbcTemplate"
class
=
"org.springframework.jdbc.core.JdbcTemplate"
>
<
property
name
=
"dataSource"
>
<
ref
bean
=
"dataSource"
/>
</
property
>
</
bean
>
<
bean
id
=
"userDAO"
class
=
"cn.zhd.DAO.Imp.UserDAOImp"
>
<
property
name
=
"jt"
>
<
ref
bean
=
"jdbcTemplate"
/>
</
property
>
</
bean
>
<
bean
id
=
"user"
class
=
"cn.zhd.Model.User"
>
<
property
name
=
"dao"
>
<
ref
bean
=
"userDAO"
/>
</
property
>
<
property
name
=
"name"
>
<
value
>
zjd
</
value
>
</
property
>
<
property
name
=
"password"
>
<
value
>
888
</
value
>
</
property
>
</
bean
>
</
beans
>
|
package cn.zhd.Model;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class UserTest {
public static void main(String []args){
// User u=new User("zjd","888");
//
批量插入数据
List<User> u = new ArrayList<User>();
u.add(new User("haha","123"));
u.add(new User("hoho","234"));
u.add(new User("zhansan","345"));
u.add(new User("lisi","456"));
u.add(new User("maqi","577"));
u.add(new User("wo","899"));
u.add(new User("admin","haha"));
u.add(new User("fdsdf","675"));
u.add(new User("werwr","89"));
Resource resource=new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
User user = (User) factory.getBean("user");
// user.insert();
// user.update("update admin set name='zbj' where id=2");
user.insertBatchData(u);
// user.selectWithTemp();
// user.selectById("2");
// user.getInfo("2");
}
}
|