1. 程式人生 > >idea建立springMVC框架和配置小檔案

idea建立springMVC框架和配置小檔案

這個框架主要還是思想,之後,,,還是建立專案好了,

1.新建一個專案

新建一個maven,並且選擇webapp型別。

2.點選next選項

這裡面的兩個選項可以隨便填,但是Artifactid一般是專案名,第一個可以是自己定義的名稱了,

3.繼續點next

 在這我們可以新增name=archetypeCatalog,internal,可以在建立專案的時候快一點,

3.建立好了專案之後就把我建立的一個小案例放上了

1.建立專案的流程

01.引入需要的pom檔案節點

02.web.xml檔案中配置核心控制器

03.WEB-INF目錄下建立mvc核心配置檔案(spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

  這個是檔案的頭部資訊,

核心配置檔案的名稱 必須是  <servlet-name>+”-servlet.xml

04.index.jsp頁面建立一個連線

<a href="hello">helloSpringMVC</a>

05.在核心配置檔案中增加對應的處理bean

<bean id="/hello" class="com.xdf.controller.HelloController"/>

06.建立對應的包和controller

public class HelloController  extends AbstractController{
    @Override
    
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("您已經進入了後臺的controller/action/servlet"); ModelAndView mv= new ModelAndView(); mv.setViewName("/WEB-INF/welcome.jsp"); return new ModelAndView("/WEB-INF/welcome.jsp"); }

07.部署伺服器

 

啟動測試的專案,