码迷,mamicode.com
首页 > 编程语言 > 详细

springboot-springmvc

时间:2018-09-18 19:21:48      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:end   world   source   type   www.   ext   iso   java   main   

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/app/WEB-INF/jsp/helloworld.jsp

<%@ 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>
123
</body>
</html>

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

 

springboot-springmvc

标签:end   world   source   type   www.   ext   iso   java   main   

原文地址:https://www.cnblogs.com/lichangyunnianxue/p/9670195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!