当前位置:文档之家› mybatis-mrt-2.2教程

mybatis-mrt-2.2教程

mybatis-mrt-2.2教程
mybatis-mrt-2.2教程

Mybatis 框架课程

1Mybatis入门

1.1数据准备

test_table_data.sql

数据库文件:

Items.java Orderdetail.java Orders.java OrdersCustom.java 实体对象:

Person.java User.java

1.2单独使用jdbc编程问题总结

1.2.1jdbc程序

Publicstaticvoid main(String[] args) {

Connection connection = null;

PreparedStatement preparedStatement = null;

ResultSet resultSet = null;

try {

//加载数据库驱动

Class.forName("com.mysql.jdbc.Driver");

//通过驱动管理类获取数据库链接

connection =

DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis?charac terEncoding=utf-8", "root", "mysql");

//定义sql语句 ?表示占位符

String sql = "select *from userwhere username = ?";

//获取预处理statement

preparedStatement = connection.prepareStatement(sql);

//设置参数,第一个参数为sql语句中参数的序号(从1开始),第二个参数为设置的参数值

preparedStatement.setString(1, "王五");

//向数据库发出sql执行查询,查询出结果集

resultSet = preparedStatement.executeQuery();

//遍历查询结果集

while(resultSet.next()){

System.out.println(resultSet.getString("id")+" "+resultSet.getString("username"));

}

} catch (Exception e) {

e.printStackTrace();

}finally{

//释放资源

if(resultSet!=null){

try {

resultSet.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(preparedStatement!=null){

try {

preparedStatement.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(connection!=null){

try {

connection.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

上边使用jdbc的原始方法(未经封装)实现了查询数据库表记录的操作。

1.2.2jdbc编程步骤:

1、加载数据库驱动

2、创建并获取数据库链接

3、创建jdbc statement对象

4、设置sql语句

5、设置sql语句中的参数(使用preparedStatement)

6、通过statement执行sql并获取结果

7、对sql执行结果进行解析处理

8、释放资源(resultSet、preparedstatement、connection)

1.2.3jdbc问题总结如下:

1、数据库链接创建、释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接

池可解决此问题。

2、Sql语句在代码中硬编码,造成代码不易维护,实际应用sql变化的可能较大,sql变动

需要改变java代码。

3、使用preparedStatement向占有位符号传参数存在硬编码,因为sql语句的where条件不

一定,可能多也可能少,修改sql还要修改代码,系统不易维护。

4、对结果集解析存在硬编码(查询列名),sql变化导致解析代码变化,系统不易维护,如

果能将数据库记录封装成pojo对象解析比较方便。

1.3MyBatis介绍

MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis,实质上Mybatis对ibatis进行一些改进。

MyBatis是一个优秀的持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动、创建connection、创建statement、手动设置参数、结果集检索等jdbc繁杂的过程代码。

Mybatis通过xml或注解的方式将要执行的各种statement(statement、preparedStatemnt、CallableStatement)配置起来,并通过java对象和statement中的sql 进行映射生成最终执行的sql语句,最后由mybatis框架执行sql并将结果映射成java对象并返回。

1.4Mybatis架构

1、mybatis配置

SqlMapConfig.xml,此文件作为mybatis的全局配置文件,配置了mybatis的运行环境等信息。mapper.xml文件即sql映射文件,文件中配置了操作数据库的sql语句。此文件需要在SqlMapConfig.xml中加载。

2、通过mybatis环境等配置信息构造SqlSessionFactory即会话工厂

3、由会话工厂创建sqlSession即会话,操作数据库需要通过sqlSession进行。

4、mybatis底层自定义了Executor执行器接口操作数据库,Executor接口有两个实现,一个

是基本执行器、一个是缓存执行器。

5、Mapped Statement也是mybatis一个底层封装对象,它包装了mybatis配置信息及sql

映射信息等。mapper.xml文件中一个sql对应一个Mapped Statement对象,sql的id即是Mapped statement的id。

6、Mapped Statement对sql执行输入参数进行定义,包括HashMap、基本类型、pojo,Executor

通过Mapped Statement在执行sql前将输入的java对象映射至sql中,输入参数映射就是jdbc编程中对preparedStatement设置参数。

7、Mapped Statement对sql执行输出结果进行定义,包括HashMap、基本类型、pojo,Executor

通过Mapped Statement在执行sql后将输出结果映射至java对象中,输出结果映射过程相当于jdbc编程中对结果的解析处理过程。

1.5mybatis下载

mybaits的代码由https://www.doczj.com/doc/04762379.html,管理,地址:https://https://www.doczj.com/doc/04762379.html,/mybatis/mybatis-3/releases

mybatis-3.2.7.jar----mybatis的核心包

lib----mybatis的依赖包

mybatis-3.2.7.pdf----mybatis使用手册

1.6创建mysql数据库

先导入sql_table.sql,再导入sql_data.sql脚本:

如下:

1.7Mybatis入门程序

1.7.1需求

实现以下功能:

根据用户id查询一个用户信息

根据用户名称模糊查询用户信息列表

添加用户

更新用户

删除用户

1.7.2第一步:创建java工程

使用eclipse创建java工程,jdk使用1.7.0_72。

1.7.3第二步:加入jar包

加入mybatis核心包、依赖包、数据驱动包。

1.7.4第三步:log4j.properties

在classpath下创建log4j.properties如下:

# Global logging configuration

log4j.rootLogger=DEBUG, stdout

# Console output...

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

https://www.doczj.com/doc/04762379.html,yout=org.apache.log4j.PatternLayout https://www.doczj.com/doc/04762379.html,yout.ConversionPattern=%5p [%t] - %m%n

mybatis默认使用log4j作为输出日志信息。

1.7.5第四步:SqlMapConfig.xml

在classpath下创建SqlMapConfig.xml,如下:

PUBLIC"-//https://www.doczj.com/doc/04762379.html,//DTD Config 3.0//EN"

"https://www.doczj.com/doc/04762379.html,/dtd/mybatis-3-config.dtd">

SqlMapConfig.xml是mybatis核心配置文件,上边文件的配置内容为数据源、事务管理。

1.7.6第五步:po类

Po类作为mybatis进行sql映射使用,po类通常与数据库表对应,User.java如下:

Publicclass User {

privateint id;

private String username;// 用户姓名

private String sex;// 性别

private Date birthday;// 生日

private String address;// 地址

get/set……

1.7.7第六步:程序编写

1.7.7.1查询

1.7.7.1.1映射文件:

在classpath下的sqlmap目录下创建sql映射文件Users.xml:

PUBLIC"-//https://www.doczj.com/doc/04762379.html,//DTD Mapper 3.0//EN"

"https://www.doczj.com/doc/04762379.html,/dtd/mybatis-3-mapper.dtd">

namespace :命名空间,用于隔离sql语句,后面会讲另一层非常重要的作用。

在SqlMapConfig.xml中添加:

parameterType:定义输入到sql中的映射类型,#{id}表示使用preparedstatement设置占位符号并将输入变量id传到sql。

resultType:定义结果映射类型。

1.7.7.1.2加载映射文件

mybatis框架需要加载映射文件,将Users.xml添加在SqlMapConfig.xml,如下:

1.7.7.1.3测试程序:

publicclass Mybatis_first {

//会话工厂

private SqlSessionFactory sqlSessionFactory;

@Before

publicvoid createSqlSessionFactory() throws IOException {

// 配置文件

String resource = "SqlMapConfig.xml";

InputStream inputStream = Resources.getResourceAsStream(resource);

// 使用SqlSessionFactoryBuilder从xml配置文件中创建SqlSessionFactory

sqlSessionFactory = new SqlSessionFactoryBuilder()

.build(inputStream);

}

// 根据 id查询用户信息

@Test

publicvoid testFindUserById() {

// 数据库会话实例

SqlSession sqlSession = null;

try {

// 创建数据库会话实例sqlSession

sqlSession = sqlSessionFactory.openSession();

// 查询单个记录,根据用户id查询用户信息

Useruser = sqlSession.selectOne("test.findUserById", 10);

// 输出用户信息

System.out.println(user);

} catch (Exception e) {

e.printStackTrace();

} finally {

if (sqlSession != null) {

sqlSession.close();

}

}

}

// 根据用户名称模糊查询用户信息

@Test

publicvoid testFindUserByUsername() {

// 数据库会话实例

SqlSession sqlSession = null;

try {

// 创建数据库会话实例sqlSession

sqlSession = sqlSessionFactory.openSession();

// 查询单个记录,根据用户id查询用户信息

List list =

sqlSession.selectList("test.findUserByUsername", "张");

System.out.println(list.size());

} catch (Exception e) {

e.printStackTrace();

} finally {

if (sqlSession != null) {

sqlSession.close();

}

}

}

}

1.7.7.1.4#{}和${}

#{}表示一个占位符号,通过#{}可以实现preparedStatement向占位符中设置值,自动进行java 类型和jdbc类型转换,#{}可以有效防止sql注入。#{}可以接收简单类型值或pojo属性值。如果parameterType传输单个简单类型值,#{}括号中可以是value或其它名称。

${}表示拼接sql串,通过${}可以将parameterType 传入的内容拼接在sql中且不进行jdbc类型转换,${}可以接收简单类型值或pojo属性值,如果parameterType传输单个简单类型值,${}括号中只能是value。

1.7.7.1.5parameterType和resultType

parameterType:指定输入参数类型,mybatis通过ognl从输入对象中获取参数值拼接在sql 中。

resultType:指定输出结果类型,mybatis将sql查询结果的一行记录数据映射为resultType 指定类型的对象。

1.7.7.1.6selectOne和selectList

selectOne查询一条记录,如果使用selectOne查询多条记录则抛出异常:

org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3

at

org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultS qlSession.java:70)

selectList可以查询一条或多条记录。

1.7.7.2添加

1.7.7.

2.1映射文件:

在SqlMapConfig.xml中添加:

select LAST_INSERT_ID()

insert into user(username,birthday,sex,address)

values(#{username},#{birthday},#{sex},#{address})

1.7.7.

2.2测试程序:

// 添加用户信息

@Test

publicvoid testInsert() {

// 数据库会话实例

SqlSession sqlSession = null;

try {

// 创建数据库会话实例sqlSession

sqlSession = sqlSessionFactory.openSession();

// 添加用户信息

Useruser =new User();

user.setUsername("张小明");

user.setAddress("河南郑州");

user.setSex("1");

user.setPrice(1999.9f);

sqlSession.insert("test.insertUser", user);

//提交事务

https://www.doczj.com/doc/04762379.html,mit();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (sqlSession != null) {

sqlSession.close();

}

}

}

1.7.7.

2.3mysql自增主键返回

通过修改sql映射文件,可以将mysql自增主键返回:

select LAST_INSERT_ID()

insert into user(username,birthday,sex,address)

values(#{username},#{birthday},#{sex},#{address});

添加selectKey实现将主键返回

keyProperty:返回的主键存储在pojo中的哪个属性

order:selectKey的执行顺序,是相对与insert语句来说,由于mysql的自增原理执行完insert语句之后才将主键生成,所以这里selectKey的执行顺序为after resultType:返回的主键是什么类型

LAST_INSERT_ID():是mysql的函数,返回auto_increment自增列新记录id值。1.7.7.2.4Mysql使用uuid实现主键

需要增加通过select uuid()得到uuid值

keyProperty="id">

select uuid()

insert into user(id,username,birthday,sex,address)

values(#{id},#{username},#{birthday},#{sex},#{address})

注意这里使用的order是“BEFORE”

1.7.7.

2.5Oracle使用序列生成主键

首先自定义一个序列且用于生成主键,selectKey使用如下:

keyProperty="id">

SELECT 自定义序列.NEXTVAL FROM DUAL

insert into user(id,username,birthday,sex,address)

values(#{id},#{username},#{birthday},#{sex},#{address})

注意这里使用的order是“BEFORE”

1.7.7.3删除

1.7.7.3.1映射文件:

delete from userwhere id=#{id}

1.7.7.3.2测试程序:

// 根据id删除用户

@Test

publicvoid testDelete() {

// 数据库会话实例

SqlSession sqlSession = null;

try {

// 创建数据库会话实例sqlSession

sqlSession = sqlSessionFactory.openSession();

// 删除用户

sqlSession.delete("test.deleteUserById",18);

// 提交事务

https://www.doczj.com/doc/04762379.html,mit();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (sqlSession != null) {

sqlSession.close();

}

}

}

1.7.7.4修改

1.7.7.4.1映射文件

update userset

username=#{username},birthday=#{birthday},sex=#{sex},address=#{address} where id=#{id}

1.7.7.4.2测试程序

// 更新用户信息

@Test

publicvoid testUpdate() {

// 数据库会话实例

SqlSession sqlSession = null;

try {

// 创建数据库会话实例sqlSession

sqlSession = sqlSessionFactory.openSession();

// 添加用户信息

Useruser =new User();

user.setId(16);

user.setUsername("张小明");

user.setAddress("河南郑州");

user.setSex("1");

user.setPrice(1999.9f);

sqlSession.update("test.updateUser", user);

// 提交事务

https://www.doczj.com/doc/04762379.html,mit();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (sqlSession != null) {

sqlSession.close();

}

}

}

1.7.8Mybatis解决jdbc编程的问题

1、数据库链接创建、释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接

池可解决此问题。

解决:在SqlMapConfig.xml中配置数据链接池,使用连接池管理数据库链接。

2、Sql语句写在代码中造成代码不易维护,实际应用sql变化的可能较大,sql变动需要改

变java代码。

解决:将Sql语句配置在XXXXmapper.xml文件中与java代码分离。

3、向sql语句传参数麻烦,因为sql语句的where条件不一定,可能多也可能少,占位符

需要和参数一一对应。

解决:Mybatis自动将java对象映射至sql语句,通过statement中的parameterType定义输入参数的类型。

4、对结果集解析麻烦,sql变化导致解析代码变化,且解析前需要遍历,如果能将数据库

记录封装成pojo对象解析比较方便。

解决:Mybatis自动将sql执行结果映射至java对象,通过statement中的resultType定义输出结果的类型。

1.7.9与hibernate不同

Mybatis和hibernate不同,它不完全是一个ORM框架,因为MyBatis需要程序员自己编写Sql语句,不过mybatis可以通过XML或注解方式灵活配置要运行的sql语句,并将java 对象和sql语句映射生成最终执行的sql,最后将sql执行的结果再映射生成java对象。

Mybatis学习门槛低,简单易学,程序员直接编写原生态sql,可严格控制sql执行性能,灵活度高,非常适合对关系数据模型要求不高的软件开发,例如互联网软件、企业运营类软件等,因为这类软件需求变化频繁,一但需求变化要求成果输出迅速。但是灵活的前提是mybatis无法做到数据库无关性,如果需要实现支持多种数据库的软件则需要自定义多套sql 映射文件,工作量大。

Hibernate对象/关系映射能力强,数据库无关性好,对于关系模型要求高的软件(例如需求固定的定制化软件)如果用hibernate开发可以节省很多代码,提高效率。但是Hibernate 的学习门槛高,要精通门槛更高,而且怎么设计O/R映射,在性能和对象模型之间如何权衡,以及怎样用好Hibernate需要具有很强的经验和能力才行。

总之,按照用户的需求在有限的资源环境下只要能做出维护性、扩展性良好的软件架构都是好架构,所以框架只有适合才是最好。

2Dao开发方法

使用Mybatis开发Dao,通常有两个方法,即原始Dao开发方法和Mapper接口开发方法。

2.1需求

将下边的功能实现Dao:

根据用户id查询一个用户信息

根据用户名称模糊查询用户信息列表

添加用户信息

2.2SqlSession的使用范围

SqlSession中封装了对数据库的操作,如:查询、插入、更新、删除等。

通过SqlSessionFactory创建SqlSession,而SqlSessionFactory是通过SqlSessionFactoryBuilder 进行创建。

2.2.1SqlSessionFactoryBuilder

SqlSessionFactoryBuilder用于创建SqlSessionFacoty,SqlSessionFacoty一旦创建完成就不需要SqlSessionFactoryBuilder了,因为SqlSession是通过SqlSessionFactory生产,所以可以将SqlSessionFactoryBuilder当成一个工具类使用,最佳使用范围是方法范围即方法体内局部变量。

2.2.2SqlSessionFactory

SqlSessionFactory是一个接口,接口中定义了openSession的不同重载方法,SqlSessionFactory的最佳使用范围是整个应用运行期间,一旦创建后可以重复使用,通常以单例模式管理SqlSessionFactory。

2.2.3SqlSession

SqlSession是一个面向用户的接口,sqlSession中定义了数据库操作,默认使用DefaultSqlSession实现类。

执行过程如下:

1、加载数据源等配置信息

Environment environment = configuration.getEnvironment();

2、创建数据库链接

3、创建事务对象

4、创建Executor,SqlSession所有操作都是通过Executor完成,mybatis源码如下:

if (ExecutorType.BATCH == executorType) {

executor = new BatchExecutor(this, transaction);

} elseif (ExecutorType.REUSE == executorType) {

executor = new ReuseExecutor(this, transaction);

} else {

executor = new SimpleExecutor(this, transaction);

}

if (cacheEnabled) {

executor = new CachingExecutor(executor, autoCommit);

}

5、SqlSession的实现类即DefaultSqlSession,此对象中对操作数据库实质上用的是Executor

结论:

每个线程都应该有它自己的SqlSession实例。SqlSession的实例不能共享使用,它也是线程不安全的。因此最佳的范围是请求或方法范围。绝对不能将SqlSession实例的引用放在一个类的静态字段或实例字段中。

打开一个SqlSession;使用完毕就要关闭它。通常把这个关闭操作放到finally 块中以确保每次都能执行关闭。如下:

SqlSession session = sqlSessionFactory.openSession();

try {

// do work

} finally {

session.close();

}

2.3原始Dao开发方式

原始Dao开发方法需要程序员编写Dao接口和Dao实现类。

2.3.1映射文件

PUBLIC"-//https://www.doczj.com/doc/04762379.html,//DTD Mapper 3.0//EN"

"https://www.doczj.com/doc/04762379.html,/dtd/mybatis-3-mapper.dtd">

select LAST_INSERT_ID()

insert into user(username,birthday,sex,address)

values(#{username},#{birthday},#{sex},#{address})

2.3.2Dao接口

Publicinterface UserDao {

public User getUserById(int id) throws Exception;

publicvoid insertUser(Useruser)throws Exception;

}

Publicclass UserDaoImpl implements UserDao {

//注入SqlSessionFactory

public UserDaoImpl(SqlSessionFactory sqlSessionFactory){

this.setSqlSessionFactory(sqlSessionFactory);

}

private SqlSessionFactory sqlSessionFactory;

@Override

public User getUserById(int id) throws Exception {

SqlSession session = sqlSessionFactory.openSession();

Useruser =null;

try {

//通过sqlsession调用selectOne方法获取一条结果集

//参数1:指定定义的statement的id,参数2:指定向statement中传递的参数

user = session.selectOne("test.findUserById", 1);

System.out.println(user);

} finally{

session.close();

}

return user;

}

@Override

Publicvoid insertUser(Useruser)throws Exception {

SqlSession sqlSession= sqlSessionFactory.openSession();

全国英语等级考试(PETS1-5)复习辅导

1、词汇pets1-5级的词汇要求是1000-7500词。学习这些词汇时应掌握大纲词汇表所列词汇的音标,词素分析,词性,英文例句,相关词组和短语以及派生词。 语言记忆规律告诉我们,对语言加工的程度越深记忆就越深刻。 所以学习词汇时要学习每一个单词的方方面面从而加深记忆;一切语言输入必须是有意义的,音必须在词中学,词必须在许多不同的句子语境中去学。因此我们学习的例句不仅能让我们了解单词的用法还可以帮助记忆单词本身。个人兴趣也会影响人的记忆,我们学习的例句应与我们的现实生活紧密联系,这样可以提高学习兴趣,接触活的语言。 2、大纲中规定的考试项目包括听力、语言知识应用、阅读理解、写作和口语等五部分。这五部分内容就是pets书面考试的四种题型和口试。 听力部分要求掌握考试大纲所列的功能意念表和语言技能表,详细了解各种听力能力的标准和培养方法,然后进行相应的练习;考试前做一些与pets考试出题形式和试题结构一致的模拟训练题。平时应利用一切机会多听,包括对教材内容的精听和各种英语广播节目的泛听;了解时事、关注社会热点,扩大知识面等对提高听力能力都有帮助。 总的来说,语言知识运用部分体现在完形填空这种题型上。它是综合考查应试者英语水平的题型。针对此种题型,我们应分别从词汇、语法和语篇层次上学习应对方法,提高对连贯性和一致性等语段特征的掌握和对一定语境下规范的语言成分的掌握。每部分复习完后应做一些相应的练习题。个别级别的本部分还保留有语法填空题,那是我国的英语学习者的拿手好戏。 阅读理解部分全面介绍了大纲规定的阅读能力的构成和培养,包括 (1)理解主旨要义; (2)理解文中具体信息; (3)根据上下文推测生词的词义; (4)进行有关的判断、推理和引申; (5)理解文中的概念性含义; (6)理解文章的结构以及单词之间、段落之间的关系; (7)快速阅读较长的文字材料,获取有关信息; (9)区分观点、论点和论据; 写作在pets考试中被称作语言产出能力的一种,也就是以书面的形式与他人交流的能力。我们从选词造句,连句成段和连段成篇等方面全面学习英语写作基础知识和现实交际所需的各种实用文体的写作。 还应掌握优秀文章的写作技巧,进行适当的写作练习是最终提高写作能力的必由之路。 口语部分,我们应详尽了解各种功能意念在口语表达中的运用,以及pets口试的三个部分,即考生与口试教师的交流、两个考生的相互交流和每个考生的连续表达及两个考生的相互提问的试题形式、考查内容和应试技巧。平时还应有意识地参加一些英语交际活动。在实际工作中验证各种表达方式的交际效果和自己利用外语完成一定任务的能力。 pets是一种新型的考试,我们参加的目的是测试自己的英语应试能力,我们的学习应围绕这一中心,但是我们多年来积累起来的一些教与学的方法和技巧也有它继续存在的合理性,因为目前在短时间内测试语言水平还要靠考试这种形式。 全国英语等级考试复习辅导(二)

初级中学三级-五级考试题型(国标版,新课标版)

第二十一届《新课标英语考级教程》初中三、四、五级考试题型 注意:此题考级的试题核心重点严格贯彻2011年6月版《英语课程标准》的要求和规定。 第二十一届新课标英语等级测试全国统一试题(EGT初中三、四、五级),本套试题总分120分,一共三部分—听力、笔试、口试。 第一部分为听力,分值为20分; 第二部分为基础知识与综合能力运用,分值为80分; 第三部分为口试,分值为20分。 全部答案都必须按要求在答题卡中相对应题号下填涂或书写,要求填涂正确、书写工整、清晰、规范,卷面清洁。 (考试只是手段,不是目的。所以能让学生在准备考试的过程中不断的提高才是考试的真正目的。不管是何种题型,都不该仅仅拘泥于对单个知识点的考查,而应考查学生在具体情境中运用所学英语知识与技能的综合语言运用能力。) 第Ⅰ卷听力占笔试20% (共20分每个小题1分) 一、听录音,从下面所给的选项中选择与句子内容相符的图片。每个对话读两遍。(共5分,每小题1分) 备注:难度递进,5级句子只读一遍。 e.g. (C)1. A. B. C.

录音原文:1. T om is reading. 评析 此题型要求学生听句子选择与句子描述相符合的图片。可以考查学生看图想其英语表达,听音联系其英文表达,达到通过一个题目考查学生三种能力的目的。注意在选图时,所使用的图画要清晰明了。尽量避免因学生的生活经验或文化背景的差异而导致不能正确识别图画的可能性。 二、听录音,根据你听到的句子,选出最恰当的应答。每个句子读两遍。(共5分,每小题1分) e.g.(A)1. A. Here you are. B. Here we are. C. It‘s yours. 录音原文:Q: Can I borrow your pen? 评析 此题型要求学生在听到句子后,给出相应的答语。考查学生反应能力。这种形式的题型很接近生活中英语的实际运用,即一些应答,寻求信息等。 三、听录音,判断下列句子是否符合你所听到的对话内容,符合的用“A”表示,不符合的用“B”表示。每个句子读两遍。(共5分,每小题1分) e.g. ( B ) 1.The dinner will be ready in an hour and hal f. 录音原文:---I am so hungry. When will the dinner be ready, mum?

全国英语等级考试PETS第二级全真模拟试卷一

考试时间120分钟. 第一部分听力 第一节听下面5段对话。每段对话后有一个小题,从题中所给的[A]、[B]、 [c]三个选项中选出最佳选项,并标在试卷的相应位置。听完每段对话后,你都有10秒钟的时间来回答有关小题和阅读下一小题。每段对话仅读一遍。 1. Where did the woman say she put her glasses? [A] In the cupboard. [B] On the desk. [C] She couldn' t remember exactly. 2. When will the bank be open on Saturday? [A]12 noon to 9 p.m. [B]9 a.m. to 5 p.m. [C]9 a.m. to12 noon. 3. How .does the woman feel about the news? [A] She is quite sympathetic towards the doctor. [B] She thinks it' s right. [C]She does not care 4. What are the speakers talking about? [A] Maybe a picnic. [B] Maybe something new. [C] Maybe a new car. 5. What does the man possibly do? [A]Maybe a teacher. [B] Maybe a student. [C] Maybe a meeting organizer, 第二节听下面5段对话或独自。每段对话或独自后有几个小题,从题中所给 的[A]、[B]、[C]三个选项中选出最佳选项,并标在试卷的相应位置。听每段对话 或独白前,你将有时间阅读各个小题,每小题5秒钟;听完后,各小题将给出5秒钟 的作答时间。每段对话或独白读两遍。 听第6段材料,回答第6~7题。 6. Why does Jane want to leave her present job? [A]Because she does not like the job. [B] Because she wants to do something different.

全国英语等级考试考试1级教材(Word)可编辑

Unit 1 Greetings and Introductions 问候与介绍 Dialogues 1 Ann and Joe meet each other for the first time. Ann: How do you do? Joe: How do you do? Ann: My name is Ann. Joe: I am Joe. Ann: Glad to meet you. Joe: Glad to meet you, too. Ann: I’m afraid I must be going now. Joe: See you tomorrow. 2 Ann and her friend Carter meet Mr. Bush at the airport. Ann: Excuse me. Are you Mr. Bush from England? Mr. Bush: Yes, I am. May I have your name? Ann: Sure. My name is Ann Taylor. How do you do? Mr. Bush: How do you do? Ann: May I introduce Mr. Carter to you? Mr. Bush: Yes, please. Ann: Mr. Bush, this is Mr. Carter. Mr. Carter, this is Mr. Bush. He is from England. Carter: Pleased to meet you! Mr. Bush: Pleased to meet you, too! 3 Bill and Susan meet each other. Bill: Good morning, Susan. Susan: Morning, Bill. How are you? Bill: Fine, thank you. And you? Susan: Me too, thank you. How about your sister Lily? Bill: She is fine, but she is very busy. Susan: Please give my best wishes to her. Bill: I will.

《新课标英语考级教程》小学一二级考试题型

十九届《新课标英语考级教程》小学一、二级考试题型 注意:此题考级的试题核心重点严格贯彻2011年6月版《英语课程标准》的要求和规定。 第十九届新课标英语等级测试全国统一试题(EGT小学一、二级),本套试题总分120分,一共三部分—听力、基础知识与综合能力运用和口试。 第一部分为听力,分值为20分; 第二部分为基础知识与综合能力运用,分值为80分; 第三部分为口试,分值为20分。 全部答案都必须按要求在答题卡中相对应题号下填涂或书写,要求填涂正确、书写工整、清晰、规范,卷面清洁。 (考试只是手段,不是目的。所以能让学生在准备考试的过程中不断的提高才是考试的真正目的。不管是何种题型,都不该仅仅拘泥于对单个知识点的考查,而应考查学生在具 体情境中运用所学英语知识与技能的综合语言运用能力。) 第Ⅰ卷听力理解占笔试20% (共20分每个小题1分) 一、听录音,选择你所听到的单词。每个单词只读一遍。(共5分,每小题1分) e.g. (C) 1. A. cup B. cap C. cake 录音原文:1. cake 评析 此题型要求学生听单词录音选择单词。主要考察学生对语音知识的掌握。题目中设计的单词都会含有相同或者相似的一部分字母或者字母组合,学生需要准确掌握其读音才能更准确地完成此题。 ) 二、听录音,选择与你所听到单词相符的图片。每个单词只读一遍。(共5分,每小题1分 录音原文:1. listen 评析 此题型要求学生听单词录音选择与单词相符合的图片。可以考查学生看图想其英语表达,听音联系其英文表达,达到通过一个题目考查学生三种能力的目的。注意在选图时,所使用的图画要清晰明了。尽量避免因学生的生活经验或文化背景的差异而导致不能正确识别图画的可能性。

全国公共英语等级考试英语一级(1级)试题 含答案

全国公共英语等级考试英语一级(1级)模拟试题含答案 第一节:单项选择 从A、B、C、D四个选项中,选出可以填入空白处的最佳选项,并在答题卡上将该项涂黑. 1. ----- will you be able to finish the job this week? ----- ___________ , but I'm not skilled enough, you know. A.I can't say so B.I expect so C. I'm sure so D. I don't know so 2. We arrived at the station _______ late, or we the bus. A. too much; would catch B. a little too; had caught C. much too; would have caught D. too much; would have caught 3. Is it the watch you want ________? A. to have it repaired B. to repair it C. to have repaired D. to have repaired it 4. The two thieves fled the town separately, _______ a bag. A. each carrying B. whose that watch is C. whose watch is that D. whose watch is 5. The little boy can't tell ________. A. whose is that watch B. whose that watch is C. whose watch is that D. whose watch is 6. If a baby bird stays _______ for two or three weeks after leaving the nest, it has a fair chance of becoming an adult. A. living B. lively C. alive D. live 7. We will not attack ______ we are attacked;if attacked,we will certainly counter-attack. A. if B. when C. unless D. even if 8. You can take ______ seat you like. A. no matter what B. no matter which C. what D. whichever 9. I ______ to speak to you all these days. A. wanted B. have wanted C. shall want D. shall be wanting 10.A burning cigarette he threw into the wastepaper basket ______ fire to the hotel. A. made B. set C. caused D. caught 11."Do you hear someone knocking at the door?" "Yes, I did. I heard him ______ three times." A. knocking B. knocked C. being knocking D. knock 12.Peter,John and Tom each ______. A. say they came first B. says they came first C. says he came first D. say came first 13.Through long power lines electricity goes ______. A. to the place needed B. there it is needed C. where it is needed D. which it is needed 14. ______ from the apple tree. A. It down fell B. there it is needed C. Down fell it D. Fell it down 15.The service in this restaurant is very poor;there are not enough waiters to wait ______ customers. A. on B. for C. with D. to 第二节:完形填空 阅读下面短文,从短文后所给各题的四个选项(A、B、C、D中选出能填入相应空白处的最佳选项,并在答题卡上将该项涂黑.

新课标英语考级教程三级A-1

新课标英语考级教程3A Lesson7 第3课时 What would you like? 浙江省象山协华外语学校Eva 一、Teaching contents: Dialogue1 —What would you like? 二、Teaching aims and demands: (1) M aster skillfully and use the pattern:would like sth, would like to do sth (2) L et Ss learn to make sentences with the substitutions. 三、Main points: Master and use the patterns:would like sth, would like to do sth 四、Difficult points: (1) would like “... ,想要...”,相当于want,是较委婉的表达方式,后接名词或动词不定式. (2) how much 多少,是对数量或价钱来提问. 五、 Teaching aids: (1) A recorder (2) some pictures 六、Teaching procedures: Step1 Preparation (1) T: Hello,everyone. S: Hello,Miss Yu. (2) T: Who is not here? S: Li Ming is not here. (3) T: What day is today? S: It’s Thursday. (4) T: How’s the weather? S: It’s sunny. (5) T: What food do you like? S: I like vegetables. (6) T: Do you like coffee? S: Yes, I do./ No, I don’t. Step2 Revision (1) Review the following words we have learned last class: well,fresh,Sprite, salad, biscuit, shopkeeper, done, medium, bean, order, dinner, waitress, steak, rare. a. Teacher speaks in English,Ss speak in Chinese quickly. b. Teacher speaks in Chinese, Ss speaks in English one by one. (2) Listen and write down the following words and their Chinese meanings: well,fresh,done, bean,order, steak. Step3 Presentation (1) Lead in the dialogue. T: We eat something every day,but some people like to eat apples,some people don’t. Now firstly, I tell you what I would like to eat.Listen to me carefully,then I will ask you. Teacher shows some pictures and says: I’d like some bread. I’d like some biscuits. I’d like to eat apples. I’d like to eat bananas. (Teacher writes down the four sentences on the blackboard and ask Ss to read them after the teacher.) T: What would you like? (Let Ss try to say,the teacher guides them.)

全国英语等级考试二级模拟试题

全国英语等级考试二级模拟试题(二) 第一部分听力理解(略) 第二部分英语知识运用 第一节单项填空 1.He is ______ a writer. A. failure as B. a failure as C. the failure for D. a failure with 2.– can you come on Monday or Tuesday? – I'm afraid ______ day is possible. A. either B. neither C. any D. some 3.Dr. Black comes from either Oxford or Cambridge. I can't remember ______. A. where B. there C. which D. what 4.In the centuries _____, Egypt became one of the most advanced civilizations on earth. A. followed B. tat was followed C. which was following D. which followed 5.To enter his house is like ______ a small museum. A. to enter B. entering C. entered D. enter 6.The local government cut down their costs ______ 30 percent. A. at B. by C. for D. with 7.I'm reading his ______ novel. A. best-selling B. best-sold C. best-sale D. best-sell 8.It's rude of you to shout _______ the room. A. beyond B. through C. across D. over 9.People are more likely to stay _______ 30 miles of _______ they were born. A. in … where B. at … what C. within … what D. within … where 10.After searching for half an hour, she realized that her glasses ______ on the table all the time. A. were lain B. had been lain C. have been lying D. had been lying 11.Facts show that as many as 50 percent of patients do not take drugs ______ directed. A . like B. as C. which D. so 12.I walked too much yesterday and ______ are still aching now. A. my leg muscles B. my muscles of leg C. my leg's muscles D. my muscles of the leg 13.He will have ______ 30 by the end of this year. A. turned B. become C. got D. taken 14.Macao ______ its return to China in December, 1999. A. watched B. found C. saw D. noticed 15.This hotel _______ $60 for a single room with bath. A. charges B. demands C. prices D. claims 第二节完形填空 My father waved me goodbye and the bus (16)_____. My first country journey then began. The man sitting next to me was a road engineer. He said that (17)_____ by bus was an excellent way to (18)_____ road for him. We passed many villages on the way and stopped once (19)_____ to buy cold drinks, (20)_____ it was very hot. The countryside was brown and dry and there were long (21)_____ with no people or villages in (22)_____. We also stopped once at

【资格考试】2019最新整理--(历年真题)全国英语等级考试(PETS)三级样题

——教学资料参考参考范本——【资格考试】2019最新整理-- (历年真题)全国英语等级考试(PETS)三级样题 ______年______月______日 ____________________部门

PETS Level 3 Sample Tasks Section I: Listening ComprehensionThis section is designed to test your ability to understand spoken English. You will hear a selection of recorded materials and you must answer the questions that accompany them. There are two parts in this section, Part A and Part B. Remember, while you are doing the test, you should answer the questions in your test booklet, NOT on the ANSWER SHEET. At the end of the listening comprehension section, you will have 3 minutes to transfer your answers from your test booklet onto your ANSWER SHEET1. If you have any questions, you may raise your hand NOW as you will not be allowed to speak once the test is started.Now look at Part A in your test booklet. Part A:You will hear 10 short dialogues. For each dialogue, there is one question and four possible answers. Choose the correct answer A, B, C or D, and mark it in your test booklet. You will have 15 seconds to answer the question and you will hear each dialogue ONLY ONCE. Example:You will hear:W: Could you please tell me if the Beijing flight will be arriving on time?M: Yes, Madam. It should be arriving in about ten minutes.You will read:Who do

全国公共英语等级(PETS)考试技巧

听力部分: 听力部分在100分的原始分就占20分, 而其加权占了30%, 可见pets对听力的重视。 提高听力的水平, 必须多听; 要听就必须有合适的听力材料, 有恰当的练习方法。一般说来, 在学习第二语言时, 一个人的听力和他的阅读能力相比往往差了一些, 因此选择听力材料相对容易。听力材料可以分三部分: 一是各种考试真题和模拟题的录音带; 二是英美新闻或广播专题; 三是趣味英语。不管选什么, 选材不易过难, 因为那样会挫伤练习听力的兴趣和积极性; 但也不能太容易, 因为什么都听懂了, 就起不到练习的效果。因此, 要选那些大部分都能听懂, 但又不能完全听懂得内容, 反复多听几篇, 最后争取全听懂。各级的pets考试对听力的要求不同, 对不同的级别采取不同的复习策略; 例如, pets三级对听力的要求是考生理解事实性信息的能力(a部分)和理解总体和特定信息的能力(b部分), 这就要求考生掌握在交际场合各类听力测试题的解题方式,如人物关系的判断、谈话发生地点时间的推理、对话所谈论事件的判断、对未来的推测、说话者寓意的判断、原因的推断、计算等。考生应采取针对性的练习, 复习听力首先从功能意念开始,包括友好往来、交流补救、态度、情感、影响生活的话语、时间表达、空间意念和比较关系等。从听力信息上讲,应当学会理解主旨要义、获取事实性具体信息、理解明确表达的概念性含义、进行有关的判断、推理和引申、理解说话者的意图、观点或态度等。 提高英语听力的水平单靠"听"是不能解决问题的, 个人的听力水平的高低与其掌握的词汇量、对语法结构的熟悉程度、知识面、理解能力甚至阅读速度等都密切相关。考生平时应注意全面提高自身英语各方面的水平。 应试时, 考生要做好充分的思想准备, 以正常心态应试。首先, 要充满自信, 相信自己能正常发挥水平, 考出理想成绩; 其次, 要实事求是, 估计到考试中可能出现的困难。考试时争取会的题不丢分, 没有把握的题尽可能争取得分。即使有的词或句子没有听清, 甚至没有听见, 也不要过分思考, 不要滞留, 要舍得放弃。以保证听好下面的内容。实际上, 个别单词和句子没有抓住一般不一定会影响做题。

全国英语等级考试一级模拟试题1

全国公共英语等级考试(1级)模拟试题(2) 第一节:单项选择 从A、B、C、D四个选项中,选出可以填入空白处的最佳选项,并在答题卡上将该项涂黑. 1. ----- will you be able to finish the job this week? ----- ___________ , but I'm not skilled enough, you know. A.I can't say so B.I expect so C. I'm sure so D. I don't know so 2. We arrived at the station _______ late, or we the bus. A. too much; would catch B. a little too; had caught C. much too; would have caught D. too much; would have caught 3. Is it the watch you want ________? A. to have it repaired B. to repair it C. to have repaired D. to have repaired it 4. The two thieves fled the town separately, _______ a bag. A. each carrying B. whose that watch is C. whose watch is that D. whose watch is 5. The little boy can't tell ________. A. whose is that watch B. whose that watch is C. whose watch is that D. whose watch is 6. If a baby bird stays _______ for two or three weeks after leaving the nest, it has a fair chance of becoming an adult. A. living B. lively C. alive D. live 7. We will not attack ______ we are attacked;if attacked,we will certainly counter-attack. A. if B. when C. unless D. even if 8. Y ou can take ______ seat you like. A. no matter what B. no matter which C. what D. whichever 9. I ______ to speak to you all these days. A. wanted B. have wanted C. shall want D. shall be wanting 10.A burning cigarette he threw into the wastepaper basket ______ fire to the hotel. A. made B. set C. caused D. caught 11."Do you hear someone knocking at the door?" "Yes, I did. I heard him ______ three times." A. knocking B. knocked C. being knocking D. knock 12.Peter,John and Tom each ______. A. say they came first B. says they came first C. says he came first D. say came first 13.Through long power lines electricity goes ______. A. to the place needed B. there it is needed C. where it is needed D. which it is needed 14. ______ from the apple tree. A. It down fell B. there it is needed C. Down fell it D. Fell it down 15.The service in this restaurant is very poor;there are not enough waiters to wait ______ customers. A. on B. for C. with D. to 第二节:完形填空 阅读下面短文,从短文后所给各题的四个选项(A、B、C、D中选出能填入相应空白处的最佳选项,并在答题卡上将该项涂黑.

全国英语等级考试教材第五级

Text A The Revolution That Turned Education Sentimental At some point in the mid-1960s the picture of the classroom in the national imagination changed. Before, it consisted of ranks of traditional, slope-surfaced wooden desks at which sat uniformed children, their heads bowed, before an authoritarian and perhaps eccentric teacher. After, there were tables organized into groups, no uniforms and a nice, friendly teacher who probably liked the same pop music as his pupils. This is a cartoon view, but it depicts a real change. It was an educational revolution that was well-meant, benignly inspired by concern for our children and apparently, endorsed by some of the greatest minds of our age. Its ideal was to help children grow and its politics were egalitarian. With Shirley Williams’ abolition of most grammar schools and the introduction of comprehensives, the plan was in place. It was, as we and the Prince of W ales now know, an unmitigated disaster. Understanding why we did it and why it fails is a gloomy but necessary business. Perhaps it was simply because it seems like a nice thing to do. Of course teachers should help children to grow up; of course comprehensives should break down class divisions; of course grim authority should give way to happy enthusiasm. These were simple ideals, but they were created by a thought process and it is this that now has to be dismantled. The first point is not to be confused by the politics. Today’s teachers are not the raging extremists of Tory and tabloid mythology. Indeed, more than 50% of them,

全国英语等级考试模拟试题

全国英语等级考试(一级)模拟试题 第一部分听力(略) 第二部分英语知识运用 第一节单项填空 阅读下面的句子和对话,从三个选项中选出一个能填入空白处的最佳选项,并在答题卡将该项涂黑。 26. He is badly ill. We must ___B__ a doctor at once. A. send to B. send for C. send away 27. The hospital ____C___ last year. A. built B. was built C. has been built 28. When I came into the classroom, the teacher ___B__something on the blackboard. A. is writing B. was writing C. wrote 29. --How long have you been ill -- A A. Since last week B. A week ago C. Once a week 30. Everybody is here __C___Mike. A .not B. and C. except 31. We don’t understand the passage __C_ there are a few new words in it. A. and B. unless C. because 32. The TV set is very nice. How long have you ___C____it A. bought B. had C. taken 33. --- Shall I get one more apple for you, Dad ---Thanks, but you ___C____. I’ve had enough. A. may not B. must not C. needn’t 34. --- ____B_____is your shirt --- It is 100yuan. A. How many B. How much C. How long 35. He is ___C____kind an old man that all the children like him. A. very B. so C. such 36. Either Jim or Sam __A____going to help the farmers with the orange harvest this afternoon. A. was B. were C. is 37. We have studied for two hours. Let’s stop _______B__________. A. have a rest B. to have a rest C. having a rest 38. We won’t go to Great Wall if it ___B_____tomorrow. A. rains B. rain C. will rain 39. No book and no pen__A____in the bag. A. is B. are C. has 40. Please give me ___C___. A. two cups of milks B. two cup of milk C. two cups of milk 第二节完形填空 阅读下面短文,从短文后所给的三个选项中选出能填入相应空白处的最佳选项,并在答题卡1上将该项涂黑。 It’s fine spring weather now. The trees and fields are___C__. The farmers are busy ___B__in the fields. The birds are singing happily in the forest and the__C__ are coming out. The sun is shining warmly and __C__ is a warm wind. Some little boys are flying kites in the fields. They like the wind

相关主题
文本预览
相关文档 最新文档