《web应用技术》第9次课后作业

一、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>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值