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.部署服務器

 

啟動測試的項目,


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM