时间是个常数,但也是个变数。勤奋的人无穷多,懒惰的人无穷少。——字严
今天中午午休抽时间写了个thymeleaf
和vue
使用elementUI
简单入门Demo
仓库地址:https://gitee.com/VampireAchao/simple-thymeleaf-html.git
前端代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| <!doctype html> <html> <head> <title>给胖哥的html页面</title> <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet"> </head>
<body>
<div id="app"> <el-button @click="openDialog">{{message}}</el-button> <el-dialog :visible.sync="visible" title="弹框标题"> <p>[[${paramFromServer}]]</p> </el-dialog> </div> </body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui@2.15.8/lib/index.js"></script> <script> new Vue({ el: '#app', data() { return { visible: false, message: '[[${message}]]' } }, methods: { openDialog() { this.visible = true; } } }) </script> </html>
|
启动类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package com.ruben.simplethymeleafhtml;
import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping;
@Controller @SpringBootApplication public class SimpleThymeleafHtmlApplication {
@Resource private HttpServletRequest request;
public static void main(String[] args) { SpringApplication.run(SimpleThymeleafHtmlApplication.class, args); }
@GetMapping("/") public String index() { request.setAttribute("paramFromServer", "我是controller中返回的值"); request.setAttribute("message", "我是后端返回的值"); return "index"; }
}
|
GAV
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ruben</groupId> <artifactId>simple-thymeleaf-html</artifactId> <version>0.0.1-SNAPSHOT</version> <name>simple-thymeleaf-html</name> <description>simple-thymeleaf-html</description>
<properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.3.7.RELEASE</spring-boot.version> </properties>
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.7.RELEASE</version> <configuration> <mainClass>com.ruben.simplethymeleafhtml.SimpleThymeleafHtmlApplication</mainClass> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
</project>
|