2019独角兽企业重金招聘Python工程师标准>>>
1.pom.xml文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
2.application.yml文件
server:
port: 8383
spring:
datasource:
url: jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&autoReconnect=true
username: upgrade
password: upgrade
driverClassName: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
thymeleaf:
cache: false
suffix: .html
encoding: UTF-8
prefix: classpath:/templates/
logging:
level.com.test.data: debug
3.index.html文件
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>
thymedef简单练习
</title>
</head>
<body>
<div>
<span>ID:</span>
<button>${user.id}</button>
</div>
<div>
<span>姓名:</span>
<button>${user.userName}</button>
</div>
</body>
</html>
4.controller文件
package com.test.data.controller;
import com.test.data.model.User;
import com.test.data.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
import java.util.List;
/**
* Created by guanguan on 2017/7/20.
*/
@Controller
public class controller {
@Autowired
UserService userService;
@RequestMapping("/")
public String index(ModelMap model){
HashMap<String,Object> params= new HashMap<String, Object>();
List<User> userList= userService.findBy(params);
model.addAttribute("user",userList.get(0));
return "index";
}
}
运行结果如下: