zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    第一部分 Linux的规划与安装
    第二部分 Linux 文件、目录与磁盘格式
    for in 遍历对象
    时间
    javaScript模块化
    Hbuilder将移动app或者web项目打包
    echarts的通用属性的介绍
    echart的x轴或y轴区间标签如何从大到小排列
    数组的sort()排序
    解决vscode下载很慢的问题
  • 原文地址:https://www.cnblogs.com/lichangyunnianxue/p/9670195.html
Copyright © 2011-2022 走看看