用SpringBoot做一个web小案例环境搭建

前面我讲了四部分内容:springboot入门,springboot的配置相关知识点,springboot的视图模板引擎,springboot整合持久层框架

有了这些知识点,我们就可以来完成一个相对功能完整的增删改查的小案例了,这个案例我们把以前讲JavaWeb入门课程中的哪个例子重新写一遍,基本功能:登录,用户列表显示,用户信息的增删改查,用户的模糊查询等,选用的技术由springboot2.0.6做整合,thymeleaf模板引擎做视图,spring data jpa做持久层:

1、搭建开发环境,导入相应的启动器和jar包依赖


    org.springframework.boot
    spring-boot-starter-data-jpa


    org.springframework.boot
    spring-boot-starter-web


    org.springframework.boot
    spring-boot-starter-thymeleaf


    mysql
    mysql-connector-java
    runtime


    org.springframework.boot
    spring-boot-starter-test
    test

2、配置数据库基本信息,建立起项目的包结构,并创建model类

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/springbootdemo
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#sprigboot内部是使用springdata,springdata里的jpa是使用hibernate实现的
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
@Entity
@Table(name = "t_users")
public class User {
    private int id;
    private String username;
    private String pasword;
    private Date regDate;
    private Address address;

@Entity
@Table(name = "t_address")
public class Address {
    private int id;
    private String addressInfo;

3、把首页做成登录页面login.html的视图做出来

用SpringBoot做一个web小案例环境搭建_第1张图片

用户名:

密 码:

 

你可能感兴趣的:(Java,代码笔记,spring,boot,java,后端)