如果HelloWorld都没有实现的同学,建议先学习HelloWorld!
Spring Boot (一)
http://blog.csdn.net/yioow/article/details/78614782
1. 在pom.xml里的<dependencies>加入配置
<!-- Starter for building MVC web applications using FreeMarker views -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
2. 新建文件
src/main/java
+- com
+- test
+- springBoot
+- controller
+- LoginController.java
+- entity
+- mapper
+- services
+- Application.java
src/main/resources
+- application.yml
webapp
+- WEB-INF
+- jsp
+- login
+- login.jsp
1. 新建application.yml ,配置视图前缀后缀(当然你也可以是properties文件)
SpringBoot默认从application.properties和application.yml 文件里读取配置
yml文件的优点就是在写的时候层次感强,而且少写了代码。所以现在很多人都使用yml配置文件 ^-^
yml文件的写法
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
properties文件的写法
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
2.编写LoginController.java和login.jsp
这个我就不做解释了,大家都懂
LoginController.java
package com.test.springBoot.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/login")
public class LoginController {
private static final String LANDING_PAGE_VIEW = "login/login";
/**
* 登陆页
*/
@RequestMapping("/home")
public ModelAndView LandingPage(ModelAndView mav, HttpServletRequest req, HttpServletResponse res, HttpSession ses) {
mav.setViewName(LANDING_PAGE_VIEW);
return mav;
}
}
login.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=utf-8">
<title>登陆页</title>
</head>
<body>
<form action="">
用户名:<input type="text" name="userName"><br>
密码:<input type="password" name="password">
</form>
</body>
</html>
3.在浏览器输入http://localhost:8080/login/home
Good Luck!