提交用例

This commit is contained in:
luoxiang
2018-12-31 18:51:18 +08:00
parent 85f4d1a591
commit 4484b8d2af
43 changed files with 1233 additions and 0 deletions

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.heibaiying</groupId>
<artifactId>spring-boot-tomcat</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-tomcat</name>
<description>boot-tomcat project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--排除依赖 使用外部tomcat容器启动-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!--使用外置容器时候SpringBootServletInitializer 依赖此包 -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,28 @@
package com.heibaiying.springboottomcat;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* 如果用外置tomcat,启动报错java.lang.NoClassDefFoundError: javax/el/ELManager
* 是因为tomcat 7.0 el-api包中没有ELManager类 , 切换tomcat 为8.0 以上版本即可
*/
@SpringBootApplication
public class SpringBootTomcatApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//传入SpringBoot应用的主程序
return application.sources(SpringBootTomcatApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringBootTomcatApplication.class, args);
}
}

View File

@ -0,0 +1,24 @@
package com.heibaiying.springboottomcat.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
/**
* @author : heibaiying
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Programmer {
private String name;
private int age;
private float salary;
private LocalDate birthday;
}

View File

@ -0,0 +1,24 @@
package com.heibaiying.springboottomcat.controller;
;
import com.heibaiying.springboottomcat.bean.Programmer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDate;
/**
* @author : heibaiying
*/
@Controller
@RequestMapping("index")
public class JspController {
@RequestMapping
public String jsp(Model model){
Programmer programmer = new Programmer("heibai", 21, 1298.31f, LocalDate.now());
model.addAttribute("programmer",programmer);
return "show";
}
}

View File

@ -0,0 +1,5 @@
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp

View File

@ -0,0 +1,13 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>programmer</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/show.css">
</head>
<body>
<ul>
<li>姓名: ${programmer.name}</li>
<li>年龄: ${programmer.age}</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,4 @@
li{
font-size: 30px;
color: blueviolet;
}

View File

@ -0,0 +1,17 @@
package com.heibaiying.springboottomcat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootTomcatApplicationTests {
@Test
public void contextLoads() {
}
}