0依赖

<!-- jsp -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency> 

1、添加代码式注解,配置springmvc

@Configuration
public class SpringMvcConfigure extends WebMvcConfigurerAdapter { @Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
// viewResolver.setViewClass(JstlView.class); // 这个属性通常并不需要手动配置,高版本的Spring会自动检测
return viewResolver;
} }

  

2、创建mvc的controller

@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView hello() {
ModelAndView mv = new ModelAndView();
mv.addObject("msg", "this a msg from HelloWorldController");
mv.setViewName("helloworld");
return mv;
} }

3、根据代码式注解创建jsp所在目录以及文件

src/main/webapp/WEB-INF/jsp/helloworld.jsp(创建webapp目录可以参见另一随笔)

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
1
</body>
</html>

  

4、访问http://localhost:8080/hello

springboot-springmvc的更多相关文章

  1. springboot+springmvc+mybatis项目整合

    介绍: 上篇给大家介绍了ssm多模块项目的搭建,在搭建过程中spring整合springmvc和mybatis时会有很多的东西需要我们进行配置,这样不仅浪费了时间,也比较容易出错,由于这样问题的产生, ...

  2. SpringBoot+SpringMVC+MyBatis快速整合搭建

    作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...

  3. springboot+springmvc拦截器做登录拦截

    springboot+springmvc拦截器做登录拦截 LoginInterceptor 实现 HandlerInterceptor 接口,自定义拦截器处理方法 LoginConfiguration ...

  4. SpringBoot/SpringMVC文件下载方式

    本篇文章引用外网博客代码,共描述SpringMVC下三种文件下载方式,本人测试在SpringBoot(2.0以上版本)正常使用. 引用博客,强烈推荐https://www.boraji.com. pa ...

  5. springboot springmvc 支持 https

    Spring Mvc和Spring Boot配置Tomcat支持Https 背景 最近在项目开发中需要让自己的后端Restful接口支持https,在参考了很多前辈们的博客后总结了一些. Spring ...

  6. springboot springmvc 抛出全局异常解决方法

    springboot中抛出异常,springboot自带的是springmvc框架,这个就不多说了. springmvc统一异常解决方法这里要说明的是.只是结合了springboot的使用而已.直接上 ...

  7. CAS5.3 单点登录/登出/springboot/springmvc

    环境: jdk:1.8 cas server:5.3.14 + tomcat 8.5 cas client:3.5.1 客户端1:springmvc 传统web项目(使用web.xml) 客户端2:s ...

  8. SpringBoot,SpringMvc, SpringCloud

    1,SpringBoot VS SpringMvc VS SpringBoot SpringBoot: SpringBoot 是一个快速开发的框架,能够快速的整合第三方框架,简化XML配置,全部采用注 ...

  9. spring-boot spring-MVC自动配置

    Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:==(WebMvcAuto ...

  10. SpringBoot+springmvc异步处理请求

    有两种情况,第一种是业务逻辑复杂,但不需要业务逻辑的结果,第二种是需要返回业务逻辑的处理结果 第一种比较简单,利用多线程处理业务逻辑,或者利用spring中@Asyn注解更简单, 使用@Asyn注解, ...

随机推荐

  1. Redis长短链接的区别

    本文介绍了phpredis中与redis建立连接的两种方式:connect(短连接)和pconnect(长连接)的区别. 问题背景: 项目采用LNMP架构,考虑到数据访问性能问题,因此使用redis来 ...

  2. stat /var/lib/docker/tmp/docker-builder234542842/usr/local/resource/noah_init.sql

    参考:https://blog.csdn.net/andrew_wf/article/details/85202511 将noah_init.sql放到与Dockerfile同一目录

  3. 《黑白团团队》第九次团队作业:Beta冲刺第一天

    项目 内容 作业课程地址 任课教师首页链接 作业要求 团队项目 填写团队名称 黑白团团队 填写具体目标 认真负责,完成项目 团队项目Github仓库地址链接. 第一天 日期:2019/6/24 1.1 ...

  4. 1.安装Loucust

    python 3.x 通过pip安装: pip install locustio 如果是以分布式队列运行locust,需要装一种通信队列的库pyzmq  :pip install pyzmq 安装成功 ...

  5. [NOI2008]假面舞会——数论+dfs找环

    原题戳这里 思路 分三种情况讨论: 1.有环 那显然是对于环长取个\(gcd\) 2.有类环 也就是这种情况 1→2→3→4→5→6→7,1→8→9→7 假设第一条链的长度为\(l_1\),第二条为\ ...

  6. appium+python 【Mac】UI自动化测试封装框架介绍 <二>---脚本编写(单设备)

    1.单设备的执行很简单,平时可多见的是直接在config中进行配置并进行运行即可.如下: # coding=UTF- ''' Created on // @author: SYW ''' from T ...

  7. .net System.Net.Mail 之用SmtpClient发送邮件Demo

    private static bool sendMail()     {     try    {     //接收人邮箱    string SendTo = "XXXXX@163.com ...

  8. vue 日期格式化过滤器

    formateDate日期格式化,写在公共的js中: export function formateDate(date, fmt){ if ('/(y+)/'.test(fmt){ fmt = fmt ...

  9. PHP mysqli_get_client_info() 函数

    定义和用法 mysqli_get_client_info() 函数返回 MySQL 客户端库版本. <?php echo mysqli_get_client_info(); ?>

  10. 014_linuxC++之_不同类型的继承

    #include <iostream> #include <string.h> #include <unistd.h> using namespace std; c ...