springboot-springmvc
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的更多相关文章
- springboot+springmvc+mybatis项目整合
介绍: 上篇给大家介绍了ssm多模块项目的搭建,在搭建过程中spring整合springmvc和mybatis时会有很多的东西需要我们进行配置,这样不仅浪费了时间,也比较容易出错,由于这样问题的产生, ...
- SpringBoot+SpringMVC+MyBatis快速整合搭建
作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...
- springboot+springmvc拦截器做登录拦截
springboot+springmvc拦截器做登录拦截 LoginInterceptor 实现 HandlerInterceptor 接口,自定义拦截器处理方法 LoginConfiguration ...
- SpringBoot/SpringMVC文件下载方式
本篇文章引用外网博客代码,共描述SpringMVC下三种文件下载方式,本人测试在SpringBoot(2.0以上版本)正常使用. 引用博客,强烈推荐https://www.boraji.com. pa ...
- springboot springmvc 支持 https
Spring Mvc和Spring Boot配置Tomcat支持Https 背景 最近在项目开发中需要让自己的后端Restful接口支持https,在参考了很多前辈们的博客后总结了一些. Spring ...
- springboot springmvc 抛出全局异常解决方法
springboot中抛出异常,springboot自带的是springmvc框架,这个就不多说了. springmvc统一异常解决方法这里要说明的是.只是结合了springboot的使用而已.直接上 ...
- 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 ...
- SpringBoot,SpringMvc, SpringCloud
1,SpringBoot VS SpringMvc VS SpringBoot SpringBoot: SpringBoot 是一个快速开发的框架,能够快速的整合第三方框架,简化XML配置,全部采用注 ...
- spring-boot spring-MVC自动配置
Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:==(WebMvcAuto ...
- SpringBoot+springmvc异步处理请求
有两种情况,第一种是业务逻辑复杂,但不需要业务逻辑的结果,第二种是需要返回业务逻辑的处理结果 第一种比较简单,利用多线程处理业务逻辑,或者利用spring中@Asyn注解更简单, 使用@Asyn注解, ...
随机推荐
- CentOS 6 多实例 编译安装mariadb-5.5.59
系统平台: CentOS release 6.9 (Final) 内核 2.6.32-696.el6.x86_64 1.去官网下载适合的源码包 http://mariadb.org/ mariadb- ...
- apply, bind, call--绑定this的方法
Function.prototype.call(),Function.prototype.apply(),Function.prototype.bind() 是三种改变函数内部this指向(即函数执行 ...
- 多线程 submit与execute区别
(1)可以接受的任务类型 submit: execute: 可以看出: execute只能接受Runnable类型的任务 submit不管是Runnable还是Callable类型的任务都可以接受,但 ...
- kubernetes Configmap secret的使用
kubernetes configmap 核心作用是让配置信息和镜像解耦,pod可以使用configmap的数据生成配置文件.如果后端的pod配置文件要改变时,只需要更改下configmap里面的数据 ...
- frontEnd(前端基础)
第一章:前端概述 第二章:前端三剑客 第三章:第一个页面 第四章:html常用标签 第五章:标签分类 第六章:css三种引入方式 第七章:样式与长度颜色 第八章:常用样式 第九章:CSS选择器 第十章 ...
- 关于tensorflow里面的tf.contrib.rnn.BasicLSTMCell 中num_units参数问题
这里的num_units参数并不是指这一层油多少个相互独立的时序lstm,而是lstm单元内部的几个门的参数,这几个门其实内部是一个神经网络,答案来自知乎: class TRNNConfig(obje ...
- java中的变量和数据类型
变量和javascript的变量含义一样 在Java中,变量分为两种:基本类型的变量和引用类型的变量.(javascript中同样是这样的) 基本数据类型 基本数据类型是CPU可以直接进行运算的类型. ...
- import torch错误解决
import torch出现 ”from torch._C import * ImportError: DLL load failed: 找不到指定的模块“错误这里torch=1.0.1,torchv ...
- Python基础之深浅copy
1. 赋值 lst1 = [1, 2, 3, ["a", "b", "c"]] lst2 = lst1 lst1[0] = 11 print ...
- tomcat在浏览器输入用户名和密码后报错Tomcat Manager App--403 Access Denied You are not authorized to view this page
报错截图:Tomcat Manager App--403 Access Denied You are not authorized to view this page 解决办法: 1.关闭Tomcat ...