SSH getting started (Struts2.1 + Spring3.1 + Hibernate4.1)-Query System (bottom), struts2.1spring3.1

Source: Internet
Author: User

SSH getting started (Struts2.1 + Spring3.1 + Hibernate4.1)-Query System (bottom), struts2.1spring3.1

Let's continue. The biggest advantage of SSH is the loose coupling of the implemented system, which can separate the background and foreground organically.

 

I. directory structure

A good program should have a good start. Let's take a look at the entire directory structure.

The main concept is the three-tier architecture, or the mvc concept.

Ii. Hibernate entity III. Hibernate data layer dao iv. Logic Design Service Layer

The design method is similar to that of the Dao layer. It is also designed as an interface mode. More importantly, the interface inherits the entity interface of the Dao layer, which ensures behavior consistency.

IArchiveService

 

package cpacm.service;import cpacm.dao.IArchiveDao;public interface IArchiveService extends IArchiveDao {}

 

 

ArchiveService

Package cpacm. service; import java. util. list; import cpacm. dao. archiveDao; import cpacm. pojo. archive; public class ArchiveService implements IArchiveService {private ArchiveDao archiveDao; // load the database operation class (load using spring) @ Override public void save (Archive transientInstance) throws Exception {// TODO Auto-generated method stub archiveDao. save (transientInstance) ;}@ Override public void delete (Archive persistentInstance) throws Exception {// TODO Auto-generated method stub archiveDao. delete (persistentInstance) ;}@ Override public void update (Archive instance) throws Exception {// TODO Auto-generated method stub archiveDao. update (instance) ;}@ Override public int updateByQuery (String hql) {// TODO Auto-generated method stub return archiveDao. updateByQuery (hql) ;}@ Override public Archive findById (Integer id) {// TODO Auto-generated method stub return archiveDao. findById (id) ;}@ Override public List <Archive> findAll () {// TODO Auto-generated method stub return archiveDao. findAll () ;}@ Override public List <Archive> queryForPage (String hql, int offset, int length) {// TODO Auto-generated method stub return archiveDao. queryForPage (hql, offset, length) ;}@ Override public List <Archive> findByQuery (String queryString) {// TODO Auto-generated method stub return archiveDao. findByQuery (queryString);} public ArchiveDao getArchiveDao () {return archiveDao;} public void setArchiveDao (ArchiveDao archiveDao) {this. archiveDao = archiveDao ;}}
5. Struts control layer Action

This is the most important part of our interaction with the foreground. We control the background by setting the Action.

Vi. Spring Reverse Control Injection bean

I don't know if you have noticed that several objects in the class are not instantiated. Here we use Spring's reverse control.
Like here

Private ArchiveDao archiveDao; // load database operation class (use spring for loading)

(It is important that you set the set and get methods for these classes)

It is implemented through the Spring configuration file.

 

The above background is over, so we can implement it through the front-end.

VII. JSP front-end page

There are many front-end interfaces. Here I will extract more important code. The first is the preview of the webpage.

VIII. Conclusion
This can be regarded as the simplest system in SSH, but it simply implements the data addition, deletion, modification, and query operations without other functions.

Through the practice of this system, we have a preliminary understanding of SSH, but it is far from enough. It is estimated that it is not even easy to get started ~.

 

Source code download: https://github.com/cpacm/WebSystem

 

==========================================================

 

 

 

Author: cpacm
(Http://www.cnblogs.com/cpacm/p/4004504.html)

 


In the ssh framework, how does hibernate and spring work?

Various management, struts implements mvc, hibernate is responsible for orm, spring manages various beans

Getting started with struts2, hibernate, spring, and SSH frameworks

I have a lot of tutorials I 've learned before. Do you want? Send an email to me if necessary. Threenoodles@163.com
They are both entry-level and easy to understand.

I sent a copy of struts2 to see how it works. If it is good, there will also be a set of hibernate and spring.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.