标签: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
标签:end world source type www. ext iso java main
原文地址:https://www.cnblogs.com/lichangyunnianxue/p/9670195.html