Spring MVC 环境搭建

2021-03-09 05:27

阅读:698

标签:java   ret   驱动加载   dir   准备工作   word   cte   git   index   

创建好的Maven项目:

技术图片

 

 

 

首先要在main下创建两个文件夹:java,resources/config(标准是resources)

技术图片

 

 

 

 然后把Java文件用Make Directory as设置为Sources Root    

   把resources用Make Directory as设置为Resources Root

 

准备工作做好,主要步骤:

1、POM.xml中添加相应的依赖



junit
junit
4.12
test



org.springframework
spring-context
5.0.14.RELEASE


org.springframework
spring-webmvc
5.0.14.RELEASE


org.springframework
spring-test
5.0.14.RELEASE
test


org.springframework
spring-jdbc
5.0.14.RELEASE



mysql
mysql-connector-java
5.1.48



org.mybatis
mybatis-spring
2.0.4


org.mybatis
mybatis
3.5.2


commons-dbcp
commons-dbcp
1.4


com.github.pagehelper
pagehelper
5.1.2




javax.servlet
javax.servlet-api
provided
3.1.0


javax.servlet
jsp-api
provided
2.0


jstl
jstl
1.2


taglibs
standard
1.1.2



org.mybatis.generator
mybatis-generator-core
1.4.0




log4j
log4j
1.2.12


commons-logging
commons-logging
1.2

2、在web.xml中配置DispatcherServlet


Archetype Created Web Application


contextConfigLocation
classpath:beans.xml


org.springframework.web.context.ContextLoaderListener



CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
utf-8



CharacterEncodingFilter
/*



app
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:spring-web.xml

1


app
/


3、在resource目录中新建Springmvc的配置文件

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">










测试
java文件夹新建com.controller包,包下新建
TestController.java

package com.controller;

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

/**
 * Created by Tired on 2018/8/3.
 */
@Controller
@RequestMapping("test")
public class TestController {
    @RequestMapping("/index")
    public String index()
    {
        return  "index";

    }
}


webapp下新增admin文件夹,下新建index.jsp

技术图片

 

 添加tomcat访问localhost:8080/test/index

技术图片

 

 

访问成功则说明Spring-MVC搭建成功

Spring MVC 环境搭建

标签:java   ret   驱动加载   dir   准备工作   word   cte   git   index   

原文地址:https://www.cnblogs.com/1372841965ZQ/p/14185971.html


评论


亲,登录后才可以留言!