第一个SpringMVC程序 (注解版)
1.新建一个web项目
2.导入相关jar包
3.编写web.xml , 注册DispatcherServlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<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:springmvc-config.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>
</web-app>
4.编写springmvc配置文件
<?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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 自动扫描包,让指定包下的注解生效,由IOC容器统一管理 -->
<context:component-scan base-package="com.king.controller"/>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<!-- 视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
5.接下来就是去创建对应的控制类 , controller
package com.king.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/h1")
public String hello(Model model){
//封装数据
model.addAttribute("msg","HelloSpringMVC");
return "hello"; //会被视图解析器处理
}
}
6.最后完善前端视图和controller之间的对应
<%--
Created by IntelliJ IDEA.
User: KING
Date: 2020/5/24
Time: 14:52
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>
${msg}
</body>
</html>
7.测试运行调试.
第一个SpringMVC程序 (注解版)的更多相关文章
- 第一个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程序
可能之前写的文章走进SpringMVC世界,从SpringMVC入门到SpringMVC架构中的第一个springMVC入门程序讲解的不是那么优雅.细致.精巧,因此特地写这篇稍微优雅.细致.精巧一些的 ...
- SpringMVC_001 第一个SpringMVC程序
今天我们来学习第一个SpringMVC程序 一.配置开发方式 (1)首先建立一个SpringMVC web程序 (2)导入jar包 (3)建立UserController.java package ...
- ROS Learning-015 learning_tf(编程) 编写一个监听器程序 (Python版)
ROS Indigo learning_tf-02 编写一个 监听器 程序 (Python版) 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 1 ...
- SpringMVC学习02(我的第一个SpringMVC程序)
2.Hello,SpringMVC 2.1 配置版 1.新建一个Moudle , springmvc-02-hello , 添加web的支持! 2.确定导入了SpringMVC 的依赖! 3.配置we ...
- 1、第一个SpringMVC程序
1.创建如下项目结构 2.在src下的com.springmvc下创建User.java package com.springmvc; public class User { private Stri ...
- Servlet3.0整合Springmvc(注解版)
在创建maven的web工程时候,如果报错缺少web.xml 则在pom添加如下配置 : <build> <plugins> <plugin> <groupI ...
- 第一个SpringMVC的注解应用
由于默认的配置文件中支持了注解,所以可以直接编写注解的Controller 将ItcastController加入到SpringMVC容器中: 配置Controller的扫描包
随机推荐
- PG primary 和 slave 互换
http://blog.sina.com.cn/s/blog_544a710b0101a122.html http://blog.51cto.com/heyiyi/1898506 https://bl ...
- 201771010128王玉兰实验一软件工程准备——<阅读《构建之法——现代软件工程》初步了解软件工程>
|||||||||||||| |:--|:--| |项目|内容| |软件工程|https://www.cnblogs.com/nwnu-daizh/| |作业要求在博客里|https://www.cn ...
- CF #459 D. MADMAX
D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- POJ2516
题目链接:http://poj.org/problem?id=2516 解题思路: 最小费用最大流,这个没什么疑问.但此题小难点在于读题,大难点在于建图. 首先,供应量小于需求量的时候直接输出“-1” ...
- SXSSFWorkbook的简单使用
在工作中使用到SXSSFWorkbook来导出Excel,写一篇博客记录一下SXSSFWorkbook的使用方法 1.介绍 SXSSFWorkbook是属于apache基金会的Excel导出工具类,从 ...
- java颜色对照表
- 在Cent OS云服务器上部署基于TP5后端代码踩坑记录_艾孜尔江撰
推荐使用镜像安装Cent OS系统,或者在纯净安装完成之后在完成Apache+MySQL+PHP的时候不要每个单独安装,因为这样会出一些三者之间版本不配的问题,网上各种说法都有,查起来也非常困难,版本 ...
- async/await 内幕【译文】
C# Under the Hood: async/await 原文地址:https://www.markopapic.com/csharp-under-the-hood-async-await/ 前言 ...
- python2.7入门 01
进入python官网 http://www.python.org/download/ 下载python2.7.x 版 下载安装后配置环境变量 在path中——>>>把安装路 ...
- CSS 超出行显示...
一行超出 overflow:hidden; white-space:nowrap; text-overflow:ellipsis; 多行超出 overflow: hidden; text-overfl ...