vue-项目的整体增删改查
Dept:
package com.example.demo.gs; public class Dept {
private int id;
private String name;
private String location;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
@Override
public String toString() {
return "Dept [id=" + id + ", name=" + name + ", location=" + location + "]";
} }
DeptMapper:
package com.example.demo; import java.util.List; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.w3c.dom.ls.LSOutput; import com.example.demo.gs.Dept; @Mapper
public interface DeptMapper { @Select("select * from dept")
List<Dept>select(); @Insert("insert into `dept`(name,location)values(#{name},#{location})") void Insert (String name,String location); @Select("select * from dept where id =#{id}") List<Dept>selectFrom(int id); @Update("update `dept` set location =#{location}where location=#{OldLocation}") void updateFromLocation(String location,String OldLocation); @Delete("delete from dept where location =#{location}") void deleteFromDept(String location); }
ServeMapper
package com.example.demo; import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.example.demo.gs.Dept; @Service
public interface DeptService { List<Dept>selectFromService(); void Insert(Dept dept); List<Dept>selectFromId(int id); void updateFromLocation(String location ,String oldLocation); void Delete(String location); }
DeptServiceImplement:
package com.example.demo.gs; import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.example.demo.DeptMapper;
import com.example.demo.DeptService; @Service
public class DeptServiceImplement implements DeptService {
@Autowired
private DeptMapper Mapper; @Transactional
@Override
public List<Dept> selectFromService() {
// TODO Auto-generated method stub
return this.Mapper.select();
} @Transactional
@Override
public void Insert(Dept dept) {
this.Mapper.Insert(dept.getName(),dept.getLocation()); // TODO Auto-generated method stub } @Transactional
@Override
public List<Dept> selectFromId(int id) {
// TODO Auto-generated method stub
return this.Mapper.selectFrom(id);
} @Transactional
@Override
public void updateFromLocation(String location ,String oldLocation) {
this.Mapper.updateFromLocation(location, oldLocation); } @Transactional
@Override
public void Delete(String location ) {
this.Mapper.deleteFromDept(location);
System.out.println(location);
} }
DeptContorller
package com.example.demo.gs; import java.util.List; import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.example.demo.DeptService; @RestController
public class DeptContorller { @Autowired
private DeptService Service; @GetMapping("/select")
@ResponseBody
List<Dept>Select(){
List<Dept> userDepts =this.Service.selectFromService();
return userDepts; } @GetMapping("/delete")
@ResponseBody
List<Dept>delete(int id) {
return this.Service.selectFromId(id);
} @PostMapping("/Insert")
@ResponseBody
void Insert(@RequestBody Dept dept) {
this.Service.Insert(dept); } @GetMapping("/Deletes")
@ResponseBody
void Deletes(String location){
this.Service.Delete(location);
System.out.println(location); } @GetMapping("/Update")
@ResponseBody
void Update(String location ,String OldLocation){
this.Service.updateFromLocation(location, OldLocation); }
}
路由:
import Vue from "vue";
import VueRouter from "vue-router";
import SelectView from "../components/SelectView.vue";
import SelectFromView from "../components/SelectFromView.vue";
import InsertView from "../components/InsertView.vue";
import DeleteView from "../components/DeleteView.vue";
import UpdateView from "../components/UpdateView.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Select",
component: SelectView,
},
{
path: "/1",
name: "Delete",
component: SelectFromView,
},
{
path: "/2",
name: "Insert",
component: InsertView,
},
{
path: "/3",
name: "DeleteView",
component: DeleteView,
},
{
path: "/4",
name: "UpdateView",
component: UpdateView,
},
];
const router = new VueRouter({
routes,
});
export default router;
<template>
<div class="nav">
<!-- <button @click="inserts()">查询</button> -->
<el-button size="small" @click="inserts()" type="primary">查询</el-button>
<div class="navs">
<!-- ------------------- -->
<div v-for="item in count" :key="item.id">
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="账号" width="180">
<span>{{ item.id }}</span>
</el-table-column>
<el-table-column prop="name" label="部门" width="180">
<span>{{ item.location }}</span>
</el-table-column>
<el-table-column prop="address" label="名字">
<span>{{ item.name }}</span>
</el-table-column>
</el-table>
</div>
</div>
</div>
<!-- </div> -->
</template>
<script>
import axios from "axios";
export default {
name: "LoginView",
data() {
return {
count: [],
tableData: [
{
date: "2016-05-02",
name: "王小虎",
address: "上海市普陀区金沙江路 1518 弄",
},
],
};
},
methods: {
inserts() {
axios.get("http://localhost:8086/select/").then((result) => {
console.log(result.data);
this.count = result.data;
});
},
},
};
</script>
<style>
label {
font-size: 20px;
font-weight: 700;
}
.navs {
margin-top: 10px;
}
-- > -- > .nav {
border-top: 3px solid #ff8500;
background-color: #fcfcfc;
border-bottom: 1px solid #edeeed;
line-height: 41px;
}
.nav a {
display: inline-block;
height: 41px;
padding: 0px 10px;
font-size: 15px;
color: #4c4c4c;
font-family: "微软雅黑";
text-decoration: none;
}
.nav a:hover {
background: #edeeed;
color: #ff8500;
}
</style>
<template>
<div class="nav">
<label for="#">查询账号:</label>
<!-- <input v-model="count" type="text" /> -->
<el-input
size="small"
style="width: 150px"
v-model="count"
placeholder="请输入内容"
></el-input>
<div v-for="item in name" :key="item.id">
<div class="navs">
<label for="#">账号:</label>
<span>{{ item.id }}</span
> <label for="#">部门:</label>
<span>{{ item.location }}</span
> <label for="#">名字:</label>
<span>{{ item.name }}</span>
</div>
</div>
<!-- <button @click="Delete()">查询</button> -->
<el-button
style="margin-left: 12px"
size="medium"
@click="Delete()"
type="success"
>查询</el-button
>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "DleteView",
data() {
return {
count: [],
name: [],
};
},
methods: {
Delete() {
axios({
// 请求方式
method: "GET",
// 请求地址
url: `http://localhost:8086/delete`,
// URL中的查询参数
params: {
id: this.count,
},
}).then((result) => {
console.log(result.data);
this.name = result.data;
});
},
},
};
</script>
<style>
label {
color: #303133;
}
.nav {
margin-top: 20px;
border-top: 3px solid #ff8500;
background-color: #fcfcfc;
border-bottom: 1px solid #edeeed;
line-height: 41px;
}
.nav a {
display: inline-block;
height: 41px;
padding: 0px 10px;
font-size: 15px;
color: #4c4c4c;
font-family: "微软雅黑";
text-decoration: none;
}
.nav a:hover {
background: #edeeed;
color: #ff8500;
}
</style>
<template>
<div class="nav">
<label for="name">名称:</label
><input class="inps" v-model="name" type="text" />
<label for="location">部门:</label
><input class="inps" v-model="location" type="text" />
<br />
<input value="增加" @click="Insert()" type="button" />
<h4 v-if="font === 4">成功</h4>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "LoginView",
data() {
return {
name: "",
location: "",
font: "",
};
},
methods: {
Insert() {
axios({
// 请求方式/
method: "POST",
// 请求地址
url: "http://localhost:8086/Insert",
data: {
name: this.name,
location: this.location,
},
// URL中的查询参数
}).then((res) => {
console.log(res);
this.font = 4;
});
},
},
};
</script>
<style>
label {
font-size: 20px;
font-weight: 700;
}
.inps {
margin-left: 20px;
margin-right: 20px;
}
.nav {
border-top: 3px solid #ff8500;
background-color: #fcfcfc;
border-bottom: 1px solid #edeeed;
line-height: 41px;
}
.nav a {
display: inline-block;
height: 41px;
padding: 0px 10px;
font-size: 15px;
color: #4c4c4c;
font-family: "微软雅黑";
text-decoration: none;
}
.nav a:hover {
background: #edeeed;
color: #ff8500;
}
</style>
根据部门进行删除:
<template>
<div class="nav">
<label for="#">部门名称:</label>
<input v-model="location" type="text" />
<el-button size="small" @click="Deletes()" type="primary">删除</el-button>
<!-- <input @click="Deletes()" value="删除" type="button" /> -->
<h4 v-if="font === 4">成功,但不晓得你数据库有没有这个数据;</h4>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "DeleteView",
data() {
return {
location: "",
font: [],
};
},
methods: {
Deletes() {
axios({
// 请求方式
method: "GET",
// 请求地址
url: `http://localhost:8086/Deletes`,
// URL中的查询参数
params: {
location: this.location,
},
}).then((sta) => {
console.log(sta);
this.font = 4;
});
},
},
};
</script>
<style>
label {
font-size: 20px;
font-weight: 700;
}
.navs {
margin-top: 10px;
}
.nav {
margin-top: 10px;
border-top: 3px solid #ff8500;
background-color: #fcfcfc;
border-bottom: 1px solid #edeeed;
line-height: 41px;
}
.nav a {
display: inline-block;
height: 41px;
padding: 0px 10px;
font-size: 15px;
color: #4c4c4c;
font-family: "微软雅黑";
text-decoration: none;
}
.nav a:hover {
background: #edeeed;
color: #ff8500;
}
</style>
修改部门名称:
<template>
<div class="nav">
<label for="">新部门</label><input v-model="location" type="text" />
<label for="">旧部门</label><input v-model="OldLocation" type="text" />
<input @click="Updata()" value="更改" type="button" />
<h4 v-if="font === 4">更改成功,但是不晓得你数据库有没有前置部门条件;</h4>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "UpdateView",
data() {
return {
location: [],
OldLocation: [],
font: [],
};
},
methods: {
Updata() {
axios({
// 请求方式
method: "GET",
// 请求地址
url: `http://localhost:8086/Update`,
// URL中的查询参数
params: {
location: this.location,
OldLocation: this.OldLocation,
},
}).then((res) => {
console.log(res);
this.font = 4;
});
},
},
};
</script>
<style>
label {
font-size: 20px;
font-weight: 700;
margin-left: 10px;
margin-right: 10px;
}
input {
margin-left: 10px;
margin-right: 10px;
}
.navs {
margin-top: 10px;
}
.nav {
border-top: 3px solid #ff8500;
background-color: #fcfcfc;
border-bottom: 1px solid #edeeed;
line-height: 41px;
}
.nav a {
display: inline-block;
height: 41px;
padding: 0px 10px;
font-size: 15px;
color: #4c4c4c;
font-family: "微软雅黑";
text-decoration: none;
}
.nav a:hover {
background: #edeeed;
color: #ff8500;
}
</style>
vue-项目的整体增删改查的更多相关文章
- vue实战(一):利用vue与ajax实现增删改查
vue实战(一):利用vue与ajax实现增删改查: <%@ page pageEncoding="UTF-8" language="java" %> ...
- django之创建第8-1个项目-数据库之增删改查/数据库数据显示在html页面
1.为test.DB数据库预先创建下面数据 1 张三 16 2015-01-02 12 李四 17 2015-01-04 13 王五 14 ...
- vue+express+mongodb 实现 增删改查
一.创建一个vue项目 用脚手架vue-cli搭建一个项目,数据请求用axios方式,写几个按钮用来调接口(vue这块不做多解释,不懂的可以先去官网学习vue-cli:https://cli.vuej ...
- Asp.net WebApi 项目示例(增删改查)
1.WebApi是什么 ASP.NET Web API 是一种框架,用于轻松构建可以由多种客户端(包括浏览器和移动设备)访问的 HTTP 服务.ASP.NET Web API 是一种用于在 .NET ...
- vue实现数据的增删改查
在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...
- 利用idea创建一个基本的smm项目(带增删改查)
环境 idea jdk1.8 tomcat mysql 打开idea选择创建一个maven项目 然后点击next,next,finsh 然后看项目的结构 如图所示 接着创建com包,再在com ...
- Django项目----快速实现增删改查组件(起步阶段!!!)
一.相关知识点回顾 1.什么是反射? 可以用字符串的方式去访问对象的属性 2.反射有四种方法? hasattr(object,name):判断一个对象是不是有name属性或者方法 getattr: ...
- JPA-day02 项目结构 编写增删改查测试类
- 一个完整的mybatis项目,包含增删改查
1.导入jar包,导入相关配置文件,均在自己博客园的文件中 编写mybatis.xml文件 <?xml version="1.0" encoding="UTF-8& ...
随机推荐
- JS的简介
JS式JavaScript的简称,它是一门弱语言,它可以实现让网页动起来 JS的构成 核心(ECMAScript) 文档对象模型(DOM)-- Document Object Module 浏览器对 ...
- 论文解读(PairNorm)《PairNorm: Tackling Oversmoothing in GNNs》
论文信息 论文标题:PairNorm: Tackling Oversmoothing in GNNs论文作者:Lingxiao Zhao, Leman Akoglu论文来源:2020,ICLR论文地址 ...
- 【Java】学习路径60-利用TCP协议接收多个客户端的数据
import java.io.IOException; import java.net.*; public class TCP_Server { public static void main(Str ...
- 域名+端口号 访问minio服务问题
业务上需要用到分布式文件服务,选择了minio作为文件服务的组件,搭建好服务后使用IP+端口号(http://xx.xx.xx.xx:9001)的形式访问在所有环境下都没有问题. 上线部署时出于正规和 ...
- Java-随机数据生成器(造数据)
概述 简单易用的随机数据生成器.一般用于开发和测试阶段的数据填充.模拟.仿真研究.演示等场景.可以集成到各种类型的java项目中使用. 优点 非常轻量级(不到1M),容易集成,无需过多第三方依赖 简单 ...
- WebGPU实现Ray Packet
大家好~本文在如何用WebGPU流畅渲染百万级2D物体?基础上进行优化,使用WebGPU实现了Ray Packet,也就是将8*8=64条射线作为一个Packet一起去访问BVH的节点.这样做的好处是 ...
- 第四十四篇:Git分支(关键知识点)
好家伙, GIT分支 分支就像是平行宇宙,两个平行宇宙自己平行,不相干扰,平安无事, 某一天它想不开,合并了.然后就变成了我写这篇博客的动机了. 1.关于Git分支中常用的指令 列出所有分支 git ...
- Vmware虚拟主机启动卡死问题解决
记录一次虚拟主机开机卡死,黑屏,无法操作的问题 一.问题现象 1.在vmware上新建数台主机后,第一次启动都正常,部分主机出现关机后再开机(或直接重启)卡死的情况: 2.在vmware上右键菜单栏均 ...
- omc.
OMC 099(4b) D 因为 \((abc)^{\dfrac 13} \le \dfrac{a+b+c}3\)(基本不等式),将 \(a = xy, b = yz, c = xz\) 代入得到 \ ...
- docker_命令总结
docker -v /hostDir:/containerDir /hostDir为宿主机的目录 /containerDir为容器内的目录 -v 实现两个目录的挂在,即容器内数据持久化到本机 dock ...