一、xml映射语句
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wzh.finalwork.Mapper.ComponentMapper">
<select id="selectall" resultType="com.liuxiaocan.finalwork.Pojo.Component">
select * from component
</select>
<select id="SelectPart" resultType="com.liuxiaocan.finalwork.Pojo.Component">
select * from component where CNo=#{cno}
</select>
<update id="Update" >
update Component set CName=#{cname},CSize=#{csize},CPrice=#{cprice},CText=#{ctext} where CNo=#{cno}
</update>
<insert id="Insert">
insert into Component values (#{cno},#{cname},#{csize},#{cprice},#{ctext})
</insert>
<delete id="Delete">
delete from Component where CNo=#{cno}
</delete>
</mapper>
二、动态sql语句
<template slot-scope="scope">
<el-button
size="mini"
type="success"
@click="handleEdit(scope.row)">编辑</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div style="width: 80%;margin: auto;margin-top: 10px" ><el-button type="primary" plain v-on:click="JumpOff">添加零件</el-button>
<el-button type="danger" plain v-on:click="deleteall">批量删除</el-button>
</div>
<div style="text-align: center">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-sizes="[5, 10, 15, 20,25]"
:page-size="pageSize"
layout="sizes, prev, pager, next"
:total="total">
</el-pagination>
</div>
</div>
<script>
new Vue({
el:"#app",
data(){
return{
ComponentData:[],
search:'',
currentPage: 1,// 当前页码
pageSize:5,
total:100,
index:'',
form:{
cno:'',
cname:'',
csize:''
},
multipleSelection: [],
List:[]
}
},
methods:{
handleEdit(row) {
window.location.href="update.html?con="+row.cno;
},
handleDelete(row) {
if(window.confirm("你确定要删除这条数据吗?")){
axios.post(`/delete/${row.cno}`).then(r=>{
if(r.data.statusCode==1){
alert("删除成功!")
this.show();
}
}).catch(error=>{
console.error(error);
})
}
},
handleSizeChange(val) {
this.pageSize=val;
this.show();
},
handleCurrentChange(val) {
this.currentPage =val;
this.show();
},
show(){
axios(`/page/${this.pageSize}/${this.currentPage}`).then(r=>{
if(r.data.statusCode==1){
this.ComponentData=r.data.data.rows;
this.total=r.data.data.total;
}
}).catch(error=>{
console.error(error);
})
},
JumpOff(){
window.location.href="insert.html"
},
SSubmit(){
axios.get(`/search/${this.pageSize}/${this.currentPage}?cno=${this.form.cno}&cname=${this.form.cname}&csize=${this.form.csize}`).then(r=>{
if(r.data.statusCode==1){
this.ComponentData=r.data.data.rows;
this.total=r.data.data.total;
}
}).catch(error=>{
console.error(error);
})
},
deleteall(){
if(window.confirm("确定要删除吗?")){
axios.post("/DeleteAll",
this.List,{headers: {
'Content-Type': 'application/json'
}}).then(r=>{
if(r.data.statusCode==1){
window.alert("删除成功!")
this.show();
}
}).catch(error=>{
console.error(error);
})
}
},
handleSelectionChange(val){
this.multipleSelection=val;
this.List = this.multipleSelection.map(m => m.cno);
}
},
created(){
this.show();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.liuxiaocan.finalwork.Mapper.ComponentMapper">
<sql id="All">
select * from component
</sql>
<select id="selectall" resultType="com.liuxiaocan.finalwork.Pojo.Component">
<include refid="All"></include>
</select>
<select id="SelectPart" resultType="com.liuxiaocan.finalwork.Pojo.Component">
<include refid="All"></include> where CNo=#{cno}
</select>
<update id="Update" >
update Component set CName=#{cname},CSize=#{csize},CPrice=#{cprice},CText=#{ctext} where CNo=#{cno}
</update>
<insert id="Insert">
insert into Component values (#{cno},#{cname},#{csize},#{cprice},#{ctext})
</insert>
<delete id="Delete">
delete from Component where CNo=#{cno}
</delete>
<select id="Chaxun" resultType="com.liuxiaocan.finalwork.Pojo.Component">
<include refid="All"></include>
<where>
<if test="cno!=null">
CNo LIKE CONCAT('%', #{cno}, '%')
</if>
<if test="cname!=null">
and CName LIKE CONCAT('%', #{cname}, '%')
</if>
<if test="csize!=null">
and CSize LIKE CONCAT('%', #{csize}, '%')
</if>
</where>
</select>
<delete id="DeleteAll">
delete from component where cno in
<foreach collection="cnos" item="cno" separator="," close=")" open="(">
#{cno}
</foreach>
</delete>
</mapper>
![](https://img-blog.csdnimg.cn/direct/355248e5a0814f689427a82916ece1bb.png)