Face questions about the spring MVC

MVC design pattern

M model model

business model including service logic processing, entity encapsulated data entity class, dao database operation, utils tools

service business logic layer is mainly used to treat some common processing service layer may be used to complete the framework AOP spring, for example, log information, processing things

Spring is a framework that combines an enterprise-class solutions in a variety of excellent java design patterns formed

IOC : Inversion of Control, create and assign attributes to the object of the Spring framework is completed, the control by the programmer to the Spring framework that's inversion of control, IOC is the main use of Java in the factory design pattern, to be created Spring class object to the factory, the factory directly to fetch needed

DI: same IOC essentially different versions and DI, DI dependency injection, or a method set by the constructor for class attribute property assignment

AOP: Aspect Oriented Programming, OOP is a complement to object-oriented programming, Java is the main use of design patterns in the proxy, the proxy design pattern is divided into static and dynamic agent Proxy

The difference between static and dynamic proxy agent: static proxy in the proxy class code is compiled to generate a dynamic proxy that will be generated proxy class in your code run, run in the bottom of the JDK dynamically generated proxy class, and create a proxy object

Spring transaction: the transaction by the Spring Framework's declarative transaction processing is complete

Spring Framework to create a number of times to create an object :

Bean scope attribute labels can set the number of objects created, it will only create a singleton singleton is when the object once again to create a new object is an object prototype multi-instance of each plant will use Spring.

Spring Framework to create an object life cycle

Life cycle: an object from creation to destruction process, when the scope attribute when Spring plant start-up will create an object is singleton, if the Scope attribute prototype, when the need to use every time a new object is created, not Spring will then create an object when the factory started. Then the object is invoked automatically when creating the methods init-method property specified in the Bean tab, the object will call the method specified in the destroy-method property in Spring factory is destroyed, if it is multi-instance object will not help Spring framework destroy method does not call the destroy-method of garbage collection will be destroyed by the JDK

Dao layer: for data mapping, the database operation, the database stores objects DataAccessObject

JDBC jdbc java is a set of specifications provided by a set of interfaces, the specific implementation is responsible for the database vendor

JDBC-step development, 1. Driver loading, 2. create a link, 3. Sql written statement, 4. create objects, 5 Executive, 6. release resources

Whether setAutoCommit set automatically submit the transaction, commit commit the transaction, rollback roll back the transaction

Mybatis framework

MyBatis is a persistence framework, ORM framework, the framework is a semi-automatic ORM, additions and deletions can be done to change the database search operation, the JDBC package, eliminating almost all MyBatis JDBC code to solve the problem of redundant operation JDBC database

ORM framework, ORM object relation mapping, mapping object database, the database results storage to Java entity class object, which is the data mapping

The SqlSession equivalent of Connetcion JDBC object, that is to obtain a database link, Sqlsesion objects can help us complete the database operational tasks, SqlSession is a session between the Java and database operations, HttpSession is a session between the browser and server

When the property name is inconsistent in the database field names and entity class, Mybatis problem arises map data, JDBC technology will not produce such a problem

Aliases can be played with over the results of queries the database to solve,

You can use the tag to do data mapping resultMap

Using the association tag to the object type of entity class attribute assignment many-

Collection using tags assigned to many of the entity class attribute list set type

Dynamic Sql

where If the label conditional, multi-criteria query

foreach loop stitching tag sql statement to bulk delete

item variable name casually written

Data type objects collection cycle, List list array is set for the array type @Param If the annotation, the annotation name places the contents of the main recirculation open before splicing, splicing intermediate Separator each cycle the contents, the end of close loop after splicing the content database Dao layer is mainly used to operate the database

Classification database

Mesh type, hierarchical, relational, mainstream databases are relational databases: MySql, Oracle, SqlServer, sybase. Nosql non-relational databases: Mongodb, redis, these are database management system, each database management system that brings multiple databases

Oracle Database

Oracle database, MySql databases, Java computer language are part of Oracle Corporation

Oracle Database Links

You need to install the database client tools, and ensure the normal operation of Oracle Database

Sql script

Sql is not a database, Sql is a structured language, a language he is to operate the database

Oracle use string concatenation ||

dual dumb table

sysdateOracle get the current system time

Oracle in the function

The method is similar to the java incoming number of arguments, the function returns a number of run End Results

Each row of data run-way function returns a result Ends

length () Returns the length of the string argument

mod () seeking remainder

TO_DATE () to convert a string type to date

TO_CHAR () to convert strings of other types of data as

Group functions: data which is assigned to several groups, the query result will be a few lines of data, the general set of functions is used and a query packet, when a group of functions, no group data in the table, the table shows a assigned to a data group which

Min max min avg average maximum sum count sum total number of rows

Can not select back with the other fields, the use of group function, automatically excludes null value when using statistical data set of functions

Each dummy Oracle table has columns and Rownum RowId

When you link to check the results requires more than one data table, this time behind the form may be followed by more than one table, such a query on the query link

Left links left join the table to the left and right main link right join table to the right of the main table full link epitope [outer] join two tables are linked in the main table inner join two tables are linked from the table since connect your own, two tables are the same fields in a table the type Oracle Varchar2 () variable-length string Char () fixed length character string number (m, n) m is the total length of the figures, n is represented by several decimal integer double type is not recommended date date date type Clob store large binary files store text type Blob

constraint

Primary key constraint primary key is the primary key for each row of data unique biao'ji table must have a primary key value of the primary key is not repeated

A table can have only one primary key primary key is associated with the entire life cycle of the entity, the value of the primary key of the entire life cycle can not change can not be null

The only unique constraint constraint constraint unipue unique value of the field can not duplicate primary key constraint is a special

His value can be changed value can be null

Non-empty constraint not null

Non-null field values ​​can not be null

Foreign key constraint references

Top-righteousness check (constraints)

Delete table and modify table structure

Delete table drop table table name

Modify table structure alter table modify table name field name field type

Add a field to the table alter table add constraint field name field type

Constraints delete the table alter table table name drop constraints constraint name

Classification Sql script

dql database query language

ddl database definition language

dml database manipulation language

tcl Transaction Control Language

Sequence sequence

When a lot of data in the table, we do not know the primary key to a few, in order to better control the primary key generation method, we can use the sequence

create sequence sequence names start with the start value

View view

Usually we will often use some complex sql scripts that long, inconvenient to write. We want to be treated again based on the results of these scripts. This is what we can now view this sql statement completion, to facilitate our future operations.

create view view name as sql statement

View can not improve operating efficiency

Index index

When a large amount of data in the database, the efficiency of retrieving data is affected, which is the index can improve the efficiency of retrieving data

Principle: Similar to catalog dictionary, can quickly locate the corresponding text according to the directory. The index is a database object is independent of the table

The index will improve data retrieval efficiency, and reduces the efficiency of additions and deletions

create index index name on show (field names)

MySql database

MySql database is a relational database, Oracle Database and Oracle are belong to the company

Mysql and Oracle difference

Oracle database is a large, free products, service charges, Oracle does not support batch add, support sequences, sql support || stitching, Oracle storage structure is particularly complex

Mysql is a small database, open source is free, and add support for bulk, Mysql support self-growth, function can be provided by virtue of sql Mysql

Redis database

RDB relational database Oracle Mysql

NoSql non-relational database Redis

Nosql features:

Weakened structure

Based on memory, to store data in memory, support for automatic persistence

Weakening Affairs

Based cluster environment

No complicated queries link

Js scripting language support

Redis based memory to the key-value stored data to support network transmission, automatic persistence support, is a non-relational database

Jedis Java is a link to a tool provided by Redis database redis

Entity Entity class

The main role of the entity class used to store data

V view view

Mainly used to display data and accept data entered by the user, it will submit the data to the background

HTML HTML, used to display static pages, dynamic pages can not be achieved

CSS can beautify HTML pages, HTML responsible for the content, CSS is responsible for style

JSP

JSP is a special Servlet, for dynamic page

Jsp implementation process

When a browser client's first visit to a jsp page, the server will translate into a javaServlet jsp class, then the class is compiled into .class files, the class file is executed, the whole process again accept the first jsp when a request for execution, subsequent requests, tomcat will automatically go to the implementation class file, rather than be translated and compiled

Jsp nine built-in objects

request

response

out

session

application ServletContext is encapsulation of the entire web.xml

config ServletConfig package for the object is a servlet configuration item

Exception exception information objects. If the current page is an error page, you can use the built-in object. Exception information can be obtained through the built-in objects

The object is the target this page

pageContext is a scope, the scope corresponds to a page, with a very small, can be acquired by the other eight built-in objects of the object, can operate other scopes

Jsp scope

pageScope,requestScope,sessionScope,applicationScope

EL expression

Expression language, you can get inside the scope of data, variable expressions el get to do some calculations

Scope .key} {$

EL expression can obtain data directly stored inside Cookie

EL expression can be obtained by the passed parameter request param

JSTL El expression is powerful, but do not control the process. You can use JSTL expressions and El combine to make up for this deficiency

JSTL jsp Standard Tag Library, the control flow can be done, and the EL expressions used in combination

JavaScript a scripting language,

Front-end programming languages ​​and HTML, CSS similar are interpreted by the browser execution, JavaScript is mainly used to achieve dynamic page

JavaScript is a weakly typed language, there is no variable type, value typed

event

Interactivity in the browser is event-driven. Events are built by the browser when the user operates the browser may have a built-in trigger event. When the browser to listen to the user triggers an event when a , it will call the developer (programmer) ahead of time to write a good function.

Click event onClick

Move the mouse events onmouseover

Onmouseout mouse out events

Input box gets focus onfocus event

Input box loses focus onblur event

Form submission event onsubmit

Content is changed onchange event

Page loaded onload event

DOM manipulation

When the page is loaded, the browser will create a document object model document object model of the page

BOM operation

JQuery

jQuery is a JavaScript library, jQuery greatly simplifies JavaScript programming. jQuery design aim is "writeLess, Do More", that is advocated write less code, do more things. It encapsulates the JavaScript code for commonly used functions, provide a simple JavaScript design patterns to optimize HTML document manipulation, event handling, animating and Ajax interactions design. jQuery compatible with all major browsers.

AJAX

No refresh request, do not refresh the page receives the request, and receive back a response content

AJAX-core programming language is JavaScript, AJAX technology and will use DOM CSS, AJAX by strings, JSON, xml for data transmission

AJAX implementation process

Create XMLHttpRequest object, depending on how different browsers create different

Establish a link, link is established through the open method

Transmission request, a transmission request by the send method

XMLhttpRequest monitoring state of the object, when the ready state is 4, the response status code 200, acquires the content in response to the background

EasyUI

EasyUI results page can be done, can be done by interaction ajax background and automatically parse the response content back to back, a front-end frame is further based on the package formed JQuery

Three elements EasyUI controls

Attribute is used to effect control of the control feature

When the method of behavior, functional body, and then need a certain function, call the corresponding discharge method

Events need to bind a function, call the function when it reaches the timing of the trigger event

C controller controller

Servlet

After we put into the html tomcat, these pages can be accessed through a browser. But these pages are static and do not change the content. Anyone, any time to see the content is the same.

Servlet is possible to generate dynamic html source. Servlet is a special java class, he was running on the server.

Servlet class should extend HttpServlet class

Each Servlet class needs to be configured by the tag servlet in web.xml

Package information request HttpServletRequest

HttpServletResponse response to encapsulated information

Servlet life cycle of a process to destroy the object is created when the first client sends a request to access a servlet, the server will create a servlet object, and call the init method, create a servlet is only a single case, every request this type of service servlet method will execute when the server stops, servlet objects are destroyed out before the execution will destroy destroy method

servlet request method 1.url 2. hyperlink address access method 3.form form submission

The difference between HTML pages and Servlet

Servlet is to achieve dynamic results page, html page is to achieve a static effect.

The effect is a dynamic page: page different people at different times access is not the same.

The effect is a static page: page effect all the people all the time to visit is the same.

Forwarded

After running a servlet when the need to request additional resource files, which can be used when forwarding

Forward: two resource file corresponding to a response to a request. Forwarding server porting effect. The browser is imperceptible, the browser address bar will not change

Request scope

When the request is forwarded from one action to a jsp time, if you want to use jsp action class variables, then we need to put into action the variables in the request scope to pass jsp. So you can get to the jsp the variable scope by request

Request scope features

Put data servlet and servlet must ensure that access to data using the same request object. Once the request object has changed, so, request a scope which values ​​will fail.

Method property Form Form

Submitting get way, form elements corresponding value will be? Key = value & key = value of mode displayed in the address bar inside. Post manner that does not. Post to relatively safer. Because want to get way data is displayed in the address bar inside, so he can deliver the amount of data it is limited. Post size is unlimited.

Redirect

Redirects and Forwards achieve the effect is the same.

Redirection request and response process will be twice. After RegistAction run, it will give the browser a redirect response instructions. After the browser receives the redirect instruction, it will automatically request. Users do not have to do anything.

The difference between forwarding and redirection

Forwarding and redirection code request code response. Forwarding parameters are url-pattern. The redirection is / appName / url-pattern

Forwarding process only one request and response. Redirection process will produce two requests and responses.

Forwarding address bar shows the path before forwarding resources. Redirection address bar shows the path of the resource after the redirect.

Because the redirection request will have two objects, so when using redirect the request scope will be no effect.

After the refresh redirect, will not cause abnormal database data.

Session tracking technology

On the server side there are some resource files, you need to determine the status of the request, to see whether the request has the right to access the resource files, if you have let the access request, or not allow the access request. To accomplish this requires the use of session tracking technology.

Cookie

A cookie is created out of the server, and then save the client

Once you have the browser cookie information, the browser requests all the resources of the project, cookie information will automatically carry the project

cookie features

A cookie is a string and then keep the browser, a cookie is a mark and a value, and values ​​are marked by the strings, it is not Chinese

When a browser requests project resources automatically carry with projects related to cookie

When the cookie will be automatically removed when the browser is closed again, if you want to control the cookie is valid, create a cookie object will fall by setMaxAge () to set the cookie life long, in seconds

cookie data insecurity, there is no important data in cookie

Session

session is to create a server out of a private storage space for each browser

HttpSessionsession = request.getSession (); // get the session object, when the first browser to access the server, call the method, the meaning of which is to create a session object. When the browser is not the first time to access the server, call the code, and the meaning of the code is to get the browser corresponding session

Session Life Cycle

By default, the session will survive 30 minutes, the survival time can be determined by web.xml configuration session

When the browser requests the server closes the browser. After this time, then open a browser, access the server, with the resulting session before closing the session not get the same. After the server-to-30 minutes to put out the destruction of the previous session.

session features

one to one session with the browser.

Session is stored on the server side.

Session store any data type.

Session scope which is not at liberty to release data

Cookie and session of difference

All session tracking technology, and all browser-related

Saved location is not the same, cookie and then save the browser-side, server-side session and then save, save important data in another session

Saved data is not the same, cookie saved string, session save any type

The principle of Session

When the browser first accesses the server, the server creates a session object and create a cookie object, JSESSIONID and session id into the cookie, the response to the client browser next visit, which will carry the project related cookie, the server will look for the corresponding session object through JSESSIONID, if the browser to disable the cookie, will be on the url address URL rewriting, JSESSIONID will be submitted to the server method parameters

ServletContext

ServletContext can get the contents of the configuration file, web.xml is the encapsulation of objects, a project is only one object has only one ServletContext so web.xml

Request scope minimum range, corresponding to the first request.

Session scope range should be larger. Corresponds to a session. As long as the browser is not related to a session.

The maximum range Application (ServletContext) scope. Corresponds to an application. No matter how many browsers, as long as access to the same project, then their position is a application object.

Application object associated with a project, he would have been created when tomcat starts, tomcat shut down when they were destroyed.

Monitor

You can listen to some of the events. ServletContext listener can listen tomcat startup and shutdown.

filter

Filter is a component of running a web project, when the request came, the filter will be running inside the code, and then distributed to the resource request to the real request.

Struts2 framework

struts2 frame encapsulates Servlet technology, the parameters for receiving the transmission over the page, by internal processing, and returns the result

Struts2 framework of the implementation process

The method of the browser sends a request to the server, through the core of the filter process, acquired, and Method namespace, and then matches the corresponding profile struts.xml, the content execution method, acquiring a return value, go to file struts.xml find the corresponding result tag, in accordance with the request in the manner specified resource file

Jump way

dispatcher default. Forwarded to the jsp page.

redirect redirect to a jsp page.

redirectAction redirected to an action.

forwarded to a chain action.

Auction class get session

HttpServletRequest request=ServletActionContext.getRequest();

HttpSession session=request.getSession();

The data processing mechanism struts2

the action of data processing placed inside the stack to the value. Value stack space to store data. To view inside the stack to a value which can obtain the data.

View data may be obtained through the inside of the stack to a value ognl expression. When required process control, struts2 label can.

OGNL expression

Object graph navigation language. Before he was el expression of an expression language is similar. This is independent of the ognl struts2 framework.

Ognl two data sources. 1.Root area. 2.contextMap area.

Interceptor

Struts2 interceptor struts2 framework is the most important core components. Struts2 many of the core functions are implemented by the interceptor.

When a client requests struts interceptor will first enter into the request interceptor which struts. Run the interceptor, interceptors can release request, after the release operation request action method. Action method has run, go run the code to implement the interceptor finished.

The difference between filters and interceptors

Belonging to the related art servlet filter, the interceptor is struts2 component technology.

Filters can filter all resources, including jsp, servlet, images, css, js. Only struts2 interceptor interception of action.

If you use a custom interceptor, the interceptor struts2 framework comes in struts2 project will fail, need to reference interceptor interceptor system configuration increases above defaultStack in action.

Interceptor stack

An interceptor stack which can store a plurality of interceptors. When Action may be referenced directly reference interceptor stack

Use the default interceptor

<Default-interceptor-ref name = "interceptor name" />

Default-action-ref

When a user requests a actionName does not exist, this time will enter the request into a default-action-ref specify action class.

Global-results

Configured as a global result

Guess you like

Origin www.cnblogs.com/490889763-qq/p/11121333.html