gradle下的第一个SpringMVC应用
新建gradle project

缺少了很多文件夹和文件,我们自己补充,补充完的目录如下:

HelloController:
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/test")
public class HelloController { @RequestMapping("/hello")
public ModelAndView del(HttpServletRequest request,
HttpServletResponse response) {
System.out.println("----del----");
return new ModelAndView("/hello", "message", "你好");
}
}
spring-mvc.xml:
<?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: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-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> <!-- scan the package and the sub package -->
<context:component-scan base-package="controller"/> <!-- don't handle the static resource -->
<mvc:default-servlet-handler /> <!-- if you use annotation you must configure following setting -->
<mvc:annotation-driven /> <!-- configure the InternalResourceViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/" />
<!-- 后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"> <!--START 设置字符编码过滤器-->
<filter>
<description>字符集过滤器</description>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>字符集编码</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--END 设置字符编码过滤器--> <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-mvc.xml</param-value>
</init-param>
<!-- <load-on-startup>1</load-on-startup> -->
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
index.jsp:
<%--
Created by IntelliJ IDEA.
User: sawyer
Date: 2018/4/19
Time: 下午11:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>我的主页</title>
</head>
<body>
你好,世界
</body>
</html>
hello.jsp:
<%--
Created by IntelliJ IDEA.
User: sawyer
Date: 2018/4/20
Time: 上午12:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${message}helloWorld </body> </html>
验证效果:
gradle下的第一个SpringMVC应用的更多相关文章
- Spring MVC框架下的第一个Hello World程序
本程序是一个maven程序,使用maven方便管理jar包和程序,简化了操作步骤.本程序的目的是通过一个简单的程序,了解Spring MVC框架的基本工作流程,由简入繁的学习Spring MVC框架, ...
- SpringMVC(一):搭建一个SpringMVC helloword项目
操作步骤: 1)下载spring framework开发包,给eclipse安装spring开发插件,如何安装开发插件&下载开发包请参考我的博文:<Spring(一):eclipse上安 ...
- 看年薪50W的架构师如何手写一个SpringMVC框架
前言 做 Java Web 开发的你,一定听说过SpringMVC的大名,作为现在运用最广泛的Java框架,它到目前为止依然保持着强大的活力和广泛的用户群. 本文介绍如何用eclipse一步一步搭建S ...
- (一)SpringMvc简介以及第一个springmvc工程
一.SpringMVC是什么? springmvc是Spring的一个模块,提供web层解决方案(就与MVC设计架构) 如上图, DispatcherServlet:前端控制器,由SpringMVC提 ...
- SpringMVC_001 第一个SpringMVC程序
今天我们来学习第一个SpringMVC程序 一.配置开发方式 (1)首先建立一个SpringMVC web程序 (2)导入jar包 (3)建立UserController.java package ...
- 第一个SpringMVC程序 (配置版)
通过配置版本的MVC程序,可以了解到MVC的底层原理,实际开发我们用的是注解版的! 1.新建一个普通Maven的项目,然后添加web的支持 2.导入相关的SpringMVC的依赖 3.配置web.xm ...
- SpringMVC-02 第一个SpringMVC程序
SpringMVC-02 第一个SpringMVC程序 第一个SpringMVC程序 配置版 新建一个Moudle , springmvc-02-hello,确定依赖导入进去了 1.配置web.xml ...
- SpringMVC学习02(我的第一个SpringMVC程序)
2.Hello,SpringMVC 2.1 配置版 1.新建一个Moudle , springmvc-02-hello , 添加web的支持! 2.确定导入了SpringMVC 的依赖! 3.配置we ...
- Ubuntu系统下的第一个console程序
进入自己喜欢的目录,前面步骤和windows基本一致,只简单描述下 执行 dotnet new 然后执行 dotnet restore 然后执行 dotnet run 第一次未编译,会自动编译,然后可 ...
随机推荐
- skynet1.0阅读笔记_skynet的启动
首先看skynet的启动,函数入口在 skynet_main.c 的main(),其中最重要的是: skynet_start(&config); 在skynet_start中做了两个启动: / ...
- C++中前置声明的应用与陷阱
前置声明的使用 有一定C++开发经验的朋友可能会遇到这样的场景:两个类A与B是强耦合关系,类A要引用B的对象,类B也要引用类A的对象.好的,不难,我的第一直觉让我写出这样的代码: // A.h #in ...
- JAVA虚拟机、Dalvik虚拟机和ART虚拟机简要对比
1.什么是JVM? JVM本质上就是一个软件,是计算机硬件的一层软件抽象,在这之上才能够运行Java程序,JAVA在编译后会生成类似于汇编语言的JVM字节码,与C语言编译后产生的汇编语言不同的是, ...
- C++中 char *s 和 char s[] 的区别
原因 刚好看到给main传递参数,书上(C++Primer)说“ int main(int argc, char *argv[])也可以写成 int main(int argc, char **arg ...
- CentOS系统命令
系统命令 yum命令 yum makecache yum 生成缓存 yum list installed mysql* 查看有没有安装过*包 rpm -qa | grep mysql* 查看有没有安装 ...
- CentOS系统安装后的基础优化
在运维工作中,我们发现Linux系统安装之后并不能立即投入生产环境使用,往往需要先经过我们运维人员的优化才行. 下面我就为大家简单讲解几点关于Linux系统安装后的基础优化操作. 注意:本次优化都是基 ...
- 【Python】多线程2
threading模块 import time import random import threading class Inclass: def __init__(self): print 'Inc ...
- UGUI 的多分辨率适配
1.Canvas的属性配置 2.Canvas Scaler的属性配置 3.根据不同的屏幕的比例动态修改缩放基准 void Start () { float standard_width = 960f; ...
- 在可部署到brew真机上的程序包构建完之后又要如何将该程序包发布到真机上呢
1.到brew官网上去申请含有classid的bid文件,以及.sig文件 2.根据申请到的bid文件重新生成mif文件. 3.将mif文件部署到brew真机上的mif文件夹下. 4.在真机上的bre ...
- mybatis由浅入深day02_9.3.5使用生成的代码_9.4逆向工程注意事项
9.3.5 使用生成的代码 需要将生成工程中所生成的代码拷贝到自己的工程中. 拷这4个到我们原来的spring_mybatis1216工程下 ItemsMapper.java package cn.i ...