博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用vue中的axios请求后台(springboot工程)
阅读量:3961 次
发布时间:2019-05-24

本文共 4303 字,大约阅读时间需要 14 分钟。

目录

1.项目结构

在这里插入图片描述

2.pom

4.0.0
com.wo
vue_first
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-test
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-data-jpa
org.projectlombok
lombok
true

3.application.yml

server:  port: 8080spring:  datasource:    driver-class-name: com.mysql.jdbc.Driver    username: root    password: 123456    url: jdbc:mysql://localhost:3306/qf?useUnicode=true&characterEncoding=utf8&useSSL=false  jpa:    database: MYSQL    generate-ddl: true    show-sql: true

4.controller

@RestControllerpublic class StudentController {
@Autowired StudentService studentService; @RequestMapping("/findAll") public List
findAll(){
return studentService.findAll(); } @RequestMapping("/saveAndUpdate") public String saveAndUpdate(@RequestBody TbStudent tbStudent){
try {
studentService.saveAndUpdateStudent(tbStudent); }catch (Exception ex){
return "fail"; } return "success"; } @RequestMapping("/findById") public TbStudent findById(@RequestBody Map map){
String id = (String) map.get("id"); return studentService.findById(Integer.valueOf(id)); } @RequestMapping("/del") public void del(@RequestBody Map map){
Integer id = (Integer) map.get("id"); studentService.deleteById(Integer.valueOf(id)); }}

5.dao

public interface StudentRespository extends JpaRepository
{
}

6.pojo

@Data@Entity@Table(name = "Tb_sys_student")public class TbStudent {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id ; private String name; private Integer age; private Integer sex; private String address;}

7.service

public interface StudentService {
List
findAll(); TbStudent findById(Integer id); void saveAndUpdateStudent(TbStudent tbStudent); void deleteById(Integer integer);}
@Servicepublic class StudentServiceImpl implements StudentService {
@Autowired StudentRespository studentRespository; @Override public List
findAll() {
return studentRespository.findAll(); } @Override public TbStudent findById(Integer id) {
return studentRespository.findById(id).get(); } @Override public void saveAndUpdateStudent(TbStudent tbStudent) {
studentRespository.saveAndFlush(tbStudent); } @Override public void deleteById(Integer integer) {
studentRespository.deleteById(integer); }}

8.启动类

@SpringBootApplicationpublic class VueApplication {
public static void main(String[] args) {
SpringApplication.run(VueApplication.class); }}

9.页面

9.1 index.html

    
Title
序号 学生姓名 学生年龄 学生性别 学生住址 操作
{
{
index+1}}
{
{
student.name}}
{
{
student.age}}
{
{
student.sex==0?'女':'男'}}
{
{
student.address}}

9.2 insert.html

    
Title
姓名:
年龄:
性别:
地址:

9.3 update.html

    
Title
姓名:
年龄:
性别:
地址:

转载地址:http://tcezi.baihongyu.com/

你可能感兴趣的文章
eclipse+ADT 进行android应用签名详解
查看>>
Robotium只有apk文件例如Music.apk
查看>>
UI自动化测试框架对比(二)
查看>>
Selenium-webdriver系列教程(9)——如何操作select下拉框
查看>>
Selenium-webdriver系列教程(10)——如何智能的等待页面加载完成
查看>>
Robotium测试NotePad(一)
查看>>
Robotium测试NotePad(二) //测试添加文本
查看>>
Robotium测试NotePad(二) //测试删除文本
查看>>
Robotium只有apk文件时进行测试
查看>>
Robotium测试NotePad(三) //测试修改文本
查看>>
怎样有效降低测试的轮次?
查看>>
功能测试用例设计策略
查看>>
真正优秀的质量工程师,都有这些特质
查看>>
JIRA与confluence的用户整合
查看>>
Robotium测试——API介绍
查看>>
autoit3——打开窗口
查看>>
autoit3 ie.au3 函数之——ControlClick
查看>>
autoit3 ie.au3 函数之——_FileWriteLog日志
查看>>
转:Android自动化压力测试工具Monkey——测试例子
查看>>
Robotium测试之——获取当前屏幕的大小
查看>>