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

  • 相关阅读:
    使用Java发送qq邮件
    docker部署nacos1.4
    职责链模式
    策略模式
    状态模式
    解释器模式
    备忘录模式
    js中数组常用方法总结
    微信小程序生成二维码工具
    小程序登录过程
  • 原文地址:https://www.cnblogs.com/lichangyunnianxue/p/9670195.html
Copyright © 2011-2022 走看看