(四)Spring 对DAO 的支持
第一节:Spring 对JDBC 的支持
1,配置数据源dbcp;
2,使用JdbcTemplate;
3,JdbcDaoSupport 的使用;
4,NamedParameterJdbcTemplate 的使用;支持命名参数变量;
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
1,使用JdbcTemplate;
T.java:
package com.wishwzp.test; import java.util.List; import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class T { private ApplicationContext ac; @Before
public void setUp() throws Exception {
ac=new ClassPathXmlApplicationContext("beans.xml");
} //添加
@Test
public void addStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int addNums=studentService.addStudent(new Student("王五", 1));
if(addNums==1){
System.out.println("添加成功");
}
} //更新
@Test
public void updateStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int updateNums=studentService.updateStudent(new Student(8,"王五2", 2));
if(updateNums==1){
System.out.println("更新成功");
}
} //删除
@Test
public void deleteStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int deleteNums=studentService.deleteStudent(8);
if(deleteNums==1){
System.out.println("删除成功");
}
} //查找
@Test
public void findStudents() {
StudentService studentService=(StudentService)ac.getBean("studentService");
List<Student> studentList=studentService.findStudents();
for(Student student:studentList){
System.out.println(student);
}
} }
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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <context:property-placeholder location="jdbc.properties"/> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> <bean id="studentDao" class="com.wishwzp.dao.impl.StudentDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean> <bean id="studentService" class="com.wishwzp.service.impl.StudentServiceImpl">
<property name="studentDao" ref="studentDao"></property>
</bean> </beans>
jdbc.properties:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db_spring?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
StudentServiceImpl.java:
package com.wishwzp.service.impl; import java.util.List; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class StudentServiceImpl implements StudentService{ private StudentDao studentDao; public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
} @Override
public int addStudent(Student student) {
return studentDao.addStudent(student);
} @Override
public int updateStudent(Student student) {
return studentDao.updateStudent(student);
} @Override
public int deleteStudent(int id) {
return studentDao.deleteStudent(id);
} @Override
public List<Student> findStudents() {
return studentDao.findStudents();
} }
StudentService.java:
package com.wishwzp.service; import java.util.List; import com.wishwzp.model.Student; public interface StudentService { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
StudentDaoImpl.java:
package com.wishwzp.dao.impl; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student; public class StudentDaoImpl implements StudentDao{ private JdbcTemplate jdbcTemplate; public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
} @Override
public int addStudent(Student student) {
String sql="insert into t_student values(null,?,?)";
Object []params=new Object[]{student.getName() , student.getAge()};
int addjdbcTemplate = jdbcTemplate.update(sql,params);
return addjdbcTemplate;
} @Override
public int updateStudent(Student student) {
String sql="update t_student set name=?,age=? where id=?";
Object []params=new Object[]{student.getName() , student.getAge() , student.getId()};
int updatejdbcTemplate = jdbcTemplate.update(sql,params);
return updatejdbcTemplate;
} @Override
public int deleteStudent(int id) {
String sql="delete from t_student where id=?";
Object []params=new Object[]{ id };
int deletejdbcTemplate = jdbcTemplate.update(sql,params);
return deletejdbcTemplate;
} @Override
public List<Student> findStudents() {
String sql="select * from t_student";
final List<Student> studentList=new ArrayList<Student>();
jdbcTemplate.query(sql, new RowCallbackHandler(){ @Override
public void processRow(ResultSet rs) throws SQLException {
Student student=new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
studentList.add(student);
}
});
return studentList;
} }
StudentDao.java:
package com.wishwzp.dao; import java.util.List; import com.wishwzp.model.Student; public interface StudentDao { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
Student.java:
package com.wishwzp.model; public class Student { private int id;
private String name;
private int age; public Student() {
super();
// TODO Auto-generated constructor stub
} public Student(String name, int age) {
super();
this.name = name;
this.age = age;
} public Student(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
} public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
} }
运行结果就是每一个对数据库的CRUD
3,JdbcDaoSupport 的使用;
T.java:
package com.wishwzp.test; import java.util.List; import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class T { private ApplicationContext ac; @Before
public void setUp() throws Exception {
ac=new ClassPathXmlApplicationContext("beans.xml");
} @Test
public void addStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int addNums=studentService.addStudent(new Student("王五", 1));
if(addNums==1){
System.out.println("添加成功");
}
} @Test
public void updateStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int updateNums=studentService.updateStudent(new Student(4,"王五2", 2));
if(updateNums==1){
System.out.println("更新成功");
}
} @Test
public void deleteStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int deleteNums=studentService.deleteStudent(10);
if(deleteNums==1){
System.out.println("删除成功");
}
} @Test
public void findStudents() {
StudentService studentService=(StudentService)ac.getBean("studentService");
List<Student> studentList=studentService.findStudents();
for(Student student:studentList){
System.out.println(student);
}
} }
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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <context:property-placeholder location="jdbc.properties"/> <bean id="studentDao" class="com.wishwzp.dao.impl.StudentDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean> <bean id="studentService" class="com.wishwzp.service.impl.StudentServiceImpl">
<property name="studentDao" ref="studentDao"></property>
</bean> </beans>
jdbc.properties:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db_spring?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
StudentServiceImpl.java:
package com.wishwzp.service.impl; import java.util.List; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class StudentServiceImpl implements StudentService{ private StudentDao studentDao; public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
} @Override
public int addStudent(Student student) {
return studentDao.addStudent(student);
} @Override
public int updateStudent(Student student) {
return studentDao.updateStudent(student);
} @Override
public int deleteStudent(int id) {
return studentDao.deleteStudent(id);
} @Override
public List<Student> findStudents() {
return studentDao.findStudents();
} }
StudentService.java:
package com.wishwzp.service; import java.util.List; import com.wishwzp.model.Student; public interface StudentService { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
StudentDaoImpl.java:
package com.wishwzp.dao.impl; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.support.JdbcDaoSupport; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student; public class StudentDaoImpl extends JdbcDaoSupport implements StudentDao{ @Override
public int addStudent(Student student) {
String sql="insert into t_student values(null,?,?)";
Object []params=new Object[]{student.getName(),student.getAge()};
int addgetJdbcTemplate = getJdbcTemplate().update(sql,params);
return addgetJdbcTemplate;
//return this.getJdbcTemplate().update(sql,params);
} @Override
public int updateStudent(Student student) {
String sql="update t_student set name=?,age=? where id=?";
Object []params=new Object[]{student.getName() , student.getAge() , student.getId()};
int updategetJdbcTemplate = getJdbcTemplate().update(sql,params);
return updategetJdbcTemplate;
//return this.getJdbcTemplate().update(sql,params);
} @Override
public int deleteStudent(int id) {
String sql="delete from t_student where id=?";
Object []params=new Object[]{id};
int deletegetJdbcTemplate = getJdbcTemplate().update(sql,params);
return deletegetJdbcTemplate;
//return this.getJdbcTemplate().update(sql,params);
} @Override
public List<Student> findStudents() {
String sql="select * from t_student";
final List<Student> studentList=new ArrayList<Student>();
this.getJdbcTemplate().query(sql, new RowCallbackHandler(){ @Override
public void processRow(ResultSet rs) throws SQLException {
Student student=new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
studentList.add(student);
} });
return studentList;
} }
StudentDao.java:
package com.wishwzp.dao; import java.util.List; import com.wishwzp.model.Student; public interface StudentDao { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
Student.java:
package com.wishwzp.model; public class Student { private int id;
private String name;
private int age; public Student() {
super();
// TODO Auto-generated constructor stub
} public Student(String name, int age) {
super();
this.name = name;
this.age = age;
} public Student(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
} public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
} }
运行结果就是每一个对数据库的CRUD
4,NamedParameterJdbcTemplate 的使用;支持命名参数变量;
T.java:
package com.wishwzp.test; import java.util.List; import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class T { private ApplicationContext ac; @Before
public void setUp() throws Exception {
ac=new ClassPathXmlApplicationContext("beans.xml");
} @Test
public void addStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int addNums=studentService.addStudent(new Student("王五", 1));
if(addNums==1){
System.out.println("添加成功");
}
} @Test
public void updateStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int updateNums=studentService.updateStudent(new Student(11,"王五2", 2));
if(updateNums==1){
System.out.println("更新成功");
}
} @Test
public void deleteStudent() {
StudentService studentService=(StudentService)ac.getBean("studentService");
int deleteNums=studentService.deleteStudent(11);
if(deleteNums==1){
System.out.println("删除成功");
}
} @Test
public void findStudents() {
StudentService studentService=(StudentService)ac.getBean("studentService");
List<Student> studentList=studentService.findStudents();
for(Student student:studentList){
System.out.println(student);
}
} }
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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <context:property-placeholder location="jdbc.properties"/> <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource"></constructor-arg>
</bean> <bean id="studentDao" class="com.wishwzp.dao.impl.StudentDaoImpl">
<property name="namedParameterJdbcTemplate" ref="namedParameterJdbcTemplate"></property>
</bean> <bean id="studentService" class="com.wishwzp.service.impl.StudentServiceImpl">
<property name="studentDao" ref="studentDao"></property>
</bean> </beans>
jdbc.properties:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db_spring?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
StudentServiceImpl.java:
package com.wishwzp.service.impl; import java.util.List; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student;
import com.wishwzp.service.StudentService; public class StudentServiceImpl implements StudentService{ private StudentDao studentDao; public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;
} @Override
public int addStudent(Student student) {
return studentDao.addStudent(student);
} @Override
public int updateStudent(Student student) {
return studentDao.updateStudent(student);
} @Override
public int deleteStudent(int id) {
return studentDao.deleteStudent(id);
} @Override
public List<Student> findStudents() {
return studentDao.findStudents();
} }
StudentService.java:
package com.wishwzp.service; import java.util.List; import com.wishwzp.model.Student; public interface StudentService { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
StudentDaoImpl.java:
package com.wishwzp.dao.impl; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import com.wishwzp.dao.StudentDao;
import com.wishwzp.model.Student; public class StudentDaoImpl implements StudentDao{ private NamedParameterJdbcTemplate namedParameterJdbcTemplate; public void setNamedParameterJdbcTemplate(
NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
} @Override
public int addStudent(Student student) {
String sql="insert into t_student values(null,:name,:age)";
MapSqlParameterSource sps=new MapSqlParameterSource();
sps.addValue("name", student.getName());
sps.addValue("age", student.getAge());
return namedParameterJdbcTemplate.update(sql,sps);
} @Override
public int updateStudent(Student student) {
String sql="update t_student set name=:name,age=:age where id=:id";
MapSqlParameterSource sps=new MapSqlParameterSource();
sps.addValue("name", student.getName());
sps.addValue("age", student.getAge());
sps.addValue("id", student.getId());
return namedParameterJdbcTemplate.update(sql,sps);
} @Override
public int deleteStudent(int id) {
String sql="delete from t_student where id=:id";
MapSqlParameterSource sps=new MapSqlParameterSource();
sps.addValue("id", id);
return namedParameterJdbcTemplate.update(sql,sps);
} @Override
public List<Student> findStudents() {
String sql="select * from t_student";
final List<Student> studentList=new ArrayList<Student>();
namedParameterJdbcTemplate.query(sql, new RowCallbackHandler(){ @Override
public void processRow(ResultSet rs) throws SQLException {
Student student=new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
studentList.add(student);
} });
return studentList;
} }
StudentDao.java:
package com.wishwzp.dao; import java.util.List; import com.wishwzp.model.Student; public interface StudentDao { public int addStudent(Student student); public int updateStudent(Student student); public int deleteStudent(int id); public List<Student> findStudents();
}
Student.java:
package com.wishwzp.model; public class Student { private int id;
private String name;
private int age; public Student() {
super();
// TODO Auto-generated constructor stub
} public Student(String name, int age) {
super();
this.name = name;
this.age = age;
} public Student(int id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
} public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
} }
运行结果就是每一个对数据库的CRUD
第二节:Spring 对Hibernate 的支持
后面Spring 整合Hibernate 的时候会提的。
(四)Spring 对DAO 的支持的更多相关文章
- Spring学习记录4——Spring对DAO的支持
Spring对DAO的支持 随着持久化技术的持续发展,Spring对多个持久化技术提供了集成支持,包括Hibernate.MyBatis.JPA.JDO:此外,还提供了一个简化JDBC API操作的S ...
- Spring对DAO的支持?
Spring对数据访问对象(DAO)的支持旨在简化它和数据访问技术如JDBC,Hibernate or JDO 结合使用.这使我们可以方便切换持久层.编码时也不用担心会捕获每种技术特有的异常.
- Spring 对 DAO 的支持?
Spring 对数据访问对象(DAO)的支持旨在简化它和数据访问技术如 JDBC, Hibernate or JDO 结合使用.这使我们可以方便切换持久层.编码时也不用担心 会捕获每种技术特有的异常.
- 1.Spring对JDBC整合支持
1.Spring对JDBC整合支持 Spring对DAO提供哪些支持 1)Spring对DAO异常提供统一处理 2)Spring对DAO编写提供支持的抽象类 3)提高编程效率,减少DAO编码量 Spr ...
- [Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction
1.Spring中的数据库支持 把具有相同功能的代码模板抽取到一个工具类中.2.关于jdbc template的应用 jdbcTemplate模板操作类,把访问jdbc的模板抽取到template中, ...
- Spring AOP和AspectJ支持
学了Spring之后发现我都不知道java为何物-- 在这一章中有好几节,讲的切面编程 第一节:在项目中启用Spring的AspectJ注解支持 第二节:用AspectJ注解声明aspect 第三节: ...
- Spring【DAO模块】就是这么简单
前言 上一篇Spring博文主要讲解了如何使用Spring来实现AOP编程,本博文主要讲解Spring的DAO模块对JDBC的支持,以及Spring对事务的控制... 对于JDBC而言,我们肯定不会陌 ...
- Spring之DAO模块
Spring的DAO模块提供了对JDBC.Hibernate.JDO等DAO层支持 DAO模块依赖于commons-pool.jar.commons-collections.jar Spring完全抛 ...
- J2EE进阶(四)Spring配置文件详解
J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...
随机推荐
- VC 生成后事件 Post-Build Event
原文链接地址:https://blog.csdn.net/jfkidear/article/details/27313643.https://blog.csdn.net/kevindr/article ...
- 跨域通信的解决方案JSONP
在web2.0时代,熟练的使用ajax是每个前端攻城师必备的技能.然而由于受到浏览器的限制,ajax不允许跨域通信. JSONP就是就是目前主流的实现跨域通信的解决方案. 虽然在在jquery中,我们 ...
- (转)C++常见问题: 字符串分割函数 split
http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速 ...
- [DeeplearningAI笔记]序列模型1.7-1.9RNN对新序列采样/GRU门控循环神经网络
5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.7对新序列采样 基于词汇进行采样模型 在训练完一个模型之后你想要知道模型学到了什么,一种非正式的方法就是进行一次新序列采 ...
- ubuntu环境下添加中文输入法
1.下载软件包 打开终端,输入命令 sudo apt-get install fcitx-table-wbpy 2.打开 system settings-> language support-& ...
- java rmi远程方法调用实例
RMI的概念 RMI(Remote Method Invocation)远程方法调用是一种计算机之间利用远程对象互相调用实现双方通讯的一种通讯机制.使用这种机制,某一台计算机上的对象可以调用另外一台计 ...
- SPOJ DQUERY 离线树状数组+离散化
LINK 题意:给出$(n <= 30000)$个数,$q <= 2e5$个查询,每个查询要求给出$[l,r]$内不同元素的个数 思路:这题可用主席树查询历史版本的方法做,感觉这个比较容易 ...
- MappedByteBuffer以及ByteBufer的底层原理
最近在用java中的ByteBuffer,一直不明所以,尤其是对MappedByteBuffer使用的内存映射这个概念云里雾里. 于是首先补了物理内存.虚拟内存.页面文件.交换区的只是:小科普——物理 ...
- 为什么 .NET 会被叫做 .NET?
微软开发.NET Framework是在20世纪90年代后期,最初是叫做“下一代Windows服务”(Next Generation Windows Services 简称 NGWS). 那么为什么微 ...
- jQuery 写的简单打字游戏
var off_x; //横坐标 var count=0; //总分 var speed=5000; //速度,默认是5秒. var keyErro=0; //输入错误次数 var keyRight= ...