October 3, 2016 10:36:40
Have always wanted to write their own blog, one can share their learning experience, and then can be summed up in a timely manner, after all, the blog is written to everyone to see, need to pay more attention to each detail, rather than just let yourself understand.
Learning Java also has about 6 months, it feels necessary to summarize the study, because it is possible to engage in. Net. Three-tier architecture +servlet: Start the project first, because of the new feature of the servlet3.0 version, no need to configure Web. XML (without using spring), I am currently using the @ annotation form. Front end via form form, or address link, or AJAX, make a request such as <a href= "Subjectservlet?method=modifysubject&id=${subject.id}" > Modify </ A> matches to the corresponding servlet "@WebServlet ("/subjectservlet ") @webServlet is used to declare a class as a servlet, which will be handled by the container at deployment time. The container deploys the corresponding class as a servlet based on the specific property configuration. "The Doget () or Dopost () method" function body that is overridden in the execution servlet will execute its own method "as follows Doecho () function
The server obtains the front-end data (Request.getparameter) through the request. The data that exists in the request is converted into an object by the set method. Then the corresponding function block is judged by the corresponding method variable. For example, show all, method corresponding function block will call the DAO layer display all functions, return LIST<SUBJECT>, the value is stored in session, and finally through response to complete the jump page. The JSP page can also be used to retrieve values from the session. Finish the display at the end. (Note that the above backend by the value in the session, the front end from the session to take value, just in the JSP page) "A word summed up: the role of servlet is to accept the request and to make the corresponding"
DAO layer Invocation: ① invokes the DAO layer's Save () method, which converts the incoming object information into an SQL statement in the Save () method. Call the data link layer to execute the SQL statement. ② calls the FindAll () method, first new out of the list collection to hold the returned database records. Execute the SQL statement to get the database result set. Iterate through the result set, save each record in the new object, and save the object in the list collection. Returns the list collection.
The biggest difference between ssh:struts and servlet is that struts uses multiple cases, and the servlet uses a singleton pattern. You need to configure Web. XML in SSH. ① configures the interceptor, where all URLs ("/*") are blocked, and the permissions are given to struts for processing. ② Configure the spring load path and listener. The Web. XML must be configured, but in the actual running project should be configured <welcom-file> for the Project Launch load page (in fact, all should be configured, not described earlier, no longer intend to repeat, this is very important, easy to ignore, reminders.) The first time you configure your environment, you may be mistaken for other configurations because of that. Struts.xml is configured to match the value of the URL to the corresponding action. and jump to the corresponding page based on the return value. (Struts.xml will automatically load, regardless of how the URL is intercepted after the specific action path is found.) There are also application are automatically loaded under a certain path, these default add-ons everyone knows, at least temporarily no doubt. Now client input add information, click submit Form form to server. Filters intercept all URLs. In action, the uploaded data is converted to an object by the set, and then according to the method value matching corresponding methods, execute the corresponding DAO layer (hibernate) code, Save the recorded object data to the session. Finally, according to the value of return and Strut.xml value to jump to the corresponding page (now found Strus.xml also have this function, in fact, can also be set to JSON data return). Comparing the servlet, we can see that the data acquisition is not required by the request method to obtain, but rather through the front-end name matching the transmission of the specific value. is still relatively simple.
Hibernate: Get session through session factory. Begins a transaction. Execute the method (Hibernate encapsulated Orm method, manipulate the database, modify or read), commit the transaction, close the session.
Where sessionfactory needs to load the Hibernate.cfg.xml file (connect to the database and specify the mapping file path). Mapping files The mapping between the primary configuration database and the entity class.
Spring:spring mainly responsible for the production and management of objects. There are three types of injection methods (the constructor method is not used at present). An injection (<property> tag element, where the Name property corresponds to the variable name to inject, the type of the variable to which the value of the Type property corresponds, a class or wrapper type can be customized) by means of a property setter. The Value property corresponds to the corresponding values, and a ref property, which corresponds to the corresponding bean, and the annotation method @autowired injection. I personally prefer the @autowired way, because. xml files are relatively simple, but also cause a unclear dependency. A learning connection is available here: http://www.imooc.com/article/1309
And: http://blog.csdn.net/qiulongtianshi/article/details/7748227 (with code)
Ssm:spring is the same as SSH, but you need to be aware of the scope property in SSH
The configuration of the Web. xml file in the SSM is similar to that of the Shh configuration, but the spring path must be configured, but in SSH it is necessary to configure the filter to submit the request to struts, whereas in SSM you do not need to configure the filter, but instead configure the Dispatcherservlet front controller to configure the phase for different requests Spring-mvc path (Below is the Web. xml file code for a workflow, which can be used to reflect dispatcherservlet usage and configuration)
SPRING-MVC when the request is received (or when the project is started, as set up here <load-on-startup>1</load-on-startup>), Different URL requests are matched to the appropriate SPRING-MVC configuration file (configuration component Scan, or you can configure the controller request and the prefix of the jump)
The SPRING-MVC configuration file detects @controller in the corresponding package to produce the corresponding controller object, the URL request is matched to the corresponding @requestmapping, and the data is passed (SSM simple rude don't worry about how the data is transmitted, How to deposit objects). Its role as struts, no longer repeat.
Mybatis: The first is to take advantage of the Sqlsessiontemplate object generated by spring and get the DAO method in it. Where the MyBatis configuration file mybatis-config.xml The primary configuration map file path, and the alias is set for the class. The connection configuration of the database is in the Sring-mvc.xml (real spring) configuration
Http://blog.sina.com.cn/s/blog_4550f3ca0100ubmt.html
In the MyBatis XML file no longer say, the main attention Resulttype and resultmap difference, very useful OH
Refer to the document in slices:
Http://si shuok.com/forum/blogpost/list/5188.html16436
Java MVC Framework Series summary Ssh,ssm,servlet