栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring MVC详细环境配置和入门

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring MVC详细环境配置和入门

Spring MVC环境配置和入门
  • 新建Meven项目,构建mvc
  • 解决maven创建项目过慢,添加 archetypeCatalog internal
  • 部署tomcat
  • 目标结构(多余的类是练习的)
  • 添加pom坐标
  • 创建HelloController
  • 在resources配置srpingmvc.xml
  • 在webapp下WEB-INF中web.xml 配置环境
  • index.jsp
  • pages下success.jsp
  • 运行结果截图
    • index.jsp
    • success.jsp

新建Meven项目,构建mvc

解决maven创建项目过慢,添加 archetypeCatalog internal

部署tomcat

目标结构(多余的类是练习的)

添加pom坐标



  4.0.0

  com.itboy
  springmvc_day01_start
  1.0-SNAPSHOT
  war

  springmvc_day01_start Maven Webapp
  
  http://www.example.com

  
    UTF-8
    1.8
    1.8
    
    5.0.2.RELEASE
  

  
    
      org.springframework
      spring-context
      ${spring.version}
    

    
      org.springframework
      spring-web
      ${spring.version}
    

    
      org.springframework
      spring-webmvc
      ${spring.version}
    

    
      javax.servlet
      servlet-api
      2.5
      provided
    

    
      javax.servlet.jsp
      jsp-api
      2.0
      provided
    
  

  
    springmvc_day01_start
    
      
        
          maven-clean-plugin
          3.1.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.8.0
        
        
          maven-surefire-plugin
          2.22.1
        
        
          maven-war-plugin
          3.2.2
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
      
    
  


创建HelloController
package com.itboy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class HelloController {
    @RequestMapping(path = "/hello" )
    public String sayhello(){
        System.out.println("helle springmvcc 你好");
        return "success";
    }
}

在resources配置srpingmvc.xml



    
    

    
    
        
        
    

    
    
        
            
                
            
        
    


    
    

在webapp下WEB-INF中web.xml 配置环境



    Archetype Created Web Application
    
    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc.xml
        
        1
    
    
        dispatcherServlet
        /
    
    
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    
    
        characterEncodingFilter
        /*
    


index.jsp
<%--
  Created by IntelliJ IDEA.
  User: 儒雅
  Date: 2021/11/12
  Time: 20:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


你好

入门mvc
pages下success.jsp
<%--
  Created by IntelliJ IDEA.
  User: 儒雅
  Date: 2021/11/12
  Time: 21:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


入门成功

运行结果截图 index.jsp

success.jsp

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/488970.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号