axios的综合案例
需求:
- 用户发起请求:http://localhost:8080/vue/findAll,获取所有的user数据
- 通过Vue.js 要求在页面中展现数据,以表格的形式展现
- 为每行数据添加 修改/删除 的按钮
- 在一个新的div中编辑3个文本框 name/age/sex 通过提交按钮实现新增
- 如果用户点击修改按钮,则在全新的div中,回显数据
- 用户修改完成数据之后,通过提交按钮,实现数据的修改
- 当用户点击删除按钮时,要求实现数据的删除操作
1. 创建springboot项目,并导入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
</dependencies>
2. 配置类
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/jt?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&autoReconnect=true&allowMultiQueries=true
username: root
password: 123456
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
mapper-locations: classpath:/mappers/*.xml
type-aliases-package: com.jt.pojo
logging:
level:
com.jt.mapper: debug
3. 启动类
package com.jt;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.jt.mapper")
public class RunApp {
public static void main(String[] args) {
SpringApplication.run(RunApp.class, args)