1.SpringBoot+Thymeleaf+MySQL简单操作

0.结构

链接:https://pan.baidu.com/s/1FhoBoXgl1to1d65zv8eC1w
提取码:ivf3

1.SpringBoot+Thymeleaf+MySQL简单操作

1.pom.xml文件

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.5</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </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>

2.Mapper文件

@Repository
@Mapper
public interface PreregMapper {
    @Select("SELECT * FROM Prereg")
    List<Prereg> findAll();
}

3.Controller文件

@Controller
public class PreregController {

    @Autowired
    PreregMapper preregMapper;

    @RequestMapping("/listPrereg")
    public String listPrereg(Model model)
    {
        List<Prereg> preregs=preregMapper.findAll();
        model.addAttribute("preregs",preregs);
        return "listPrereg";
    }
}

4.Bean文件

public class Prereg {

        private String StuId;
        private String StuName;
        private String Trans;
        private int IsCompany;
        private int PeopleCount;
        private Date ArrTime;

        public String getStuId() {
            return StuId;
        }

        public void setStuId(String stuId) {
            StuId = stuId;
        }

        public String getStuName() {
            return StuName;
        }

        public void setStuName(String stuName) {
            StuName = stuName;
        }

        public String getTrans() {
            return Trans;
        }

        public void setTrans(String trans) {
            Trans = trans;
        }

        public int getIsCompany() {
            return IsCompany;
        }

        public void setIsCompany(int isCompany) {
            IsCompany = isCompany;
        }

        public int getPeopleCount() {
            return PeopleCount;
        }

        public void setPeopleCount(int peopleCount) {
            PeopleCount = peopleCount;
        }

        public Date getArrTime() {
            return ArrTime;
        }

        public void setArrTime(Date arrTime) {
            ArrTime = arrTime;
        }

        @Override
        public String toString() {
            return "Prereg{" +
                    "StuId=‘" + StuId + ‘\‘‘ +
                    ", StuName=‘" + StuName + ‘\‘‘ +
                    ", Trans=‘" + Trans + ‘\‘‘ +
                    ", IsCompany=" + IsCompany +
                    ", PeopleCount=" + PeopleCount +
                    ", ArrTime=" + ArrTime +
                    ‘}‘;
        }


}

5.HTML文件

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>springboot-thymeleaf demo</title>
</head>
<body>
<table border="1" width="1000">
    <thead>
    <tr>
        <td>学生学号</td>
        <td>学生姓名</td>
        <td>到达时间</td>
        <td>家人陪伴</td>
        <td>陪伴数量</td>
        <td>交通工具</td>
    </tr>
    </thead>
    <tr th:each="item,eee: ${preregs}">
    <td th:text="${item.stuId}"></td>
    <td th:text="${item.stuName}"></td>
    <td th:text="${item.arrTime}"></td>
    <td th:text="${item.isCompany}"></td>
    <!--<td th:text="${item.peopleCount}"></td>-->
    <td>[[${item.peopleCount}]]</td>
    <td th:text="${item.trans}"></td>
</tr>

</table>
</body>
</html>
</html>

6.application.properties

#数据库配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
# 非Mysql8.0请改为com.mysql.jdbc.Driver
spring.datasource.driver-class-name=com.mysql.jdbc.Driver       

7.数据库内容,运行结果

1.SpringBoot+Thymeleaf+MySQL简单操作

1.SpringBoot+Thymeleaf+MySQL简单操作

分手后的第一个博客,不想写字,就这样吧,哎

                          

相关推荐