Spring + Spring MVC + Hibernate environment, mvchib.pdf

Source: Internet
Author: User

Spring + Spring MVC + Hibernate environment, mvchib.pdf

Spring + Spring MVC + Hibernate for short, "SSH ". Spring container is the core of Spring and is responsible for managing java components in spring. Core Mechanism of Spring: dependency injection. Hibernate is a good ORM (relational object ing) framework. Steps for Spring + Spring MVC + Hibernate environment combination:


1. Build the Spring + Hibernate environment (consistent with the ssh Build Steps)

(1) Add the rack package of Spring + Hibernate.

2. Build the SpringMVC Environment
(1) Add Springmvc dependency package: spring-webmvc.jar
(2) Configure web. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <! -- Spring listener: --> <listener-class> org. springframework. web. context. ContextLoaderListener </listener-class> </listener> <! -- Specify the spring file path --> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: applicationContext. xml </param-value> </context-param> <! -- ============================== Configure spring mvc Start ====================== =============================--> <servlet-name> SpringMVC </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <! -- Configure springmvc Lu Jin --> <init-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: springmvc. xml </param-value> </init-param> <! --> = 0 indicates that the servlet is loaded when the web container is started (the number indicates the priority) --> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-name> SpringMVC </servlet-name> <url-pattern> *. do </url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> index. jsp </welcome-file> </welcome-file-list> </web-app>

(3) Configure springmvc. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http://www.springframework.org/schema/context" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "> <! -- SpringMVC configuration rules are the same as Spring: Seamless Integration --> <! -- Configuration view --> <bean id = "internalView" class = "org. springframework. web. servlet. view. InternalResourceViewResolver"> <! -- Configure the view prefix --> <! -- <Property name = "prefix" value = "WEB-INF/jsp/"/> --> <property name = "prefix" value = "/"/> <! -- Configure the view suffix --> <property name = "suffix" value = ". jsp"/> </bean> <! -- Configure URL ing --> <bean id = "urlMpping" class = "org. springframework. web. servlet. handler. simpleUrlHandlerMapping "> <property name =" mappings "> <props> <prop key =" userController. do "> userController </prop> <prop key =" perpoController. do "> perpoController </prop> <prop key =" multiMethodController. do "> multiMethodController </prop> </props> </property> </bean> <! -- Multi-method call rules --> <bean id = "parameterMethod" class = "org. springframework. web. servlet. mvc. multiaction. ParameterMethodNameResolver"> <! -- Value is random, but it must be meaningful --> <property name = "paramName" value = "method"/> </bean> <! -- Submit the Controller to the Spring container for Management --> <bean id = "userController" class = "com. ssh. springMVC. controller. userController "> </bean> <bean id =" perpoController "class =" com. ssh. springMVC. controller. perpoController "> </bean> <! -- Configure multiple methods in a controllet --> <bean id = "multiMethodController" class = "com. ssh. SpringMVC. controller. MultiMenthodController"> <! -- Inject multiple method call rules --> <property name = "methodNameResolver" ref = "parameterMethod"> </property> </bean> </beans>

 

Logon page:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Form submission process MultiMenthodController. java File

Package com. msit. springmvc. controller; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import org. springframework. web. servlet. modelAndView; import org. springframework. web. servlet. mvc. multiaction. multiActionController; public class MultiMenthodController extends MultiActionController {/*** url: http: // localhost: 8080/SpringMVCDay1/multiMethodController. do? Method = login * @ return */public ModelAndView login (HttpServletRequest request, HttpServletResponse response) {System. out. println ("here is the login method" + request. getParameter ("username"); return new ModelAndView ("MyJsp");} public ModelAndView update (HttpServletRequest request, HttpServletResponse response) {System. out. println ("here is the update method"); return new ModelAndView ("MyJsp ");}}

:

You can click the button in the lower-right corner to comment on the content of the article, or click the follow button in the lower-left corner to follow the latest developments in my blog. If the content of the article is helpful to you, do not forget to click the recommendation button in the lower right corner to support it. If you have any questions about the content of the article, you can contact me by commenting or sending an email: if you need to reprint 2276292708@qq.com, please indicate the source, thank you !!

 

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.