MVC is no stranger to us. It originated from a software design pattern for the Smalltalk language in the 1980s and is now widely used. In recent years, with the popularity of Java, MVC's low coupling, high reusability, maintainability, manageability of software engineering and many other advantages make it very popular in the Java platform. In the meantime, many excellent ones have also been born. MVC frameworks, such as Struts, WebWork, Struts2, JSF and other frameworks that focus on the control layer, focus on the Spring framework of business logic, Hibernate, iBaTIs, Castor, JORM and other frameworks focusing on the persistence layer. Due to the recent use of an SSI framework, this article is mainly a summary of the three open source MVC frameworks of Strtus2, Spring, and iBaTIs.
Struts2 mainly comes from the webwork framework. Compared with Struts1, in terms of data transfer, Struts2 provides a more powerful OGNL tag function, which enables it to directly pass values ​​to the data in the jsp page by defining variables in acTIon. Struts1's formbean; and in the jump control, Struts2 simplifies the amount of information in the configuration file, making the exchange between the page and acTIon more concise and intuitive, easy for developers to manage.
Spring is very powerful, such as its control inversion/dependency injection mechanism, which eliminates the need to write our own factory pattern. The implementation class will use control classes, business logic classes, data access classes, and JNDI or JDBC. Data source hosting; Spring's support for AOP saves us a lot of work in user chmod.html 'target='_blank' permission control, transaction processing;
iBatis is a lightweight OR Mapping framework. Compared with Hibernate, iBatis provides a semi-automated object-relational mapping implementation. Developers need to write specific SQL statements to provide more free space for system design. Sql statement optimization provides convenience.
The picture below is a combination of the three frameworks we have used, which is briefly described below.
In the control layer, the Strtus2 tag function is used to directly interact with the data on the jsp page in the Action. Struts2 provides support for Sping when calling business logic layer applications. Developers need to complete the configuration of struts.xml and write the various Action classes.
In the business logic layer, the dependency injection of the Spring framework is used to implement the instance hosting of the business logic class and the DAO class. In terms of transaction processing, the face-oriented transaction processing function provided by Spring is used to make the transaction control of the data out of the data access interface. Implementation; in terms of object-relational mapping, leverage Spring's support for database connection pooling and support for the iBatis framework. Developers need to complete the configuration of the data source, the configuration of the application*.xml file for the different modules, and the definition of the business logic interface and the implementation of the business logic implementation.
In the persistence layer, using the semi-automated object-relational mapping provided by iBatis, developers need to write specific SQL statements to provide more freedom for system design. In addition, the developer needs to complete the configuration of SqlMapConfig.xml and *SqlMap.xml, as well as the definition of the DAO interface and the implementation of the DAO interface.
In the process of exchanging between layers, data transfer classes are used for data transfer and interaction. Among them, the data transmission class corresponds to the database table one by one.
The SSI framework can reduce the coupling of our code, enhance the robustness and reusability of the code, and speed up the development, but there are also some shortcomings, such as the configuration files of the three frameworks, but also brought us Some inconveniences, especially for smaller applications.
One: First introduce the struts2 spring ibatis their respective jar packages are not listed here.
Two: add a configuration file
Let's start with the web.xml file.
Web.xml loading process:
1 When starting the WEB project, the container (eg: Tomcat) will read his configuration file web.xml to read two nodes.
"listener" / "listener" and "context-param" / /context-param
2 Next, the container creates a ServletContext (context). This part of the WEB project will share this context.
3 The container converts "context-param" /context-param into a key-value pair and hands it to the ServletContext
4 the container creates an instance of the class in "listener" / /listener, that is, create a listener
5 There will be a contextInitialized(ServletContextEvent args) initialization method in the listener , which is obtained in this method:
ServletContext = ServletContextEvent.getServletContext();
The value of context-param = ServletContext.getInitParameter ("context-param key");
Web.xml node load order
The order in which nodes are loaded is independent of their order in the web.xml file. That is, because the filter is written in front of the listener, the filter will be loaded first. The final conclusion is: listener-"filter-"servlet
There is also a configuration node: context-param, which is used to provide key-value pairs, ie application context information, to the ServletContext. Our listener, filter, etc. will use the information of these contexts during initialization. So should the context-param configuration section be written before the listener configuration section? In fact, the context-param configuration section can be written anywhere, so the actual load order is:
Context-param -" listener -" filter -》 servlet
Loading spring
"listener"
"listener-class"
org.springframework.web.context.ContextLoaderListener
/listener-class
/listener
final conclusion:
The loading order of web.xml is: [context-param -" listener - "filter -" servlet - "spring], and the order of the actual program calls between nodes of the same type is called according to the order of the corresponding mapping. .
Open the web.xml file and add the following content according to actual needs.
"! -- Context parameters for log4j and spring use --"
"context-param"
"param-name" webAppRootKey "/param-name"
"param-value"/WEB-INF/log4j.properties "/param-value"
/context-param
"! -- application context parameters, specify the location of the spring configuration file --"
"context-param"
"param-name" contextConfigLocation "/param-name"
"param-value"/WEB-INF/beans.xml "/param-value"
/context-param
"listener"
"listener-class" org.springframework.web.util.Log4jConfigListener "/listener
-class
/listener
"! -- Listener is used to initialize the spring framework --"
"listener"
"listener-
Class"org.springframework.web.context.ContextLoaderListener"/listener-class
/listener
Here are some configuration files when talking about SSI integration:
1, contextConfigLocation: Spring container needs to load the Spring configuration file when starting. The default is the applicationContext.xml file in the /WEB-INF directory.
Of course, you can also put it on the classpath, you can include multiple spring configuration files, you have to rely on contextConfigLocation
"! -- Load spring configuration file if the file name is applicationContext.xml and is in the WEB-INF directory - this configuration is not required --"
"context-param"
"param-name" contextConfigLocation "/param-name"
"param-value"/WEB-INF/beans.xml "/param-value"
/context-param
If the context-param is not configured in web.xml, the spring configuration is like the code example above, and it is automatically looking for applicationContext.xml in the WEB-INF directory. At this point, if you modify the name of applicationContext.xml, or remove it, and then start the server, you will get the following exception information:
1.nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
This confirms its default configuration. In the default configuration, spring will only look for the configuration file in the WEB-INF directory, and will not look for it under the classpath.
If we don't want to put the configuration file in the WEB-INF directory? Development often creates a config directory under src for storing configuration files. At this point, the corresponding param-value is changed to: classpath:config/applicationContext.xml.
Be sure to add the classpath, which tells the spring to look for the configuration file in the config directory under the classes directory.
2, how to start the Spring container
Two methods, one to start a load-on-startup servlet with a listener.
"! -- Configure spring listener --"
"listener"
"listener-class" org.springframework.web.context.ContextLoaderListener "/listener-class"
/listener
Second
Servlet
"servlet-name" context "/servlet-name"
"servlet-class" org.springframework.web.context.ContextLoaderServlet "/servlet-class"
"load-on-startup" 1 "/load-on-startup"
/servlet
3, integration of Struts2
"filter"
"filter-name" struts2 "/filter-name"
"filter-class" org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter "/filter-class"
"/filter"
Filter-mapping
"filter-name" struts2 "/filter-name"
"url-pattern"/*"/url-pattern"
/filter-mapping
4, Spring integration ibatis configuration file
"bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
"property name="configLocation"
"value" classpath: SqlMapConfig.xml "/value"
"/property"
"/bean"
5, Struts.xml
Constant name=“struts.objectFactory†value=“spring†/》
Constant configuration struts constants (also available in the struts.properties) file, the struts object factory support by spring management.
Power Storage LiFePO4 Battery Solar Energy Systems For Home
S/N
|
Item
|
Content
|
1
|
product type
|
Modular 48V large-capacity energy storage power system
|
2
|
Module model
|
48V200Ah
|
3
|
Weight
|
430kg
|
4
|
System capacity
|
200Ah*Parallel number(200~2000Ah)
|
5
|
Module dimension
|
19-inch standard cabinet width, thickness 5U, depth 480
|
6
|
Maximum continuous charge and discharge current
|
0.75C
|
7
|
Installation method
|
Pedal models, seat bucket models, etc.
|
8
|
IP rating
|
Module IP20, system power box can be customized IP65
|
9
|
Service life
|
10 years or 3000 cycles
|
10
|
Operating temperature range
|
Temperature: -20~60℃ Humidity: ≤85%RH
|
11
|
product description
|
The product is positioned as an energy storage power supply system, in accordance with the ultra-long storage/cycle life, modular design, can be connected in parallel according to the required system capacity, and can realize battery intelligent monitoring and
battery management through RS485 communication or CAN communication, and inverter power supply/ UPS power supply and other equipment are perfectly compatible and can be widely used in various 48V energy storage power systems |
14
|
certificate
|
MSDS,ISO9001,CB,UN38.3
|
Energy Storage Lithium Battery Cbinet For Home
Jiangsu Zhitai New Energy Technology Co.,Ltd , https://www.zt-tek.com