Java EE Enterprise Application Development Tutorial Question Bank (Second Edition)

foreword

  Java EE is a practical course, but most of the exams are theoretical. I want to understand three frameworks in one semester, hehe, it's difficult! If you are a freshman, freshman, and sophomore, it is really useful to study hard. If you are a junior student, such as a student who is employed and going in this direction, study hard. If you are a student in the third year of the postgraduate entrance examination, arrange your own time. Here are my five usual assignments, built into a question bank for everyone to search. The answer part inside is very strange, but it is the standard answer, you can discuss it with the teacher. Rules of use: Ctrl + F keys to search for the topic you need.


Homework 1 Getting to know Mybatis

multiple choice

1. Regarding the solution provided by MyBatis to solve the disadvantages of JDBC programming, the statement is wrong ().
A. Configure the data link pool in SqlMapConfig.xml, and use the connection pool to manage the database link.
B. MyBatis configures the SQL statement in the MyBatis mapping file without separation from the Java code
. C. MyBatis automatically maps the Java object to the SQL statement. Define the type of input parameters through parameterType in Statement
D, MyBatis automatically maps SQL execution results to Java objects, and define the type of output results through resultType in Statement

1 Reference answer: B
[Answer analysis]
MyBatis configures the SQL statement in the MyBatis mapping file, realizing the separation from the Java code.

2. The following statement about the attributes of the elements in the mapping file is correct ().

A. The value of the parameterType attribute indicates the returned entity class object
B. The value of the namespace attribute is usually set to the fully qualified class name of the corresponding entity class
C. The value of the resultType attribute indicates the incoming parameter type
D. The above statements are not correct

2 Refer to answer B
[Answer Analysis]
The value of the parameterType attribute indicates the type of the parameter passed in, and the value of the resultType attribute indicates the returned entity class object, using package.class name


3. Among the following options, the correct statement about the configuration of MyBatis is ()
A. The Mapper.xml core configuration file mainly configures the operating environment of MyBatis and other information.
B. SQL statements for operating the database are configured in mybatis-config.xml.
C. The session factory SqlSession can be directly built through MyBatis environment and other configuration information.
D. MyBatis can load multiple mapping files, and each mapping file corresponds to a table in the database.

3 Reference answer: D
[Answer analysis]
1. The core configuration file mybatis-config.xml mainly configures the operating environment of MyBatis and other information.
2. The Mapper.xml file configures the SQL statement for operating the database, which needs to be loaded in mybatis-config.xml to be executed. mybatis-config.xml can load multiple mapping files, and each mapping file corresponds to a table in the database.
3. Construct the session factory SqlSessionFactory through MyBatis environment and other configuration information to create SqlSession.

4. The following statement about the MyBatis framework is correct ().
A. MyBatis is a semi-automatic mapping framework. The so-called "semi-automatic" here is relative to Hibernate full table mapping. B.
MyBatis is a business logic layer framework.
C. MyBatis has higher encapsulation than Hibernate.
D. MyBatis is A framework for full table mapping

4 Reference answer: A
[Answer analysis]
MyBatis was originally iBatis, an open source project of Apache. In 2010, this project was migrated from Apache Software Foundation to Google Code, and renamed MyBatis. In November 2013, MyBatis was migrated to Github. MyBatis is an excellent persistence layer framework, which can establish a mapping relationship between entity classes and SQL statements. It is a semi-automatic ORM (Object/Relation Mapping, object-relational mapping) implementation. MyBatis is less encapsulated than Hibernate, but it has superior performance, is easy to learn, and is widely used in the development of Internet applications.

5. The statement about the working principle of MyBatis is wrong ().

A. The global configuration file of MyBatis configures information such as the operating environment of MyBatis, the main content of which is to obtain the database connection. B. The
SQL statement for operating the database is configured in the MyBatis mapping file, which needs to be loaded in the global configuration file of MyBatis to be executed.
C. The session object SqlSession D and SqlSession object can be constructed through MyBatis environment and other configuration information
, which contains all the methods for executing SQL

5 Reference answer: C
[Answer analysis]
The session factory SqlSessionFactory is built through MyBatis environment and other configuration information

6. In traditional JDBC programming, SQL changes need to change Java code, which violates the principle of opening and closing. Which of the following methods can solve this problem? ()
A. MyBatis configures the SQL statement in the MyBatis mapping file, realizing the separation from the Java code.
B. MyBatis automatically maps the Java object to the SQL statement, and defines the type of the input parameter through the parameterType in the Statement.
C. MyBatis automatically The SQL execution result is mapped to the Java object, and the type D of the output result is defined by the resultType in the Statement. The
above statements are not correct

6 reference answer: A

7. After using the ORM framework, the application no longer directly accesses the underlying database, but operates the persistent object (PO, that is, Persisent Object) in the way of ().
A, business-oriented
B, Hibernate
C, object-oriented
D, MyBatis

7 reference answer: C

multiple choice

8. The MappedStatement object will define the input parameters for the user to execute the SQL statement, and the type of these parameters can be ().
A, Map type
B, List type
C, basic type
D, OPJO type

8 reference answer: A,B,C,D

9. Among the following options, the correct statement about the benefits of using MyBatis programming is ().
A. You can efficiently manage database connections without configuring a data connection pool.
B. Realized the separation of SQL and Java code.
C. Automatically map SQL execution results to Java objects.
D. Automatically map Java objects to SQL statements.

9 reference answer: B,C,D

10. Which of the following statements about the advantages of using the framework is correct ( ).
A. Improve development efficiency
B. Improve code standardization and maintainability
C. Improve software performance
D. No need to expand the program

10 reference answer: A,B,C

11.
Among the following options, the correct statement about the disadvantages of traditional JDBC programming is ().
A. Frequent creation and release of database connections will waste system resources and affect system performance.
B. The statement is hard-coded, which will make the code difficult to maintain.
C. There is hard coding in using PreparedStatement to pass parameters to placeholders, which makes the system difficult to maintain.
D. JDBC has hard-coded result set parsing, which makes the system not easy to maintain.

11 reference answer: A,B,C,D

True or False

  1. A software framework will include supporting programs, compilers, code, libraries, toolsets, and APIs that bring all these components together to support the development of a project or system.

12 reference answer: yes

13. The Mapper.xml file is configured with SQL statements for operating the database, which need to be loaded in mybatis-config.xml to be executed.

13 reference answer: yes

14. A software framework is a generic, reusable software environment that provides specific functionality to facilitate the development of software applications, products, and solutions

14 reference answer: Yes

  1. The MyBatis framework can establish a mapping relationship between entity classes and SQL statements, and is a semi-automatic ORM implementation.

15 reference answer: Yes

16. The MyBatis mapping file is mainly used to realize the mapping between SQL statements and Java objects, so that the relational data queried by SQL statements can be encapsulated into Java objects.

16 reference answer: yes

17. The SQL statement for operating the database is configured in the Mapper.xml file, which needs to be loaded in mybatis-config.xml to be executed.

17 reference answer: yes

18.
If a project has multiple mapping files, the mybatis-config.xml core configuration file needs to configure multiple elements under the element to specify the path of the mapping file.

18 reference answer: yes

  1. In traditional JDBC programming, SQL changes need to change Java code, which violates the principle of opening and closing.

19 reference answer: yes

20. The element in the MyBatis mapping file is the root element of the configuration file, which contains a namespace attribute, which specifies a unique namespace for this.

Reference answer: False
[Answer Analysis]
<mapperThe > element is the root element of the configuration file

fill in the blank

  1. MyBatis creates a SqlSession object from the session factory SqlSessionFactory, which contains all the methods for executing SQL.

22. The MyBatis framework is an ORM or 对象关系映射framework.

23. The core configuration file of MyBatis can be named at will, but it is usually named after mybatis-config.xml.

24. mybatis-config.xmlThe core configuration file mainly configures information such as the operating environment of MyBatis.
25. The attribute contained in the <mapper> element namespacespecifies a unique namespace for this <mapper>.

Explanation of the elements in the homework two Mybatis framework

multiple choice

1. Among the following elements, the root element of the MyBatis configuration file is ().
A, < mappers > element
B, < dataSource > element
C, < configuration > element
D, < settings > element

1 reference answer: C

2. Among the following elements, those that are not sub-elements of the <environments> element are ().
A, <environment>
B, <dataSource>
C, <transactionManager>
D, <plugins>

2 reference answer: D

3. Regarding the result type returned by the query method of the SqlSession object, the correct one is ().
A. The Set collection of generic objects
B. The List collection of generic objects
C. The Map collection of generic objects
D. The above statements are all correct

3 reference answer: B

4. Among the following attributes, the type of the result set in the <select> element is ().

A、keyProperty
B、keyColumn
C、resultSetType
D、useGeneratedKeys

4 Reference answer: C
[Answer Analysis]
The options A, B, and D are attributes of the sum element.

5. The following statements about the <select> element and its attributes are wrong ().
A. The <select> element is used to map query statements, which can help us read data from the database and assemble the data for business developers. B. The parameterType
attribute indicates the fully qualified name or alias of the parameter class passed into the SQL statement.
C 、resultMap indicates the named reference of the external resultMap, and resultType and resultMap can be used at the same time when returning.
D、Multiple <select> elements can be configured in the same mapping file

5 Reference answer: C
[Answer analysis]
You can use one of resultType or resultMap when returning

6. Regarding the value of the statementType attribute of the <insert> element, the wrong one is ().
A, STATEMENT
B, DEFAULT (default value)
C, CALLABLE
D, PREPARED (default value)

6 reference answer: B

7. Which of the following statements about the <insert> element in the MyBatis mapping file is correct ().
A. The <insert> element is used to map the insert statement. After executing the SQL statement defined in the element, no result is returned. B. The attributes
of the <insert> element are the same as those of the <select> element.
C. The keyColumn attribute is used to set the first Several columns are primary keys. When the primary key column is not the first column in the table, you need to set
D. useGeneratedKeys (useful for insert only). This property will make MyBatis use JDBC's getGeneratedKeys() method to obtain the primary key generated internally by the database

7 Reference answer: C
[Answer analysis] option A will return the number of inserted records; options B and D, keyProperty, keyColumn, and useGeneratedKeys are only valid for <insert> and <update> elements; among them, the useGeneratedKeys attribute will Make MyBatis call JDBC's getGeneratedKeys() method to obtain the primary key generated internally by the database;

8. Which of the following statements about the <mapper> element is correct ().
A. The namespace attribute of the <mapper> element is not unique
B. The name of the namespace attribute value of the <mapper> element is not necessarily the same as the name of the interface
C. The <mapper> element is not the root element of the mapping file
D. The <mapper> element is a mapping root element of the document

8 Reference answer: D
[Answer analysis]
The <mapper> element is the root element of the mapping file. This element has only one namespace attribute (namespace), and the name of the namespace attribute value must be the same as the name of the interface.

9. The following statement about the <properties> element is wrong ().
A. <properties> is an element of configuration properties, the function of this element is to read the configuration information of external files
B, use the <property... /> element to configure the database driver, the URL to connect to the database, the user name to connect to the database and the username to connect to the database Database connection parameters such as passwords
C, <properties> elements can realize static parameter configuration through the db.properties file
D, the above statements are correct

9 Reference answer: C
[Answer analysis]
The <properties> element can realize dynamic parameter configuration through the db.properties file

10. Assuming that there is an XML file named UserMapper, the following sample code about using the class path to import the mapping file is correct ().

A. <mappers><mapper resource="com/iheima/mapper/UserMapper.xml"/></mappers>
B. <mappers><mapper resource="com/itheima/mapper/UserMapper"/></mappers>
C. <mapper resource="com/iheima/mapper/UserMapper.xml"/>
D. The above statements are not correct

10 reference answer: A

multiple choice

11. The following description about the SqlSession object is correct ().
A. SqlSession is another important object in the MyBatis framework. Its main function is to perform persistent operations. B.
Each thread should have its own instance of SqlSession, and this instance cannot be shared.
C. The instance of SqlSession is not a thread It is safe, so it is best to use it in a request or a method.
D. After using the SqlSession object, it is necessary to close it in time, usually it can be closed in the finally block

11 Reference answer: A, B, C, D

12. The statement about the <resultMap> element is correct ().
4 points
A. The main function of the <resultMap> element is to define mapping rules, cascade updates, and define type converters, etc. B.
When the columns in the data table are inconsistent with the attributes of the object, the <resultMap> element can be used at this time Process
C. <association> and <collection> in the <resultMap> element are used to process multi-table associations
D. The above statements are all correct

12 reference answer: A,B,C,D

13. The following belongs to the build() method of SqlSessionFactoryBuilder to build SqlSessionFactory objects ().
A. build(InputStream inputStream, String environment, Properties properties)
B. build(Reader reader, String environment, Properties properties)
C. build()
D. build(Configuration config)

13 reference answer: A, B, D

14. The correct statement about the <environments> element and its child elements is ().
A. In the configuration file, the <environments> element is used to configure the environment
B. One <environment> sub-element can be configured in the <environments> element, which contains the configuration information of transaction management and data source
C. <environment> The sub-element <dataSource> is used to configure the data source, and its type attribute is used to specify which data source to use
. D. Multiple data sources can be configured through the <environments> element. The MyBatis framework provides three types of data sources

14 Reference answer: A, C, D
[Answer Analysis]
The <environments> element has two sub-elements, <transactionManager> element and <daraSource> element, which represent the transaction manager and data source information of the configured operating environment respectively.

15. Among the following options, the method that can introduce mapping files through the <mappers> element is ().
A. Use the class path to import
B. Use the local file path to import
C. Use the interface class to import
D. Use the package name to import

15 reference answer: A, B, C, D

True or False

16. Like the <insert> element, after the <update> and <delete> elements are executed, they will also return an integer representing the number of affected records.

Reference answer: yes

17. The SqlSession object is a single-threaded object that performs interactive operations between the application program and the persistence layer, and its main function is to perform persistence operations.

Reference answer: yes

18. The SqlSession object is thread-unsafe.

Reference answer: yes

19. The SqlSessionFactory object is thread-safe. Once it is created, it will exist throughout the execution of the application.

Reference answer: yes

20. The sub-elements of <configuration> must be configured in the specified order, otherwise MyBatis will report an error when parsing the XML configuration file.

Reference answer: yes

21. There are three key-value related attributes in the <delete> element, namely keyProperty, keyColumn and useGeneratedKeys.

Reference answer: False
[Answer Analysis]
The three attributes keyProperty, keyColumn, and useGeneratedKeys are only valid for <insert> and <update> elements.

22. The poolMaximumActiveConnections property of the POOLED data source, the default value is 1.

Reference answer: False
[Answer analysis]
The poolMaximumActiveConnections attribute indicates the number of active (that is, in use) connections that can exist at any time, and the default value is 10.

23. The <mappers> element is the root element of the mapping file, which has only one namespace attribute.

Reference answer: False
[Answer Analysis]
The <mapper> element is the root element of the mapping file.

24. The parameterType attribute of the <delete> element is an optional attribute, and the default value is unset.

Reference answer: yes

25. When the parameter of the openSession() method of the SqlSessionFactory object is a boolean value, the default is false.

Reference answer: False
[Answer analysis]
When the parameter of the openSession() method of the SqlSessionFactory object is a boolean value, if true is passed in, transaction control is turned off and submitted automatically; if false is passed in, transaction control is turned on. If no parameters are passed in, the default is true.

Homework three Mybatis framework

multiple choice

1. Among the following attributes, the ones that do not belong to the <association> element attribute are ().
A, property
B, select
C, ofType
D, autoMapping

Reference answer: C

2. The following statement about the commonly used attributes in the <association> element is wrong ().
A. property specifies the attribute of the entity class object that is mapped to, and corresponds to the table field one by one.
B. column specifies the corresponding field in the table.
C. fetchType specifies whether to enable lazy loading during associated queries. The default value is eager
D. javaType specifies the mapping to Types of Entity Object Properties

Reference answer: C
[Answer analysis]
The fetchType attribute has two attribute values, lazy and eager, and the default value is lazy (that is, the default associated mapping delay loading).

3. Which of the following descriptions about the <collection> element is correct ().
A. MyBatis handles the one-to-many relationship through the <collection> element.
B. The attribute of the element is exactly the same as that of the <association> element.
C. The ofType attribute corresponds to the javaType attribute, which is used to specify the attributes contained in all the attributes in the entity object. Element type
D, element can only use the nested query method

Reference answer: A
[Answer Analysis]
Most of the attributes of the <collection> element are the same as those of the <association> element, but it also contains a special attribute ofType. The ofType attribute corresponds to the javaType attribute, and it is used to specify the type of elements contained in the collection class attribute in the entity class object. The <collection> element is also a child element of the <resultMap> element, and it also has two configuration methods: nested query and nested result.

4. Which of the following statements about the way of loading association relationship objects in the MyBatis mapping file is correct ().
A. Nested results refer to returning the expected complex type by executing another SQL mapping statement.
B. Nested results use nested result mapping to process a subset of repeated union results.
C. Nested queries use nested results Mapping to handle repeated subsets of joint results
D, the above statements are correct

Reference answer: B

multiple choice

5. Among the following attributes, the attributes shared by <association> and <collection> elements are ().
A, property
B, select
C, ofType
D, autoMapping

Reference answer: A, B, D
[Answer Analysis]
The C option is a unique attribute of the <collection> element.

True or False

6. In MyBatis, the one-to-many relationship can be handled through the <association> element.

Reference answer: False
[Answer Analysis]
deals with a one-to-one relationship.

7. The <association> element has only one configuration method, which is the nested result method.

Reference answer: False
[Answer analysis]
The use of the <association> element is very simple. It has two configuration methods, nested query method and nested result method.

8. When the column name in the table is exactly the same as the attribute name of the corresponding object, the resultMap attribute may not be used in the query mapping file.

Reference answer: yes

9. In MyBatis, lazy loading is enabled by default.

Reference answer: False
[Answer analysis]
MyBatis does not enable lazy loading by default, and it needs to be configured in the <settings> element in the core configuration file mybatis-config.xml.

10. Many-to-many association mapping in MyBatis also has two association methods: nested query and nested result.

Reference answer: yes

fill in the blank

Note that the fill-in-the-blank question here is weird: the answer is given this, but the score is 0, like this.

insert image description here

11. In MyBatis, <collection>elements can be used to handle one-to-many relationships.
12. In MyBatis, <association>one-to-one associations can be handled through elements.
13. selectThe attribute of the <association> element is used to specify the sub-SQL statement that introduces the nested query.
14. When using the <association> element, its fetchType attribute has lazytwo attribute values, eager and eager.
15. Among the attributes of the <collection> element, it is used to specify the element type contained in the collection class attribute in the entity class object ofType.

Homework 4 Spring Framework

multiple choice

1. In the following AOP terminology, ( ) is used to indicate the intersection of the cut surface and the connection point.
A. Joinpoint
B. Pointcut
C. Aspect
D. Advice

Reference answer: B
[Answer analysis]
When a connection point meets the pre-specified conditions, AOP can locate the connection point, insert an aspect at the connection point, and the connection point becomes an entry point.

2. Which of the following statements about dependency injection is wrong ().
A. Dependency Injection (DI) and Inversion of Control (IoC) have different meanings and describe different concepts.
B. In the traditional mode, the caller usually uses the "new callee" code method to create objects. It will lead to an increase in the coupling between the caller and the callee, which is not conducive to the upgrade and maintenance of later projects.
C. After using the Spring framework, the control right is transferred from the application code to the Spring container, and the control right is reversed. This is Spring's inversion of control
D. From the perspective of the Spring container, the Spring container is responsible for assigning the dependent object to the member variable of the caller, which is equivalent to injecting a dependent instance for the caller. This is Spring's dependency injection

Reference answer: A
[Answer Analysis]
Dependency Injection (DI) and Inversion of Control (IoC) describe the same thing from different angles. Dependency injection is described from the perspective of the application, that is, the application relies on the IoC container to create and inject the external resources it needs; and the inversion of control is described from the perspective of the IoC container, that is, the IoC container controls the application, and the IoC container reverses the Inject the external resources required by the application into the application in a timely manner.

3. Among the following options, the wrong statement about the attributes in the <bean> element is ( ).
A. The id attribute is the unique identifier of the <bean> element.
B. The name attribute can specify a name for the Bean. Only one name can be specified.
C. The class attribute can specify the specific implementation class of the Bean
. D. The scope attribute is used to set the bean instance Scope of action

Reference answer: B
[Answer Analysis]
The commonly used attributes in the <bean> element include:
id attribute: the unique identifier of the <bean> element. The configuration and management of the Bean by the Spring container is completed through the id attribute. When assembling the Bean, it also needs to be based on The id value gets the object.
name attribute: Multiple names can be specified for the Bean, and each name is separated by a comma or a semicolon.
class attribute: You can specify the specific implementation class of the Bean, and its attribute value is the full path of the class to which the object belongs.
scope attribute: used to set the scope of the Bean instance, its attribute values ​​are: singleton (singleton), prototype (prototype), request, session and global session.

4. The Spring container supports various forms of Bean assembly methods, the error is ().
A. XML-based assembly
B. Properties-based assembly
C. Annotation-based assembly
D. Automatic assembly

Reference answer: B
[Answer analysis]
Bean assembly methods include: XML-based assembly, annotation-based assembly, and automatic assembly.

5. The following introduction about Spring AOP is wrong ( ).
A. The full name of AOP is Aspect-Oriented Programming, that is, aspect-oriented programming.
B. AOP adopts a horizontal isolation mechanism to extract the repeated code scattered in each method. This method of using a horizontal isolation mechanism cannot be done with OOP thinking C. Although
AOP is a new programming idea, it adopts a horizontal extraction mechanism and is an upgrade substitute for OOP. D.
The use of AOP not only improves development efficiency, but also enhances code maintainability

Reference answer: C
[Answer analysis]
AOP is a new programming idea, but it is not a substitute for OOP, it is just an extension and supplement of OOP.

6. Among the following options, the statement about the transaction management method is wrong ( ).
A. Transaction management in Spring is divided into two ways: one is traditional programmatic transaction management, and the other is declarative transaction management
. Transaction management implemented by code, including defining transaction start, transaction commit after normal execution, and transaction rollback when
abnormal AOP technology implants the "aspect" code of transaction management into the business target class
D. The biggest advantage of declarative transaction management is that developers do not need to manage transactions through programming, but only need to declare relevant transaction rules in configuration files , you can apply transaction rules to business logic

Reference answer: B
[Answer analysis]
Programmatic transaction management: transaction management implemented by writing code, including defining the start of a transaction, transaction submission after normal execution, and transaction rollback when an exception occurs. (without AOP)

7. <bean id="user" class="com.itheima.User"> <constructor-arg name="id" value="1"></constructor-arg> <constructor-arg name="name" value ="Zhang San"></constructor-arg> <constructor-arg name="password" value="123"></constructor-arg> </bean> Regarding the above code segment, the following options describe the error ( ).
A. The <bean> element instantiates the entity class
B. The class attribute in the <bean> element specifies the relative path class name to be instantiated
C. The <constructor-arg> element assigns values ​​to the attributes in the entity class
D. <constructor-arg The name attribute in the element specifies the parameter

Reference answer: B
[Answer analysis]
The <bean> element instantiates the entity class.
The class attribute in the <bean> element specifies the full path class name to be instantiated.
The <constructor-arg> element assigns values ​​to the attributes in the entity class.
<constructor-arg The name attribute in the element specifies the parameter

8. Among the following options, the one used for notification/enhanced processing is ( ).
A. Joinpoint
B. Pointcut
C. Aspect
D. Advice

Reference answer: D
[Answer analysis]
Notification/enhancement processing is the inserted aspect program code. Notification/enhancement processing can be understood as a method in an aspect, which is the specific implementation of an aspect.

9. Among the following options, the <property> element statement is wrong ( ).
A. The name attribute specifies the member variable name of the class.
B. The vlaue attribute provides the corresponding member variable injection value.
C. The <property> element is a child element of the <bean> element.
D. The ref attribute indicates the member of a Bean instance in the Spring IoC container variable reference

Reference answer: D
[Answer analysis]
The name attribute in the <property> element specifies the name of the corresponding property in the Bean instance, and the value of the name attribute can be specified through the ref attribute or the value attribute. When using the ref attribute, it represents a reference to a Bean instance in the Spring IoC container. Apply to the entire bean

10. The default scope of the Spring container is ( ).
A, prototype
B, request
C, session
D, singleton

Reference answer: D
[Answer analysis]
singleton is the default scope of the Spring container. When the scope of the Bean is singleton, the Spring container only creates one instance for the Bean, which can be reused.

11. The following statement about the prototype scope of Bean is wrong ().
A. prototype is the default scope of the Spring container
. B. When using the prototype scope, the Spring container is only responsible for creating Bean instances and no longer manages its life cycle.
C. When using the prototype scope, the Spring container will be responsible for each Bean requests create a new instance
D. To define a Bean as a prototype scope, just set the scope attribute value of the <bean> element to prototype in the configuration file.

Reference answer: A
[Answer analysis]
singleton is the default scope of the Spring container. The prototype-scoped bean creates a new bean instance every time the bean is requested, and the Spring container is only responsible for creating the bean instance and no longer manages its life cycle.
The scope attribute is used to set the scope of the Bean instance, and its attribute values ​​are: singleton (singleton), prototype (prototype), request, session and global session.

multiple choice

12. Which of the following statements about dependency injection is correct ().
A. Dependency Injection (DI) and Inversion of Control (IoC) have the same meaning, but these two names describe the same concept from two perspectives B. In the traditional mode, the caller usually uses "new to be
called The "code" method to create objects, this method will increase the coupling between the caller and the callee, which is not conducive to the upgrade and maintenance of later projects. C. After using the Spring framework, the control right is transferred from the application code to
the In the Spring container, the right of control has been reversed, which is Spring’s inversion of control
D. From the perspective of the Spring container, the Spring container is responsible for assigning the dependent object to the member variable of the caller, which is equivalent to injecting dependencies for the caller. An example, this is Spring's dependency injection

Reference answer: A, B, C, D
[Answer Analysis]
Dependency Injection (DI) and Inversion of Control (IoC) describe the same thing from different angles. Dependency injection is described from the perspective of the application, that is, the application relies on the IoC container to create and inject the external resources it needs; and the inversion of control is described from the perspective of the IoC container, that is, the IoC container controls the application, and the IoC container reverses the Inject the external resources required by the application into the application in a timely manner.
After using the Spring framework, the instance of the object is no longer created by the caller, but by the Spring container. The Spring container will be responsible for controlling the relationship between programs, rather than being directly controlled by the caller's program code. In this way, the right of control is transferred from the application code to the Spring container, and the right of control is reversed, which is Spring's inversion of control.
From the perspective of the Spring container, the Spring container is responsible for assigning the dependent object to the member variable of the caller, which is equivalent to injecting the instance it depends on for the caller, which is Spring's dependency injection.

13. The Spring container supports various forms of Bean assembly methods, the following options include ().
A. XML-based assembly
B. Properties-based assembly
C. Annotation-based assembly
D. Automatic assembly

Reference answer: A, C, D
[Answer analysis]
Bean assembly methods include: XML-based assembly, annotation-based assembly, and automatic assembly.

14. Among the following options, the description about transaction management method is correct ( ).
A. Transaction management in Spring is divided into two ways: one is traditional programmatic transaction management, and the other is declarative transaction management
B. Programmatic transaction management: transaction management implemented by writing code, including defining transaction Start, transaction commit after normal execution and transaction rollback when abnormal
C, declarative transaction management: the main idea is to write transaction management as a "aspect" code separately, and then use AOP technology to write the "aspect" code of transaction management Implanted into the business target class
D. The biggest advantage of declarative transaction management is that developers do not need to manage transactions through programming. They only need to declare relevant transaction rules in the configuration file to apply transaction rules to business logic. middle

Reference answer: A, B, C, D
[Answer analysis]
There are two ways of transaction management in Spring: one is traditional programmatic transaction management, and the other is declarative transaction management.
Programmatic transaction management: transaction management implemented by writing code, including defining the start of a transaction, transaction submission after normal execution, and transaction rollback when an exception occurs.
Declarative transaction management: The main idea is to write transaction management as a "aspect" code separately, and then implant the "aspect" code of transaction management into the business target class through AOP technology.
The biggest advantage of declarative transaction management is that developers do not need to manage transactions through programming. They only need to declare relevant transaction rules in the configuration file to apply transaction rules to business logic.

15. Which of the following statements about the singleton scope of Bean is correct ( ).
A. Singleton is the default scope of the Spring container
. B. When the scope of the Bean is singleton, there will only be one shared Bean instance in the Spring container.
C. The singleton scope can avoid resource consumption caused by repeated creation and destruction of instances
. D. The scope of a bean is specified by the scope attribute of the <bean> element, which has 5 values, corresponding to 5 scopes

Reference answer: A, B, C, D
[Answer analysis]
singleton is the default scope of the Spring container. When the scope of the Bean is singleton, the Spring container only creates one instance for the Bean, which can be reused. The Spring container manages the life cycle of the Bean, including the creation, initialization, and destruction of the Bean. Because creating and destroying Bean instances will bring a certain amount of system overhead, the singleton scope can avoid resource consumption caused by repeated creation and destruction of instances.
The scope attribute is used to set the scope of the Bean instance, and its attribute values ​​are: singleton (singleton), prototype (prototype), request, session and global session.

16. Among the following options, the description of Spring AOP is correct ( ).
A. The full name of AOP is Aspect-Oriented Programming, that is, aspect-oriented programming.
B. AOP adopts a horizontal isolation mechanism to extract the repeated code scattered in each method. This method of using a horizontal isolation mechanism cannot be done with OOP thinking C.
AOP is an upgraded replacement for OOP
D. The use of AOP not only improves development efficiency, but also enhances code maintainability

Reference answer: A, B, D
[Answer analysis]
AOP is a new programming idea, but it is not a substitute for OOP, it is just an extension and supplement of OOP.

17. Which of the following statements about Bean's prototype scope is correct ().
A. prototype is the default scope of the Spring container
. B. When using the prototype scope, the Spring container is only responsible for creating Bean instances and no longer manages its life cycle.
C. When using the prototype scope, the Spring container will be responsible for each Bean requests create a new instance
D. To define a Bean as a prototype scope, just set the scope attribute value of the <bean> element to prototype in the configuration file.

Reference answer: B, C, D
[Answer analysis]
singleton is the default scope of the Spring container. The prototype-scoped bean creates a new bean instance every time the bean is requested, and the Spring container is only responsible for creating the bean instance and no longer manages its life cycle.
The scope attribute is used to set the scope of the Bean instance, and its attribute values ​​are: singleton (singleton), prototype (prototype), request, session and global session.

18. <bean id="user1" class="com.itheima.User1"> <property name="id" value="2"></property> <property name="name" value="Li Si"> </property> <property name="password" value="456"></property> </bean> Regarding the above code segment, the correct description of the following options is ().
A. The <bean> element instantiates the entity class
B. The class attribute in the <bean> element specifies the full path class name to be instantiated
C. The <property> element assigns values ​​to the attributes in the entity class
D. The <property> element in the element The name attribute specifies the parameter

Reference answer: A, B, C, D
【Answer Analysis】
The <bean> element instantiates the entity class.
The class attribute in the <bean> element specifies the full path class name to be instantiated.
The <property> element assigns values ​​to the attributes in the entity class.
The name attribute in the <property> element specifies the parameter

19. Among the following options, the description of Spring AOP terms is correct ( ).
A. Aspect: An aspect refers to a class formed by concerns (referring to repeated code in a class), and usually refers to a functional class that is encapsulated and used for horizontal insertion into the system.
B. Joinpoint: A connection point is a specific node in the program execution process.
C. Pointcut: When a connection point meets a pre-specified condition, AOP can locate the connection point and insert an aspect at the connection point. The point becomes the entry point.
D. Target: The target object refers to the method that is inserted into the aspect.

Reference answer: A, B, C, D

True or False

20. In AOP terminology, aspect refers to which Joinpoints to intercept.

Reference answer: False
[Answer analysis]
An aspect refers to a class formed by a concern (a concern refers to the repeated code in a class), and usually refers to a functional class that is encapsulated and used for horizontal insertion into the system (such as transaction management, logging, etc. ).

21. There are two ways of transaction management in Spring, one is traditional programmatic transaction management, and the other is declarative transaction management.

Reference answer: yes

22. The full name of AOP is Aspect-Oriented Programming, which is aspect-oriented programming.

Reference answer: yes

23. Dependency Injection (DI) and Inversion of Control (IoC) have different meanings, and they do not describe the same concept.

Reference answer: Wrong
[Answer Analysis] Dependency Injection (DI) and Inversion of Control (IoC) describe the same thing from different angles. Dependency injection is described from the perspective of the application, that is, the application relies on the IoC container to create and inject the external resources it needs; and the inversion of control is described from the perspective of the IoC container, that is, the IoC container controls the application, and the IoC container reverses the Inject the external resources required by the application into the application in a timely manner.

24. The Spring container supports configuration files in XML and Properties formats. In actual development, the most commonly used configuration method is the Properties format.

Reference answer: False
[Answer analysis] The Spring container supports configuration files in both XML and Properties formats. In actual development, the most commonly used configuration files are in XML format.

25. Spring provides three XML-based assembly methods: set value injection, attribute setter method injection and construction method injection.

Reference answer: False
[Answer analysis]
XML-based assembly is to read the information in the XML configuration file to complete dependency injection. The Spring container provides two XML-based assembly methods, property setter method injection and construction method injection.

Homework five Spring MVC framework

multiple choice

1. When the user sends a request to the server through the browser, it is () that is responsible for intercepting the user request.
A, processor
B, processor mapper
C, front-end controller
D, processor adapter

Reference answer: C
[Answer analysis]
The processor will return the ModelAndView object; the processor mapper will generate the processor object and the processor interceptor (if any); the processor adapter will return the ModelAndView object to the DispatcherServlet front controller;

2. The following statements about the characteristics of Spring MVC are wrong ( ).
A. Strong flexibility, but not easy to integrate with other frameworks
B. Can automatically bind user input, and can correctly convert data types
C. Support internationalization
D. Use XML-based configuration files, after compilation, do not need to reinstall Compile the application

Reference answer: A
[Answer analysis]
Spring MVC is flexible, easy to expand, and easy to integrate with other frameworks.

3. Which of the following options is the back-end controller of Spring MVC ().
A. HandlerMapping
B. HandlerAdapter
C. DispatcherServlet
D. Handler

Reference answer: D
[Answer analysis]
HandlerMapping is the processor mapper; HandlerAdapter is the processor adapter; DispatcherServlet is the front controller;

4. In the @PathVariable annotation, ( ) is used to specify the name of the placeholder in the URL.
A, defaultValue
B, value
C, name
D, required

Reference answer: B
[Answer Analysis]
The @PathVariable
annotation has the following two common attributes. :
 value: used to specify the name of the placeholder in the URL.
 required: whether to provide a placeholder, the default value is true.

5. For the following options, the description of POJO type data binding is wrong ( ).
A. Encapsulate the associated request parameters in a POJO
B. Use the POJO directly in the method as a formal parameter to complete data binding
C. The parameter name requested by the client does not need to be consistent with the attribute name in the POJO type to be bound
D. The parameter name requested by the client must be consistent with the attribute name in the POJO type to be bound

Reference answer: C
[Answer analysis]
When performing POJO type data binding, the parameter name requested by the client must be consistent with the attribute name in the POJO type to be bound. In this way, when the client sends a request, the request data will be automatically bound to the processor parameter POJO object, otherwise the value received by the processor parameter is null.

6. The following statement about the execution process of Spring MVC is wrong ().
A. The user sends a request to the server through the browser, and the request will be intercepted by the DispatcherServlet front controller.
B. The processor mapper will generate a processor object and the processor interceptor will return it to the DispatcherServlet front controller
. C. The processor adapter will call and Execute the code in the Controller class
D. After the code in the Controller class is executed, the ModelAndView object will be returned, which only contains the view name

Reference answer: D
[Answer analysis]
The ModelAndView object will contain the view name or the model and view name.

multiple choice

7. Which of the following statements about the role of the three-tier architecture developed by Java EE is correct ( ).
A. The presentation layer is responsible for receiving the client's request and responding to the client.
B. The business layer is responsible for business logic processing, which is closely related to the project requirements.
C. The persistence layer is responsible for interacting with the database and adding, deleting, modifying and checking the data in the database.
D. The above statement all correct

Reference answer: A, B, C, D

8. Among the following types, the simple data types that Spring MVC can bind are ( ).
A, Integer
B, String
C, Double
D, List

Reference answer: A, B, C
[Answer analysis]
The binding of simple data types refers to the data binding of basic types in Java (such as Integer, Double, String, etc.).

9. The annotation @RequestMapping can be marked in ( ).
A, on the class
B, on the method
C, on the property
D, all of the above are acceptable

Reference answer: A, B
[Answer Analysis]
The @RequestMapping annotation is used to establish the mapping relationship between the request URL and the Handler (processor). This annotation can be marked on the method and class.

10. Among the following options, the one that belongs to the characteristics of the Spring MVC framework is ( ).
A. Spring MVC is a follow-up product of the Spring framework, which can easily use other functions provided by the Spring framework. B.
Spring MVC supports mapping strategies for various request resources
. C. Spring MVC supports multiple view technologies, including JSP, Velocity and FreeMarker Equal view technology
D. Spring MVC supports internationalization and can display multiple languages ​​according to the user's region

Reference answer: A, B, C, D

11. The following attributes of the @RequestParam annotation are correct ( ).
A. If the current @RequestParam annotation only uses the vaule attribute, the value attribute name can be omitted.
B. The name attribute indicates the name of the bound request parameter.
C. The default value of the required attribute is true, indicating that there must be a corresponding parameter in the request.
D. defaultValue The attribute indicates the default value if there is no parameter with the same name in the request

Reference answer: A, B, C, D

12. Among the following options, the view technologies supported by the Spring MVC framework include ( ).
A, JSP
B, Velocity
C, FreeMarker
D, the above statement is not correct

Reference answer: A, B, C

True or False

13. Spring MVC is a web framework, which is based on Servlet API and belongs to a module in Spring. The official name is Spring Web MVC, but it is usually called Spring MVC.

Reference answer: yes

14. Spring MVC supports a variety of view technologies, including JSP, Velocity and FreeMarker.

Reference answer: yes

15. The @RequestMapping annotation can only be marked on the method.

Reference answer: False
[Answer Analysis]
The @RequestMapping annotation is used to establish the mapping relationship between the request URL and the Handler (processor). This annotation can be marked on the method and class.

16. In the @PathVariable annotation, the required attribute indicates whether a placeholder must be provided, and its default value is true.

Reference answer: yes

17. For simple type data binding in Spring MVC, only the name of the client request parameter is consistent with the name of the formal parameter of the processor, and the request parameter will be automatically mapped and matched to the formal parameter of the processor to complete the data binding .

Reference answer: yes

18. After Spring 4.0, the processor mapper, processor adapter and view resolver must be configured in the configuration file.

Reference answer: False
[Answer analysis]
After Spring 4.0, if the processor mapper, processor adapter and view resolver are not configured, the framework will load the internal default configuration to complete the corresponding work. Understand a little, the more updated the more convenient, this is called good body feeling.

19. The process of encapsulating all associated request parameters in a POJO, and then directly using the POJO as a formal parameter in the method to complete the data binding is called POJO type data binding.

Reference answer: yes

20. In Spring MVC, if you want to explicitly configure the processor mapper and processor adapter, you can use the <mvc:annotation-driven> element in the configuration file to achieve.

Reference answer: yes

21. Spring MVC provides comprehensive support for the MVC pattern, which can decouple the presentation layer. At the same time, Spring MVC is a request-driven framework based on the request-response processing model, which simplifies the implementation of the presentation layer.

Reference answer: yes

22. When binding complex POJO data, if the data needs to be bound to the properties of the POJO property object, the format of the parameter name requested by the client must be "property object name.property".

Reference answer: yes

23. If there is no view resolver in the Spring MVC configuration file, request forwarding will not be performed.

Reference answer: False
[Answer analysis]
If there is no view resolver in the Spring MVC configuration file, after the processor is executed, the request will be forwarded to the mapping path consistent with the return value of the method.

24. During the execution of Spring MVC, the work of the front controller, processor mapper, processor adapter and view resolver objects are all performed inside the framework.

Reference answer: yes

25. The required attribute of the @RequestParam annotation is used to specify whether the parameter is required, and its default value is false.

Reference answer: wrong

Guess you like

Origin blog.csdn.net/qq_51294669/article/details/131144408