SSM实战项目——哈哈音乐(二)后台模块开发

news2024/11/20 13:25:15

1、项目准备

① 引入后台模块(hami-console)需要的依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        <artifactId>hami-parent</artifactId>
        <groupId>com.qcby</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>hami-console</artifactId>
    <packaging>war</packaging>
    <name>hami-console Maven Webapp</name>

    <dependencies>
        <dependency>
            <groupId>com.qcby</groupId>
            <version>1.0-SNAPSHOT</version>
            <artifactId>hami-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
        </dependency>
    </dependencies>


</project>

②编写web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app
        version="2.5"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xml="http://www.w3.org/XML/1998/namespace"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>


  <filter>
    <filter-name>filter1</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>filter1</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

③创建springmvc配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">


    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
                <property name="features">
                    <array>
                        <value>WriteMapNullValue</value>
                        <value>WriteNullStringAsEmpty</value>
                    </array>

                </property>
                <property name="dateFormat" value="yyyy-MM-dd"></property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <context:component-scan base-package="com.qcby.controller"/>

    <bean id="viewResource" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/page/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!--文件上传-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="10024000"></property>
    </bean>

    <mvc:default-servlet-handler/>
    <mvc:view-controller path="/index" view-name="index"/>

</beans>

④创建controller,并引入前端页面代码资源

2、流派管理模块开发

流派管理提供了分页列表展示、添加流派、搜索流派、修改流派、删除流派的功能

 controller编写

流派的增删改查代码生成器都全部生成,不需要添加额外代码

package com.qcby.controller;

import com.qcby.model.Mtype;
import com.qcby.model.Page;
import com.qcby.query.MtypeQuery;
import com.qcby.service.MtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 流派模块的控制器
 * 增删改查
 * **/
@Controller
@RequestMapping("/mtype")
public class MtypeController {
    @Autowired
    private  MtypeService mtypeService;

    /**
     *
     * 分页查询流派信息
     */
    @RequestMapping("/list")
    public String listType(MtypeQuery mq, Model model){
        if(mq.getPageNo() == 0){
            mq.setPageNo(1);
        }
        Page<Mtype> page = mtypeService.selectObjectByCondition(mq);
        //System.out.println(page);
        model.addAttribute("page", page);
        //返回mq这个前端传过来的参数的目的时为了回显数据
        model.addAttribute("mq",mq);
        return "mtype";
    }

    /**
     *
     * 流派的添加
     */
    @ResponseBody
    @RequestMapping("/addMtype")
    public String addMtype(Mtype mt){
        int i = mtypeService.insert(mt);
        if(i>0){
            return "success";
        }
        return "failed";
    }

    /**
     * 流派回显
     */
    @ResponseBody
    @RequestMapping("/getMtype")
    public Mtype getMtype(Integer tid){
        Mtype mtype = mtypeService.selectByPrimaryKey(tid);
        return mtype;
    }

    /**
     * 流派的修改
     */
    @ResponseBody
    @RequestMapping("/updateMtype")
    public String updateMtype(Mtype mt){
        int i = mtypeService.updateByPrimaryKeySelective(mt);
        if(i>0){
            return "success";
        }
        return "failed";
    }

    /**
     * 流派删除
     */
    @ResponseBody
    @RequestMapping("/delMtype")
    public String delMtype(Integer tid){
        int i = mtypeService.deleteByPrimaryKey(tid);
        if(i>0){
            return "success";
        }
        return "failed";
    }

}

前端js代码

<script>
        $(function () {
            $("#toggleSearch").click(function () {
                var flag = $(this).attr("flag");
                if (flag == 1) {
                    $("#find").show(500);
                    $(this).attr("flag", 2);
                    $(this).html("收缩↑");
                } else {
                    $("#find").hide(500)
                    $(this).attr("flag", 1);
                    $(this).html("展开↓");
                }
            });

            $("#search").click(function () {
                $("#pageNo").val(1);
                $("#txForm").submit();
            })


            /**
             * 用于控制上一页和下一页的可用的切换
             * @type {jQuery}
             */
            var pageNo = $("#pageNo").val();
            var totalPage = $("#totalPage").val();

            pageNo = parseInt(pageNo);
            totalPage = parseInt(totalPage);
            if (pageNo == 1 && pageNo == totalPage) {
                $("#prev").addClass("disabled");
                $("#next").addClass("disabled");
            }

            if (pageNo == 1 && pageNo < totalPage) {
                $("#prev").addClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo < totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo == totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").addClass("disabled");
            }


            $("#prev").click(function () {
                $("#pageNo").val(--pageNo);
                $("#txForm").submit();
            })

            $("#next").click(function () {
                $("#pageNo").val(++pageNo);
                $("#txForm").submit();
            })

            $("a[pageNoButton]").click(function () {
                var pageNo = $(this).html();
                $("#pageNo").val(pageNo);
                $("#txForm").submit();
            })


            var pop;
            $("#addSong").click(function () {

                pop = layer.open({
                    type: 1,
                    area: [600, 350],
                    content: $('#mtypePop')
                });

            })

            layui.use('form', function () {
                var form = layui.form;

                //监听提交
                form.on('submit(demo1)', function (data) {
                    //layer.msg(JSON.stringify(data.field));
                    $.ajax({
                        url: "/mtype/addMtype",
                        type: "post",
                        data: data.field,
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("添加成功");
                                layer.close(pop);
                                $("#txForm").submit();
                            }
                        }
                    })
                    //阻止页面跳转  防止同步提交  使用ajax异步提交表单
                    return false;
                });
            });

            var pop1;
            $("[modify]").click(function () {
                var tid = $(this).attr("tid");

                $.ajax({
                    url: "/mtype/getMtype",
                    type: "post",
                    data: {
                        tid:tid
                    },
                    dataType: "json",
                    success: function (jsonObj) {
                        $("#tid").val(jsonObj.tid);
                        $("#ptname").val(jsonObj.tname);
                        $("#ptdesc").val(jsonObj.tdesc);
                    }
                })

                pop1 = layer.open({
                    type: 1,
                    area: [600, 350],
                    content: $('#mtypePop1')
                });

            })

            layui.use('form', function () {
                var form = layui.form;

                //监听提交
                form.on('submit(demo2)', function (data) {
                    //layer.msg(JSON.stringify(data.field));
                    $.ajax({
                        url: "/mtype/updateMtype",
                        type: "post",
                        data: data.field,
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("修改成功");
                                layer.close(pop1);
                                $("#txForm").submit();
                            }
                        }
                    })
                    return false;
                });
            })

            $(".btn-warning").click(function () {
                var tid = $(this).attr("tid");
                layer.confirm('是否确认删除?', {icon: 3, title:'提示'}, function(index){
                    $.ajax({
                        url: "/mtype/delMtype",
                        type: "post",
                        data: {
                            tid:tid
                        },
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("删除成功");
                                layer.close(index);
                                $("#pageNo").val(1);
                                $("#txForm").submit();
                            }
                        }
                    })
                });
            })
        });
    </script>

 列表显示

<form id="txForm" action="/mtype/list" method="post" class="form-horizontal">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="widget">
                            <div class="widget-header"><i class="icon-list-ol"></i>
                                <h3>搜索条件</h3>
                            </div>
                            <div class="widget-content">

                                <fieldset id="find">
                                    <div class="control-group">
                                        <label for="tname" class="control-label">流派</label>
                                        <div class="controls form-group">
                                            <div class="input-group"><span class="input-group-addon"><i
                                                    class="icon-music"></i></span>
                                                <input type="text" placeholder="如:摇滚" name="tname" value="${mq.tname}"
                                                       id="tname" class="form-control"/>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                                <div class="form-actions text-right">
                                    <div>
                                        <button class="btn btn-primary" id="search">搜索</button>
                                        <button id="addSong" class="btn btn-primary" data-target="#myModal2"
                                                type="button">添加流派
                                        </button>
                                        <button id="toggleSearch" flag="2" class="btn btn-default" type="button">收缩↑
                                        </button>
                                    </div>
                                </div>


                            </div>
                            <div class="widget-content">
                                <div class="body">
                                    <table class="table table-striped table-images"
                                           style="color: white;font-size: 14px">
                                        <thead>
                                        <tr>
                                            <th class="hidden-xs-portrait">序号</th>

                                            <th class="hidden-xs">流派</th>
                                            <th class="hidden-xs">描述</th>
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${page.list}" var="mtype" varStatus="status">
                                            <tr>
                                                <td class="hidden-xs-portrait">${mtype.tid}</td>
                                                <td class="hidden-xs-portrait">${mtype.tname}</td>
                                                <td class="hidden-xs"> ${mtype.tdesc} </td>
                                                <td>
                                                    <button  class="btn btn-sm btn-primary" type="button" modify tid="${mtype.tid}" > 修改</button>
                                                    <button data-toggle="button" class="btn btn-sm btn-warning" tid="${mtype.tid}"> 删除</button>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>
                                    <jsp:include page="pagination.jsp"></jsp:include>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </form>

添加弹出层

<div id="mtypePop" style="margin-right: 50px;margin-top: 50px; display: none">
    <form id="addMtypeForm" class="layui-form" method="post" action="/mtype/addMtype" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">流派</label>
            <div class="layui-input-block">
                <input type="text" name="tname" style="color: black;" lay-verify="title" autocomplete="off"
                       placeholder="请输入流派名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea style="color: black;" placeholder="请输入流派描述" class="layui-textarea" name="tdesc"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo1">添加流派
                </button>
            </div>
        </div>
    </form>
</div>

 修改弹出层

<div id="mtypePop1" style="margin-right: 50px;margin-top: 50px; display: none">
    <form id="updateMtypeForm" class="layui-form" method="post" action="/mtype/updateMtype" lay-filter="example">
        <input type="hidden" name="tid" id="tid">
        <div class="layui-form-item">
            <label class="layui-form-label">输入框</label>
            <div class="layui-input-block">
                <input id="ptname" type="text" name="tname" style="color: black;" lay-verify="title" autocomplete="off"
                       placeholder="请输入流派名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文本域</label>
            <div class="layui-input-block">
                <textarea id="ptdesc" style="color: black;" placeholder="请输入流派描述" class="layui-textarea"
                          name="tdesc"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo2">修改流派
                </button>
            </div>
        </div>
    </form>
</div>

3、歌曲管理模块开发

歌曲管理提供了分页列表展示、添加歌曲、搜索歌曲、修改歌曲、删除歌曲的功能

controller编写

歌曲的增删改查代码生成器都全部生成,不需要添加额外代码,文件上传部分在后续博客(三)中会详细介绍

package com.qcby.controller;

import com.qcby.model.*;
import com.qcby.query.SongQuery;
import com.qcby.service.AlbumService;
import com.qcby.service.MtypeService;
import com.qcby.service.SongService;
import com.qcby.service.SongerService;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/song")
public class SongController {

    @Autowired
    private MtypeService mtypeService;

    @Autowired
    private SongerService songerService;

    @Autowired
    private AlbumService albumService;

    @Autowired
    private SongService songService;

    @RequestMapping("/list")
    public String listType(SongQuery mq, Model model) {

        if (mq.getPageNo() == 0) {
            mq.setPageNo(1);
        }
        Page<Song> page = songService.selectObjectByCondition(mq);
        model.addAttribute("page", page);
        model.addAttribute("mq", mq);
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        List<Songer> songers = songerService.selectObjectAll();
        List<Album> albums = albumService.selectObjectAll();
        model.addAttribute("mtypes", mtypes);
        model.addAttribute("songers", songers);
        model.addAttribute("albums", albums);
        return "song";
    }

    @RequestMapping("/toAdd")
    public String toAdd(Model model){
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        List<Songer> songers = songerService.selectObjectAll();
        List<Album> albums = albumService.selectObjectAll();
        model.addAttribute("mtypes", mtypes);
        model.addAttribute("songers", songers);
        model.addAttribute("albums", albums);
        return "addSong";
    }

    /**
     *新增歌曲
     */
    @RequestMapping("/add")
    public String addSong(Song song){
        int srid = song.getSrid();
        Songer songer = songerService.selectByPrimaryKey(srid);
        String pic = songer.getPic();
        song.setPic(pic);
        int i = songService.insert(song);
        if(i>0){
            return "redirect:list";
        }
        return "addSong";
    }

    /**
     * 歌曲信息回显
     */
    @RequestMapping("/toUpdate")
    public String toUpdate(Integer sid, Model model){
        Song song = songService.selectByPrimaryKey(sid);
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        List<Songer> songers = songerService.selectObjectAll();
        List<Album> albums = albumService.selectObjectAll();
        model.addAttribute("song", song);
        model.addAttribute("mtypes", mtypes);
        model.addAttribute("songers", songers);
        model.addAttribute("albums", albums);
        return "updateSong";
        //return "forward:/WEB-INF/page/updateSong.jsp";
    }

    /**
     * 歌曲信息修改
     */
    @RequestMapping("/update")
    public String updateSong(Song song){
        int i = songService.updateByPrimaryKeySelective(song);
        if(i>0){
            return "redirect:list";
        }
        return "updateSong";
    }

    /**
     * 歌信息删除
     */
    @ResponseBody
    @RequestMapping("/delSong")
    public String delSong(Integer sid){
        String path = "http://localhost:8082";
        //根据aid查询pic
        Song song = songService.selectByPrimaryKey(sid);
        String pic = song.getPic();
        String mp3 = song.getMp3();
        String realPathpic = path+pic;
        String realPathmp3 = path+mp3;
        int i = songService.deleteByPrimaryKey(sid);
        if(i>0){
            if(mp3 != null && !mp3.equals("")){
                //删除本地服务器上的pic
                Client client1 = Client.create();
                WebResource resource1 = client1.resource(realPathmp3);
                // 尝试执行HEAD请求以检查资源是否存在
                ClientResponse response1 = resource1.head();
                if (response1.getStatus() == 200) {
                    // 资源存在,可以安全地删除
                    System.out.println("正在删除资源...");
                    response1.close();  // 关闭HEAD请求的响应
                    resource1.delete();
                } else {
                    // 资源不存在,不需要删除
                    System.out.println("资源不存在,无需删除");
                }
            }

            return "success";
        }
        return "failed";
    }
}

 前端js代码

<script>
        var layer
        $(function () {
            layui.use('layer', function(){
                layer = layui.layer;
            });

            $("#toggleSearch").click(function () {
                var flag =  $(this).attr("flag");
                if(flag == 1){
                    $("#find").show(500);
                    $(this).attr("flag",2);
                    $(this).html("收缩↑");
                }else{
                    $("#find").hide(500)
                    $(this).attr("flag",1);


                    $(this).html("展开↓");
                }
            });
            $("#addSong").click(function () {
                window.location.href = "/song/toAdd";
            });

            // $("[update]").click(function () {
            // // $("#updateSong").click(function () {
            //     var sid = $(this).attr("sid");
            //     console.log(sid)
            //     window.location.href = "/song/toUpdate?sid="+sid;
            // })

            $("#search").click(function () {
                $("#pageNo").val(1);
                $("#txFrom").submit();
            });

            var pageNo = $("#pageNo").val();
            var totalPage = $("#totalPage").val();

            pageNo = parseInt(pageNo);
            totalPage = parseInt(totalPage);
            if (pageNo == 1 && pageNo == totalPage) {
                $("#prev").addClass("disabled");
                $("#next").addClass("disabled");
            }

            if (pageNo == 1 && pageNo < totalPage) {
                $("#prev").addClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo < totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo == totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").addClass("disabled");
            }


            $("#prev").click(function () {
                $("#pageNo").val(--pageNo);
                $("#txForm").submit();
            })

            $("#next").click(function () {

                $("#pageNo").val(++pageNo);
                $("#txForm").submit();
            })

            $("a[pageNoButton]").click(function () {
                var pageNo = $(this).html();
                $("#pageNo").val(pageNo);
                $("#txForm").submit();

            })

            //$("#updateSong").click(function(){
            $("[update]").click(function () {
                var sid = $(this).attr("sid");
                console.log(sid)
                $.ajax({
                    url: "/song/toUpdate?sid="+sid,
                    type: "get",
                    success: function (){
                    }
                })
                return false;

            })

            // $("#deleteSonger").click(function () {
            $("[del]").click(function () {
                // $(".btn-warning").click(function () {
                var sid = $(this).attr("sid");
                console.log(sid)
                layer.confirm('是否确认删除?', {icon: 3, title:'提示'}, function(index){
                    $.ajax({
                        url: "/song/delSong",
                        type: "post",
                        data: {
                            sid:sid
                        },
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("删除成功");
                                layer.close(index);
                                $("#pageNo").val(1);
                                $("#txForm").submit();
                            }else{
                                layer.msg("删除失败");
                                layer.close(index);
                            }
                        }
                    })
                })
            })
        })

    </script>

列表显示

 <form id="txForm" action="/song/list" method="post" class="form-horizontal" >
            <div class="row">
                <div class="col-lg-12">
                    <div class="widget">
                        <div class="widget-header"> <i class="icon-list-ol"></i>
                            <h3>搜索条件</h3>
                        </div>
                        <div class="widget-content">

                            <fieldset id="find">
                                <!--<legend class="section">Horizontal form</legend>-->
                                <div class="control-group">
                                    <label for="sname" class="control-label">歌名</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-music"></i></span>
                                            <input type="text" placeholder="如:想你的365天" name="sname" value="${mq.sname}" id="sname" class="form-control" />
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="srname" class="control-label">歌手</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-user"></i></span>
                                            <input type="text" placeholder="如:李玟" name="srname" value="${mq.srname}" id="srname" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label for="aname" class="control-label">专辑</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-reorder"></i></span>
                                            <input type="text" placeholder="如:宝莲灯" name="aname" value="${mq.aname}" id="aname" class="form-control" />
                                        </div>
                                    </div>
                                </div>


                                <div class="control-group">
                                    <label for="tid" class="control-label">流派</label>

                                    <div class="controls form-group">
                                        <select id="tid" name="tid" class="form-control ">
                                            <option value="">--请选择--</option>
                                            <c:forEach items="${mtypes}" var="mtype">
                                                <option value="${mtype.tid}" <c:if test="${mtype.tid == mq.tid}">selected</c:if>>${mtype.tname}</option>
                                            </c:forEach>
                                        </select>

                                    </div>
                                </div>

                            </fieldset>
                            <div class="form-actions text-right">
                                <div>
                                    <button id="search" class="btn btn-primary" type="submit">搜索</button>
                                    <button id="addSong" class="btn btn-primary" type="button" >添加歌曲</button>
                                    <button id="toggleSearch" flag = "2" class="btn btn-default" type="button">收缩↑</button>
                                </div>
                            </div>


                        </div>
                        <div class="widget-content" >
                            <div class="body">
                                <table class="table table-striped table-images" style="color: white;font-size: 14px">
                                    <thead>
                                    <tr>
                                        <th class="hidden-xs-portrait">序号</th>
                                        <th>封面</th>
                                        <th>歌名</th>
                                        <th class="hidden-xs-portrait">歌手</th>
                                        <th class="hidden-xs">专辑</th>
                                        <th class="hidden-xs">流派</th>
                                        <th></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${page.list}" var="song">

                                        <tr>
                                            <td class="hidden-xs-portrait">${song.sid}</td>
                                            <td><img src="${filePath}${song.songer.pic}"/></td>
                                            <td> ${song.sname} </td>
                                            <td class="hidden-xs-portrait">${song.songer.srname}</td>
                                            <td class="hidden-xs"> <p><strong>${song.album.aname}</strong></p></td>
                                            <td class="hidden-xs"> ${song.mtype.tname} </td>
                                            <td><a href="/song/toUpdate?sid=${song.sid}" class="btn btn-sm btn-primary">修改</a>
<%--                                                <button id="updateSong" class="btn btn-sm btn-primary" update sid="${song.sid}"> 修改 </button>--%>
                                                <button data-toggle="button" class="btn btn-sm btn-warning" id="deleteSong" del sid="${song.sid}"> 删除 </button></td>
                                        </tr>
                                    </c:forEach>


                                    </tbody>
                                </table>
                                <jsp:include page="pagination.jsp"></jsp:include>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </form>

添加页面(通过页面跳转)

 <form data-validate="parsley" method="post" action="/song/add" novalidate="" class="form-horizontal label-left" id="song-form" >

                                <fieldset>
                                    <legend class="section">歌曲信息</legend>
                                    <div class="control-group">
                                        <label for="sname" class="control-label">歌名</label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12" name="sname" id="sname" />
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label for="srid" class="control-label">歌手<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="srid" name="srid" class="form-control ">
                                                    <c:forEach items="${songers}" var="songer">
                                                        <option value="${songer.srid}">${songer.srname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="aid" class="control-label">专辑<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="aid" name="aid" class="form-control ">
                                                    <c:forEach items="${albums}" var="album">
                                                        <option value="${album.aid}">${album.aname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="tid" class="control-label">流派<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="tid" name="tid" class="form-control ">
                                                    <c:forEach items="${mtypes}" var="mtype">
                                                        <option value="${mtype.tid}">${mtype.tname}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="isNew" class="control-label">是否新歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isNew" name="isNew" class="form-control ">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="isHot" class="control-label">是否热歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isHot" name="isHot" class="form-control ">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>




                                </fieldset>
                                <fieldset>
                                    <legend class="section">歌曲文件</legend>

                                    <div class="control-group">
                                        <label class="control-label" for="description">歌词</label>
                                        <div class="controls form-group">
                                            <textarea class="form-control" name="lrc" rows="3" id="description"></textarea>
                                            <span class="help-block">请入lrc格式歌词</span> </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="i1-file" class="control-label">选择歌曲 <span class="required">*</span></label>
                                        <!--<div class="col-sm-4 control-label">选择文件</div>-->
                                        <div class="col-sm-6">
                                            <div class="input-group">
                                                <input id='mp3loc' class="form-control" onclick="$('#i-file').click();">
                                                <label class="input-group-btn">
                                                    <audio src="" controls loop></audio>
                                                    <input type="button" id="i1-check" value="选择歌曲文件" class="btn btn-primary" onclick="$('#i1-file').click();">
                                                </label>
                                            </div>
                                        </div>
                                        <input type="hidden" id="mp3" name="mp3" lay-verify="pic">
                                        <input type="hidden" id="lastMp3" name="lastMp3">
                                        <input type="file" name="mp3file" id='i1-file'  accept=".mp3, .wma" onchange="submitFile()" style="display: none">

                                    </div>


                                </fieldset>
                                <div class="form-actions text-right">
                                    <button class="btn btn-primary" type="submit">提交歌曲</button>
                                </div>
                                </form>

修改页面(通过页面跳转)

<form data-validate="parsley" method="post" action="/song/update" novalidate="" class="form-horizontal label-left" id="song-form" >
                                    <input type="hidden" name="sid" value="${song.sid}">
                                <fieldset>
                                    <legend class="section">歌曲信息</legend>
                                    <div class="control-group">
                                        <label for="sname" class="control-label">歌名</label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12" name="sname" id="sname" value="${song.sname}"/>
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label for="srid" class="control-label">歌手<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="srid" name="srid" class="form-control ">
                                                    <c:forEach items="${songers}" var="songer">
                                                        <option value="${songer.srid}" <c:if test="${song.srid==songer.srid}">selected</c:if>>${songer.srname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="aid" class="control-label">专辑<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="aid" name="aid" class="form-control ">
                                                    <c:forEach items="${albums}" var="album">
                                                        <option value="${album.aid}" <c:if test="${song.aid==album.aid}">selected</c:if>>${album.aname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="tid" class="control-label">流派<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="tid" name="tid" class="form-control ">
                                                    <c:forEach items="${mtypes}" var="mtype">
                                                        <option value="${mtype.tid}" <c:if test="${song.tid==mtype.tid}">selected</c:if>>${mtype.tname}</option>
                                                    </c:forEach>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="isNew" class="control-label">是否新歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isNew" name="isNew" class="form-control ">
                                                    <option value="1" <c:if test="${song.isNew==1}">selected</c:if>>是</option>
                                                    <option value="0" <c:if test="${song.isNew==0}">selected</c:if>>否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="isHot" class="control-label">是否热歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isHot" name="isHot" class="form-control ">
                                                    <option value="1" <c:if test="${song.isHot==1}">selected</c:if>>是</option>
                                                    <option value="0" <c:if test="${song.isHot==0}">selected</c:if>>否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>




                                </fieldset>
                                <fieldset>
                                    <legend class="section">歌曲文件</legend>


                                    <div class="control-group">
                                        <label class="control-label" for="description">歌词</label>
                                        <div class="controls form-group">
                                            <textarea class="form-control" name="lrc" rows="3" id="description">${song.lrc}</textarea>
                                            <span class="help-block">请入lrc格式歌词</span> </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="i1-file" class="control-label">选择歌曲 <span class="required">*</span></label>
                                        <!--<div class="col-sm-4 control-label">选择文件</div>-->
                                        <div class="col-sm-6">
                                            <div class="input-group">
                                                <input id='mp3loc' class="form-control" onclick="$('#i-file').click();">
                                                <label class="input-group-btn">
                                                    <audio src="${filePath}${song.mp3}" controls loop></audio>
                                                    <input type="button" id="i1-check" value="选择歌曲文件" class="btn btn-primary" onclick="$('#i1-file').click();">
                                                </label>
                                            </div>
                                        </div>
                                        <input type="hidden" id="mp3" name="mp3" lay-verify="pic" value="${song.mp3}">
                                        <input type="hidden" id="lastMp3" name="lastMp3" value="${filePath}${song.mp3}">
                                        <input type="file" name="mp3file" id='i1-file'  accept=".mp3, .wma" onchange="submitFile()" style="display: none">

                                    </div>


                                </fieldset>
                                <div class="form-actions text-right">
                                    <button class="btn btn-primary" type="submit">提交歌曲</button>
                                </div>
                                </form>

4、艺人管理模块开发

艺人管理提供了分页列表展示、添加艺人、搜索艺人、修改艺人、删除艺人的功能

controller编写 

艺人的增删改查代码生成器都全部生成,不需要添加额外代码,图片上传部分在后续博客(三)中会详细介绍

package com.qcby.controller;

import com.qcby.model.Mtype;
import com.qcby.model.Page;
import com.qcby.model.Songer;
import com.qcby.query.SongerQuery;
import com.qcby.service.MtypeService;
import com.qcby.service.SongerService;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 歌手模块
 */
@Controller
@RequestMapping("/songer")
public class SongerController {
    @Autowired
    private SongerService songerService;
    @Autowired
    private MtypeService mtypeService;

    @RequestMapping("/list")
    public String listSonger(SongerQuery mq, Model model){
        if(mq.getPageNo() == 0){
            mq.setPageNo(1);
        }
        //查询分页的数据
        Page<Songer> page = songerService.selectObjectByCondition(mq);
        //把page对象发给页面
        model.addAttribute("page", page);
        //把查询条件也要回显
        model.addAttribute("mq", mq);
        //查询流派
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        model.addAttribute("mtypes", mtypes);
        return "songer";
    }

    @RequestMapping("/toAdd")
    public String toAdd(Model model){
        //查询流派
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        model.addAttribute("mtypes", mtypes);
        return "addSonger";
    }

    /**
     *新增歌手
     */
    @RequestMapping("/add")
    public String addSonger(Songer songer){
        int i = songerService.insert(songer);
        if(i>0){
            return "redirect:list";
        }
        return "addSonger";
    }

    /**
     * 歌手信息回显
     */
    @RequestMapping("/toUpdate")
    public String toUpdate(Model model, Integer srid){
        System.out.println(srid);
        Songer songer = songerService.selectByPrimaryKey(srid);
        System.out.println(songer);
        model.addAttribute("songer", songer);
        //查询流派
        List<Mtype> mtypes = mtypeService.selectObjectAll();
        System.out.println(mtypes);
        model.addAttribute("mtypes", mtypes);
        return "updateSonger";
        //return "forward:/WEB-INF/page/updateSonger.jsp";  能够去吗?
    }

    /**
     * 歌手信息修改
     */
    @RequestMapping("/update")
    public String updateSonger(Songer songer){
        int i = songerService.updateByPrimaryKeySelective(songer);
        if(i>0){
            return "redirect:list";
        }
        return "updateSonger";
    }

    /**
     * 歌手信息删除
     */
    @ResponseBody
    @RequestMapping("/delSonger")
    public String delSonger(Integer srid){
        String path = "http://localhost:8082";
        //根据aid查询pic
        Songer songer = songerService.selectByPrimaryKey(srid);
        String pic = songer.getPic();
        String realPath = path+pic;
        int i = songerService.deleteByPrimaryKey(srid);
        if(i>0){
            if(pic !=null && !pic.equals("")){
                //删除本地服务器上的pic
                Client client = Client.create();
                WebResource resource1 = client.resource(realPath);
                // 尝试执行HEAD请求以检查资源是否存在
                ClientResponse response1 = resource1.head();
                if (response1.getStatus() == 200) {
                    // 资源存在,可以安全地删除
                    System.out.println("正在删除资源...");
                    response1.close();  // 关闭HEAD请求的响应
                    resource1.delete();
                } else {
                    // 资源不存在,不需要删除
                    System.out.println("资源不存在,无需删除");
                }
            }
            return "success";
        }
        return "failed";
    }
}

前端js代码

<script>
        var layer
        $(function () {
            layui.use('layer', function(){
                layer = layui.layer;
            });

            $("#toggleSearch").click(function () {
                var flag =  $(this).attr("flag");
                if(flag == 1){
                    $("#find").show(500);
                    $(this).attr("flag",2);
                    $(this).html("收缩↑");
                }else{
                    $("#find").hide(500)
                    $(this).attr("flag",1);


                    $(this).html("展开↓");
                }
            });
            $("#addSonger").click(function () {
                window.location.href = "/songer/toAdd";
            });

            // $("#updateSonger").click(function(){
            //$("[update]").click(function () {
            //     //event.preventDefault(); // 阻止表单的自动提交
            //     var srid = $(this).attr("srid");
            //     console.log(srid)
            //     window.location.href = "/songer/toUpdate?srid="+srid;
            //     // return false;
            // });
            $("#search").click(function () {
                $("#pageNo").val(1);
                $("#txFrom").submit();
            });

            var pageNo = $("#pageNo").val();
            var totalPage = $("#totalPage").val();

            pageNo = parseInt(pageNo);
            totalPage = parseInt(totalPage);
            if (pageNo == 1 && pageNo == totalPage) {
                $("#prev").addClass("disabled");
                $("#next").addClass("disabled");
            }

            if (pageNo == 1 && pageNo < totalPage) {
                $("#prev").addClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo < totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo == totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").addClass("disabled");
            }


            $("#prev").click(function () {
                $("#pageNo").val(--pageNo);
                $("#txForm").submit();
            })

            $("#next").click(function () {

                $("#pageNo").val(++pageNo);
                $("#txForm").submit();
            })

            $("a[pageNoButton]").click(function () {
                var pageNo = $(this).html();
                $("#pageNo").val(pageNo);
                $("#txForm").submit();

            })

            //$("#updateSonger").click(function(){
            $("[update]").click(function () {
                var srid = $(this).attr("srid");
                console.log(srid)
                $.ajax({
                    url: "/songer/toUpdate?srid="+srid,
                    type: "get",
                    success: function (){
                    }
                })
                return false;

            })

            // $("#deleteSonger").click(function () {
            $("[del]").click(function(){
            // $(".btn-warning").click(function () {
                var srid = $(this).attr("srid");
                console.log(srid)
                layer.confirm('是否确认删除?', {icon: 3, title:'提示'}, function(index){
                    $.ajax({
                        url: "/songer/delSonger",
                        type: "post",
                        data: {
                            srid:srid
                        },
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("删除成功");
                                layer.close(index);
                                $("#pageNo").val(1);
                                $("#txForm").submit();
                            }else{
                                layer.msg("删除失败");
                                layer.close(index);
                            }
                        }
                    })
                })
            })
            //return false;

        })

    </script>

列表显示

<form id="txForm" method="post" action="/songer/list" class="form-horizontal" >
    <div class="wrapper">

        <jsp:include page="menu.jsp"></jsp:include>
        <div class="page-content">
            <div class="content container">
                <div class="row">
                    <div class="col-lg-12">
                        <h2 class="page-title">艺人列表 <small>favor song</small></h2>
                    </div>
                </div>

                <div class="row">
                    <div class="col-lg-12">
                        <div class="widget">
                            <div class="widget-header"> <i class="icon-list-ol"></i>
                                <h3>搜索条件</h3>
                            </div>
                            <div class="widget-content">

                                <fieldset id="find">
                                    <!--<legend class="section">Horizontal form</legend>-->
                                    <div class="control-group">
                                        <label for="srname" class="control-label">艺人名字</label>
                                        <div class="controls form-group">
                                            <div class="input-group"> <span class="input-group-addon"><i class="icon-music"></i></span>
                                                <input type="text" placeholder="如:黄家驹" name="srname" value="${mq.srname}" id="srname" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="area" class="control-label">地区</label>
                                        <div class="controls form-group">
                                            <div class="input-group"> <span class="input-group-addon"><i class="icon-user"></i></span>
                                                <input type="text" placeholder="如:香港" name="area" value="${mq.area}" id="area" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="tid" class="control-label">流派</label>

                                        <div class="controls form-group">
                                            <select id="tid" name="tid" class="form-control ">
                                                <option value="">--请选择--</option>
                                                <c:forEach items="${mtypes}" var="mtype">

                                                    <option value="${mtype.tid}" <c:if test="${mtype.tid == mq.tid}">selected</c:if>>${mtype.tname}</option>
                                                </c:forEach>
                                            </select>

                                        </div>
                                    </div>
                                </fieldset>
                                <div class="form-actions text-right">
                                    <div>
                                        <button id="search" class="btn btn-primary" type="submit">搜索</button>
                                        <button id="addSonger" class="btn btn-primary" type="button" >添加艺人</button>
                                        <button id="toggleSearch" flag = "2" class="btn btn-default" type="button">收缩↑</button>
                                    </div>
                                </div>


                            </div>
                            <div class="widget-content" >
                                <div class="body">
                                    <table class="table table-striped table-images" style="color: white;font-size: 14px">
                                        <thead>
                                        <tr>
                                            <th class="hidden-xs-portrait">序号</th>
                                            <th>头像</th>
                                            <th>名字</th>
                                            <th class="hidden-xs-portrait">地区</th>
                                            <th class="hidden-xs">是否热门</th>
                                            <th class="hidden-xs">流派</th>
                                            <th></th>
                                        </tr>
                                        </thead>
                                        <tbody>

                                        <c:forEach items="${page.list}" var="songer">
                                            <tr>
                                                <td class="hidden-xs-portrait">${songer.srid}</td>
                                                <td><img src="${filePath}${songer.pic}" /></td>
                                                <td> ${songer.srname} </td>
                                                <td class="hidden-xs-portrait">${songer.area}</td>
                                                <td class="hidden-xs"> <p><strong>${songer.isHot == 1?'热门':'一般'}</strong></p></td>
                                                <td class="hidden-xs"> ${songer.mtype.tname} </td>
                                                <td><a href="/songer/toUpdate?srid=${songer.srid}" class="btn btn-sm btn-primary">修改</a>
<%--                                                    <button id="updateSonger" class="btn btn-sm btn-primary" update srid="${songer.srid}"> 修改 </button>--%>
                                                    <button id="deleteSonger" data-toggle="button" class="btn btn-sm btn-warning" del srid="${songer.srid}"> 删除 </button></td>
                                            </tr>
                                        </c:forEach>



                                        </tbody>
                                    </table>
                                    <jsp:include page="pagination.jsp"></jsp:include>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

添加页面(通过页面跳转)

<form data-validate="parsley" action="/songer/add" method="post" novalidate="" class="form-horizontal label-left" id="songerForm" />

                        <div class="widget-content">

                            <div class="body">

                                <fieldset>
                                    <legend class="section">艺人信息</legend>

                                    <div class="control-group">
                                        <label for="srname" class="control-label">艺人名字 <span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12 parsley-validated" required="" name="srname" id="srname" />
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="area" class="control-label">地区</label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12" name="area" id="area" />
                                        </div>
                                    </div>


                                    <div class="control-group">
                                        <label for="tid" class="control-label">流派<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2 " >
                                                <select id="tid" name="tid" class="form-control ">
                                                    <c:forEach items="${mtypes}" var="mtype">

                                                        <option value="${mtype.tid}" >${mtype.tname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label for="isHot" class="control-label">是否热歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isHot" name="isHot" class="form-control ">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="description">个人简介</label>
                                        <div class="controls form-group">
                                            <textarea class="form-control" name="intro" rows="3" id="description"></textarea>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="" class="control-label">头像<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div class="col-sm-4 col-md-2">
                                                <div class="image-row">
                                                    <div class="image-set">
                                                        <a class="example-image-link" href="../../img/gallery-photo/image-3.jpg" data-lightbox="example-set" title="Click on the right side of the image to move forward.">
                                                        <img id="songerImg" class="example-image" src="../../img/gallery-photo/thumb-3.jpg" alt="Plants: image 1 0f 4 thumb" width="150" height="150" />
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <label for="i-file" class="control-label">选择文件 <span class="required">*</span></label>
                                        <div id="examples" class="section examples-section">
                                            <div class="col-sm-6">
                                                <div class="input-group">
                                                    <input id='location' class="form-control" onclick="$('#i-file').click();">
                                                    <label class="input-group-btn">
                                                        <input type="button" id="i-check" value="选择封面" class="btn btn-primary" onclick="$('#i-file').click();">
                                                    </label>
                                                </div>
                                            </div>
                                            <input type="hidden" id="pic" name="pic" lay-verify="pic">
                                            <input type="hidden" id="lastImg" name="lastImg">
                                            <input type="file" name="picfile" id='i-file'  accept=".jpg, .png" onchange="submitFile()" style="display: none">
                                        </div>
                                    </div>
                                </fieldset>

                                <div class="form-actions text-right">
                                    <button id="submitSonger" class="btn btn-primary" type="submit">提交艺人</button>
                                </div>

                            </div>
                            </form>

修改页面(通过页面跳转)

<form data-validate="parsley" action="/songer/update" method="post" novalidate="" class="form-horizontal label-left" id="songerForm" />
                        <input type="hidden" name="srid" id="srid" value="${songer.srid}">
                        <div class="widget-content">

                            <div class="body">

                                <fieldset>
                                    <legend class="section">艺人信息</legend>

                                    <div class="control-group">
                                        <label for="srname" class="control-label">艺人名字 <span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12 parsley-validated" required="" name="srname" id="srname" value="${songer.srname}"/>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label for="area" class="control-label">地区</label>
                                        <div class="controls form-group">
                                            <input type="text" class="col-sm-6 col-xs-12" name="area" id="area" value="${songer.area}"/>
                                        </div>
                                    </div>


                                    <div class="control-group">
                                        <label for="tid" class="control-label">流派<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2 " >
                                                <select id="tid" name="tid" class="form-control ">
                                                    <c:forEach items="${mtypes}" var="mtype">

                                                        <option value="${mtype.tid}" <c:if test="${songer.tid==mtype.tid}">selected</c:if>>${mtype.tname}</option>
                                                    </c:forEach>
                                                </select>

                                            </div>
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label for="isHot" class="control-label">是否热歌<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div data-toggle="buttons" class="btn-group col-sm-2" >
                                                <select id="isHot" name="isHot" class="form-control ">
                                                    <option value="1" <c:if test="${songer.isHot==1}">selected</c:if>>是</option>
                                                    <option value="0" <c:if test="${songer.isHot==0}">selected</c:if>>否</option>
                                                </select>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="description">个人简介</label>
                                        <div class="controls form-group">
                                            <textarea class="form-control" name="intro" rows="3" id="description">${songer.intro}</textarea>
                                        </div>
                                    </div>


                                    <div class="control-group">
                                        <label for="songerImg" class="control-label">头像<span class="required">*</span></label>
                                        <div class="controls form-group">
                                            <div class="col-sm-4 col-md-2">
                                                <div class="image-row">
                                                    <div class="image-set">
                                                        <a class="example-image-link" href="../../img/gallery-photo/image-3.jpg" data-lightbox="example-set" title="Click on the right side of the image to move forward.">
                                                        <img id="songerImg" class="example-image" src="${filePath}${songer.pic}" alt="${songer.srname}" width="150" height="150" />
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <label for="i-file" class="control-label">选择文件 <span class="required">*</span></label>
                                        <div id="examples" class="section examples-section">
                                            <div class="col-sm-6">
                                                <div class="input-group">
                                                    <input id='location' class="form-control" onclick="$('#i-file').click();">
                                                    <label class="input-group-btn">
                                                        <input type="button" id="i-check" value="选择封面" class="btn btn-primary" onclick="$('#i-file').click();">
                                                    </label>
                                                </div>
                                            </div>
                                            <input type="hidden" id="pic" name="pic" lay-verify="pic" value="${songer.pic}">
                                            <input type="hidden" id="lastImg" name="lastImg" value="${filePath}${songer.pic}">
                                            <input type="file" name="picfile" id='i-file'  accept=".jpg, .png" onchange="submitFile()" style="display: none">
                                        </div>
                                    </div>



                                </fieldset>

                                <div class="form-actions text-right">
                                    <button id="submitSonger" class="btn btn-primary" type="submit">修改艺人</button>
                                </div>

                            </div>
                            </form>

5、专辑管理模块开发

专辑管理提供了分页列表展示、添加专辑、搜索专辑、修改专辑、删除专辑的功能

controller编写 

除了专辑的增删改查,添加了通过专辑名查看专辑是否存在的功能

package com.qcby.controller;

import com.qcby.model.Album;
import com.qcby.model.Mtype;
import com.qcby.model.Page;
import com.qcby.query.AlbumQuery;
import com.qcby.service.AlbumService;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 专辑模块
 */
@Controller
@RequestMapping("album")
public class AlbumController {

    @Autowired
    private AlbumService albumService;

    @RequestMapping("/list")
    public String listAblum(AlbumQuery mq, Model model){
        if(mq.getPageNo() == 0){
            mq.setPageNo(1);
        }
        Page<Album> page = albumService.selectObjectByCondition(mq);
        model.addAttribute("page", page);
        model.addAttribute("mq", mq);
        return "album";
    }

    /**
     *查询专辑名是否存在
     */
    @ResponseBody
    @RequestMapping("/isSameName")
    public String isSameName(String aname){
        Album album = albumService.selectByAname(aname);
        if(album!=null){
            return "true";
        }
        return "false";
    }

    /**
     *新增专辑
     */
    @ResponseBody
    @RequestMapping("/addAlbum")
    public String addAblum(Album album){
        int i = albumService.insert(album);
        if(i>0){
            return "success";
        }
        return "failed";
    }

    /**
     * 流派回显
     */
    @ResponseBody
    @RequestMapping("/getAlbum")
    public Album getMtype(Integer aid){
        Album album = albumService.selectByPrimaryKey(aid);
        return album;
    }

    /**
     * 专辑修改
     */
    @ResponseBody
    @RequestMapping("/updateAlbum")
    public String updateAlbum(Album album){
        int i = albumService.updateByPrimaryKeySelective(album);
        if(i>0){
            return "success";
        }
        return "failed";
    }

    /**
     * 专辑删除
     */
    @ResponseBody
    @RequestMapping("/delAlbum")
    public String delAlbum(Integer aid){
        String path = "http://localhost:8082";
        //根据aid查询pic
        Album album = albumService.selectByPrimaryKey(aid);
        String pic = album.getPic();
        String realPath = path+pic;
        int i = albumService.deleteByPrimaryKey(aid);
        if(i>0){
            if(pic!=null && !pic.equals("")){
                //删除本地服务器上的pic
                Client client = Client.create();
                WebResource resource1 = client.resource(realPath);
                // 尝试执行HEAD请求以检查资源是否存在
                ClientResponse response = resource1.head();
                if (response.getStatus() == 200) {
                    // 资源存在,可以安全地删除
                    System.out.println("正在删除资源...");
                    response.close();  // 关闭HEAD请求的响应
                    resource1.delete();
                } else {
                    // 资源不存在,不需要删除
                    System.out.println("资源不存在,无需删除");
                }
            }
            return "success";
        }
        return "failed";
    }
}

通过专辑名查看专辑的service 接口

public interface AlbumService extends BaseService<AlbumQuery,Album>{
    //根据专辑名查询专辑
    public Album selectByAname(String aname);
}

 通过专辑名查看专辑的service 实现类

//根据专辑名查询专辑
    @Override
    public Album selectByAname(String aname) {
        Album album = albumMapper.selectByAname(aname);
        return album;
    }

 通过专辑名查看专辑的mapper接口

//根据专辑名查询专辑
    public Album selectByAname(String aname);

 通过专辑名查看专辑的sql

 <!--根据专辑名查询专辑-->
  <select id="selectByAname" parameterType="String" resultMap="BaseResultMap">
    select * from album where ANAME = #{aname}
  </select>

前端js代码

<script>
        var layer

        $(function () {
            layui.use('layer', function(){
                layer = layui.layer;
            });

            var pop;
            $("#addAlbum").click(function () {
                pop = layer.open({
                    type: 1,
                    area:[900, 650],
                    content: $("#albumPop"),
                    cancel: function(index, layero){
                        /*if(confirm('确定要关闭么')){ //只有当点击confirm框的确定时,该层才会关闭
                            layer.close(index)
                        }
                        return false;*/
                    }

                });


            })
            $("#toggleSearch").click(function () {
                var flag =  $(this).attr("flag");
                if(flag == 1){
                    $("#find").show(500);
                    $(this).attr("flag",2);
                    $(this).html("收缩↑");
                }else{
                    $("#find").hide(500)
                    $(this).attr("flag",1);
                    $(this).html("展开↓");
                }
            });


            $("#search").click(function () {
                $("#pageNo").val(1);
                $("#txFrom").submit();
            });

            var pageNo = $("#pageNo").val();
            var totalPage = $("#totalPage").val();

            pageNo = parseInt(pageNo);
            totalPage = parseInt(totalPage);
            if (pageNo == 1 && pageNo == totalPage) {
                $("#prev").addClass("disabled");
                $("#next").addClass("disabled");
            }

            if (pageNo == 1 && pageNo < totalPage) {
                $("#prev").addClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo < totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").removeClass("disabled");
            }

            if (pageNo > 1 && pageNo == totalPage) {
                $("#prev").removeClass("disabled");
                $("#next").addClass("disabled");
            }


            $("#prev").click(function () {
                $("#pageNo").val(--pageNo);
                $("#txForm").submit();
            })

            $("#next").click(function () {

                $("#pageNo").val(++pageNo);
                $("#txForm").submit();
            })

            $("a[pageNoButton]").click(function () {
                var pageNo = $(this).html();
                $("#pageNo").val(pageNo);
                $("#txForm").submit();

            })



            layui.use('laydate', function(){
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: '#addPdate'
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#searchPdate'
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#updatePdate'
                });


            });


            layui.use('form', function (data) {
                var form = layui.form;
                //监听提交
                form.on('submit(demo1)', function (data) {
                    //layer.msg(JSON.stringify(data.field));
                    $.ajax({
                        url: "/album/addAlbum",
                        type: "post",
                        data: data.field,
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("添加成功");
                                layer.close(pop);
                                $("#txForm").submit();
                            }else{
                                layer.msg("添加失败");
                            }
                        }
                    })


                    return false;
                });

                form.verify({
                    aname: function(value, item){ //value:表单的值、item:表单的DOM对象
                        if(!new RegExp("^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$").test(value)){
                            return '必须是中英文或数字字符,长度1-20';
                        }
                        var flag = "false";
                        $.ajax({
                            url: "/album/isSameName",
                            type: "post",
                            data: {
                                aname:value
                            },
                            async:false,
                            dataType: "text",
                            success: function (text) {
                                flag = text;
                            }
                        })
                        if(flag == "true"){
                            return "专辑名已存在";
                        }

                    },
                    //我们既支持上述函数式的方式,也支持下述数组的形式
                    //数组的两个值分别代表:[正则匹配、匹配不符时的提示文字]
                    company: [/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/,'必须是中英文或数字字符,长度1-20'],
                    pdate: [/^.+$/,'请选择发现日期'],
                    pic: [/^.+$/,'亲不要忘记上传专辑封面喔'],
                    lang: [/^[\u4e00-\u9fa5]{1,10}$/,'请输入中文的语种']
                });

            });

            var pop1;
            $("[modify]").click(function () {
                var aid = $(this).attr("aid");

                $.ajax({
                    url: "/album/getAlbum",
                    type: "post",
                    data: {
                        aid:aid
                    },
                    dataType: "json",
                    success: function (jsonObj) {
                        var realpath = "http://localhost:8082"+jsonObj.pic
                        $("#aid").val(jsonObj.aid);
                        $(".aname").val(jsonObj.aname);
                        $(".pic").val(jsonObj.pic);
                        $(".example-image").attr("src",realpath);
                        $(".example-image-link").attr("href",realpath);
                        $(".lastImg").val(realpath);
                        $(".company").val(jsonObj.company);
                        $(".pdate").val(jsonObj.pdate);
                        $(".lang").val(jsonObj.lang);
                    }
                })

                pop1 = layer.open({
                    type: 1,
                    area: [600, 700],
                    content: $('#albumPop1')
                });

            })


            layui.use('form', function () {
                var form = layui.form;

                //监听提交
                form.on('submit(demo2)', function (data) {
                    //layer.msg(JSON.stringify(data.field));
                    $.ajax({
                        url: "/album/updateAlbum",
                        type: "post",
                        data: data.field,
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("修改成功");
                                layer.close(pop1);
                                $("#txForm").submit();
                            }
                        }
                    })
                    return false;
                });

                form.verify({
                    aname: [/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/,'必须是中英文或数字字符,长度1-20'],
                    //我们既支持上述函数式的方式,也支持下述数组的形式
                    //数组的两个值分别代表:[正则匹配、匹配不符时的提示文字]
                    company: [/^[a-zA-Z0-9\u4e00-\u9fa5]{1,20}$/,'必须是中英文或数字字符,长度1-20'],
                    pdate: [/^.+$/,'请选择发现日期'],
                    pic: [/^.+$/,'亲不要忘记上传专辑封面喔'],
                    lang: [/^[\u4e00-\u9fa5]{1,10}$/,'请输入中文的语种']
                });
            })


            $(".btn-warning").click(function () {
                var aid = $(this).attr("aid");
                layer.confirm('是否确认删除?', {icon: 3, title:'提示'}, function(index){
                    $.ajax({
                        url: "/album/delAlbum",
                        type: "post",
                        data: {
                            aid:aid
                        },
                        dataType: "text",
                        success: function (text) {
                            if (text == "success") {
                                layer.msg("删除成功");
                                layer.close(index);
                                $("#pageNo").val(1);
                                $("#txForm").submit();
                            }else{
                                layer.msg("删除失败");
                                layer.close(index);
                            }
                        }
                    })
                });
            })

        })


        function submitFile(){
            // $("#location").val($("#i-file").val());
            $(".location").val($(".i-file").val());
            $(".layui-form").ajaxSubmit({
            // $("#addAlbumForm").ajaxSubmit({
                url:"/upload/uploadFile",
                data:{
                    fileType:"pic",
                },
                dataType:"json",
                success:function (json) {
                    // $("#albumImg").attr("src",json.realPath);
                    $(".example-image").attr("src",json.realPath);
                    $(".example-image-link").attr("href",json.realPath);
                    $(".lastImg").val(json.realPath);
                    // $("#lastImg").val(json.realPath);
                    $(".pic").val(json.relativePath);
                    // $("#pic").val(json.relativePath);
                }
            })
        }

        function submitFile1(){
            $("#location1").val($("#i-file1").val());
            // $(".location").val($(".i-file").val());
            // $(".layui-form").ajaxSubmit({
            $("#updateAlbumForm").ajaxSubmit({
                url:"/upload/uploadFile",
                data:{
                    fileType:"pic",
                },
                dataType:"json",
                success:function (json) {
                    $("#albumImg1").attr("src",json.realPath);
                    // $(".example-image").attr("src",json.realPath);
                    $(".example-image-link").attr("href",json.realPath);
                    // $(".lastImg").val(json.realPath);
                    $("#lastImg1").val(json.realPath);
                    // $(".pic").val(json.relativePath);
                    $("#pic1").val(json.relativePath);
                }
            })
        }

    </script>

列表显示

<form id="txForm" action="/album/list" method="post" class="form-horizontal" >
<div class="wrapper">

    <jsp:include page="menu.jsp"></jsp:include>

    <div class="page-content">
        <div class="content container">
            <div class="row">
                <div class="col-lg-12">
                    <h2 class="page-title">歌曲列表 <small>favor song</small></h2>
                </div>
            </div>

            <div class="row">
                <div class="col-lg-12">
                    <div class="widget">
                        <div class="widget-header"> <i class="icon-list-ol"></i>
                            <h3>搜索条件</h3>
                        </div>
                        <div class="widget-content">

                            <fieldset id="find">
                                <!--<legend class="section">Horizontal form</legend>-->
                                <div class="control-group">
                                    <label for="aname" class="control-label">专辑名</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-music"></i></span>
                                            <input type="text" value="${mq.aname}"  placeholder="如:thriller" name="aname" id="aname" class="form-control" />
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="company" class="control-label">唱片公司</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-user"></i></span>
                                            <input type="text" value="${mq.company}" placeholder="如:史诗唱片" name="company" id="company" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label for="lang" class="control-label">语种</label>

                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-user"></i></span>
                                            <input  type="text" value="${mq.lang}" placeholder="如:英语" name="lang" id="lang" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label for="searchPdate" class="control-label">日期</label>
                                    <div class="controls form-group">
                                        <div class="input-group"> <span class="input-group-addon"><i class="icon-reorder"></i></span>
                                            <input readonly id="searchPdate" value="<f:formatDate value='${mq.pdate}' pattern='yyyy-MM-dd'></f:formatDate>" type="text" placeholder="如:1970-01-01" name="pdate"  class="form-control" />
                                        </div>
                                    </div>
                                </div>




                            </fieldset>
                            <div class="form-actions text-right">
                                <div>
                                    <button id="search" class="btn btn-primary" type="submit">搜索</button>
                                    <button id="addAlbum" class="btn btn-primary" type="button" >添加专辑</button>
                                    <button id="toggleSearch" flag = "2" class="btn btn-default" type="button">收缩↑</button>
                                </div>
                            </div>


                        </div>
                        <div class="widget-content" >
                            <div class="body">
                                <table class="table table-striped table-images" style="color: white;font-size: 14px">
                                    <thead>
                                    <tr>
                                        <th class="hidden-xs-portrait">序号</th>
                                        <th>封面</th>
                                        <th>专辑名字</th>
                                        <th class="hidden-xs-portrait">唱片公司</th>
                                        <th class="hidden-xs">发行时间</th>
                                        <th class="hidden-xs">语种</th>
                                        <th></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${page.list}" var="album" varStatus="status">
                                        <tr>
                                            <td class="hidden-xs-portrait">${album.aid}</td>
                                            <td><img src="${filePath}${album.pic}" /></td>
                                            <td> ${album.aname} </td>
                                            <td class="hidden-xs-portrait">${album.company}</td>
                                            <td class="hidden-xs"> <p><strong><f:formatDate value="${album.pdate}" pattern="yyyy-MM-dd"></f:formatDate></strong></p> </td>
                                            <td class="hidden-xs">${album.lang}</td>
                                            <td><button class="btn btn-sm btn-primary" type="button" modify aid="${album.aid}"> 修改 </button>
                                                <button data-toggle="button" class="btn btn-sm btn-warning" aid="${album.aid}"> 删除 </button></td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                                <jsp:include page="pagination.jsp"></jsp:include>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

添加弹出层

<div id="albumPop" style="margin-right: 50px;margin-top: 50px; display: none">
    <form id="addAlbumForm" class="layui-form" method="post" action="/album/addAlbum" enctype="multipart/form-data" lay-filter="example">
        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">专辑名字</label>
            <div class="layui-input-block">
                <input  type="text" name="aname" style="color: black; border-color: lightgray;background-color: white"  lay-verify="aname" autocomplete="off" placeholder="请输入专辑名" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">发行公司</label>
            <div class="layui-input-block">
                <input  type="text" name="company" style="color: black; border-color: lightgray;background-color: white"  lay-verify="company" autocomplete="off" placeholder="请输入公司名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">发行时间</label>
            <div class="layui-input-block">
                <input  type="text" id="addPdate"  name="pdate" style="color: black; border-color: lightgray;background-color: white"  lay-verify="pdate" autocomplete="off" placeholder="请输入发行时间" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label" style="width:100px">图片</label>
            <div class="controls form-group">
                <div class="col-sm-4 col-md-2">
                    <div class="image-row">
                        <div class="image-set">
                            <a class="example-image-link" href="../../img/gallery-photo/image-3.jpg" data-lightbox="example-set" title="Click on the right side of the image to move forward.">
                                <img id="albumImg" class="example-image" src="../../img/gallery-photo/thumb-3.jpg" alt="Plants: image 1 0f 4 thumb" width="150" height="150" />
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="i-file" class="layui-form-label" style="width:100px">选择文件</label>
            <!--<div class="col-sm-4 control-label">选择文件</div>-->
            <div id="examples" class="section examples-section">
                <div class="col-sm-6">
                    <div class="input-group">
                        <input id='location' class='location' class="form-control" onclick="$('#i-file').click();">
                        <label class="input-group-btn">
                            <input  type="button" value="选择封面" class="btn btn-primary" onclick="$('#i-file').click();">
                        </label>
                    </div>
                </div>
                <input type="hidden" id="pic" class="pic" name="pic" lay-verify="pic">
                <input type="hidden" id="lastImg" class="lastImg" name="lastImg">
                <input type="file" name="picfile" id='i-file' class="i-file"  accept=".jpg, .png" onchange="submitFile()" style="border-color: lightgray;background-color: lightgray;display: none">
            </div>
        </div>

        <div class="layui-form-item" >
            <label for="lang2" class="layui-form-label " style="width:100px">语种</label>
            <div class="layui-input-block">
                <input id="lang2" class="lang" type="text" name="lang" style="color: black; border-color: lightgray;background-color: white"  lay-verify="lang" autocomplete="off" placeholder="请输入语种" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo1">添加专辑</button>
            </div>
        </div>
    </form>
</div>

修改弹出层

<div id="albumPop1" style="margin-right: 50px;margin-top: 50px; display: none">
    <form id="updateAlbumForm" class="layui-form" method="post" action="/album/updateAlbum" enctype="multipart/form-data" lay-filter="example">
        <input type="hidden" name="aid" id="aid">
        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">专辑名字</label>
            <div class="layui-input-block">
                <input  type="text" class="aname" name="aname" style="color: black; border-color: lightgray;background-color: white"  lay-verify="aname" autocomplete="off" placeholder="请输入专辑名" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">发行公司</label>
            <div class="layui-input-block">
                <input  type="text" class="company" name="company" style="color: black; border-color: lightgray;background-color: white"  lay-verify="company" autocomplete="off" placeholder="请输入公司名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px">发行时间</label>
            <div class="layui-input-block">
                <input  type="text" id="updatePdate" class="pdate"  name="pdate" style="color: black; border-color: lightgray;background-color: white"  lay-verify="pdate" autocomplete="off" placeholder="请输入发行时间" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label" style="width:100px">图片</label>
            <div class="controls form-group">
                <div class="col-sm-4 col-md-2">
                    <div class="image-row">
                        <div class="image-set">
                            <a class="example-image-link" href="../../img/gallery-photo/image-3.jpg" data-lightbox="example-set" title="Click on the right side of the image to move forward.">
                                <img id="albumImg1" class="example-image" src="../../img/gallery-photo/thumb-3.jpg" alt="Plants: image 1 0f 4 thumb" width="150" height="150" />
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="i-file1" class="layui-form-label" style="width:100px">选择文件</label>
            <!--<div class="col-sm-4 control-label">选择文件</div>-->
            <div class="examples" class="section examples-section">
                <div class="col-sm-6">
                    <div class="input-group">
                        <input id="location1" class='location' class="form-control" onclick="$('#i-file1').click();">
                        <label class="input-group-btn">
                            <input  type="button" id="i-check" value="选择封面" class="btn btn-primary" onclick="$('#i-file').click();">
                        </label>
                    </div>
                </div>
                <input type="hidden" id="pic1" class="pic" name="pic" lay-verify="pic">
                <input type="hidden" id="lastImg1" class="lastImg" name="lastImg">
                <input type="file" name="picfile" id='i-file1' class="i-file"  accept=".jpg, .png" onchange="submitFile()" style="border-color: lightgray;background-color: lightgray;display: none">
            </div>
        </div>

        <div class="layui-form-item" >
            <label for="lang1" class="layui-form-label " style="width:100px">语种</label>
            <div class="layui-input-block">
                <input id="lang1" class="lang" type="text" name="lang" style="color: black; border-color: lightgray;background-color: white"  lay-verify="lang" autocomplete="off" placeholder="请输入语种" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="demo2">修改专辑</button>
            </div>
        </div>
    </form>
</div>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1570277.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

金融贷款批准预测项目

注意&#xff1a;本文引用自专业人工智能社区Venus AI 更多AI知识请参考原站 &#xff08;[www.aideeplearning.cn]&#xff09; 在金融服务行业&#xff0c;贷款审批是一项关键任务&#xff0c;它不仅关系到资金的安全&#xff0c;还直接影响到金融机构的运营效率和风险管理…

LIN总线基础

文章目录 1 什么是LIN 总线&#xff1f;1.1 LIN总线的历史 2.LIN总线的特点3. 应用4 LIN总线基本概念4.1 LIN报文帧结构4.1.1 主节点与从节点4.1.2 调度表4.1.3网络管理4.1.4 帧头结构4.1.4.1 电平 1 什么是LIN 总线&#xff1f; LIN(Local Interconnect Network)是一种低成本…

linux 搭建Samba服务

Samba简介 SAMBA是⼀个实现不同操作系统之间⽂件共享和打印机共享的⼀种SMB协议的免费软件&#xff0c; SMB(Server Message block)协议是window下所使⽤的⽂件共享协议&#xff0c;我们在linux系统或 者其类unix系统当中可以通过samba服务来实现SMB功能。 &#xff08;1&…

Linux离线安装python3(源码编译)

1、下载python包 下载python3.9.6的源码包 python下载 下载后&#xff0c;解压&#xff0c;目录如下&#xff1a; -rw-------. 1 root root 1454 Aug 26 2023 anaconda-ks.cfg -rw-r--r--. 1 root root 25640094 Apr 4 21:52 Python-3.9.6.tgz drwxrwxr…

LC 96.不同的二叉搜索树

96.不同的二叉搜索树 给你一个整数 n &#xff0c;求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种&#xff1f;返回满足题意的二叉搜索树的种数。 示例 1&#xff1a; 输入&#xff1a; n 3 输出&#xff1a; 5 示例 2&#xff1a; 输入&#xff1a;…

配置启动nacos,保姆级教程

下载nacos 下载链接 https://github.com/alibaba/nacos/releases进去下拉&#xff0c;找到下载版本信息。 下载后如图所示。 配置数据库 在我们的conf文件夹中有一个nacos-mysql的数据库文件 我们需要导入数据库&#xff0c;可通过工具Navicat等进行导入。 会有一下几张表…

【面试经典150 | 动态规划】交错字符串

文章目录 写在前面Tag题目来源解题思路方法一&#xff1a;动态规划 写在最后 写在前面 本专栏专注于分析与讲解【面试经典150】算法&#xff0c;两到三天更新一篇文章&#xff0c;欢迎催更…… 专栏内容以分析题目为主&#xff0c;并附带一些对于本题涉及到的数据结构等内容进行…

JAVA毕业设计133—基于Java+Springboot+Vue的网上宠物店商城管理系统(源代码+数据库+12000字论文)

毕设所有选题&#xff1a; https://blog.csdn.net/2303_76227485/article/details/131104075 基于JavaSpringbootVue的网上宠物店商城管理系统(源代码数据库12000字论文)133 一、系统介绍 本项目前后端分离&#xff0c;分为管理员、用户两种角色 1、用户&#xff1a; 注册…

聚合DNS管理系统v1.0全新发布 域名解析管理系统

内容目录 一、详细介绍二、效果展示1.部分代码2.效果图展示 三、学习资料下载 一、详细介绍 聚合DNS管理系统可以实现在一个网站内管理多个平台的域名解析&#xff0c;目前已支持的域名平台有&#xff1a;阿里云、腾讯云、华为云、西部数码、CloudFlare。本系统支持多用户&…

数据挖掘中的PCA和KMeans:Airbnb房源案例研究

目录 一、PCA简介 二、数据集概览 三、数据预处理步骤 四、PCA申请 五、KMeans 聚类 六、PCA成分分析 七、逆变换 八、质心分析 九、结论 十、深入探究 10.1 第 1 步&#xff1a;确定 PCA 组件的最佳数量 10.2 第 2 步&#xff1a;使用 9 个组件重做 PCA 10.3 解释 PCA 加载和特…

高度不同的流体瀑布css实现方法

商城商品列表 实现瀑布流展示&#xff0c;通过flex或grid实现会导致每行中的列高度一致&#xff0c;无法达到错落有致的感觉&#xff1b; 为此需要用到&#xff1a; CSS columns 属性 columns 属性是一个简写属性&#xff0c;用于设置列宽和列数。 CSS 语法 columns: column-wi…

网络攻防中json序列化漏洞案例,fastjson远程命令执行漏洞原理

网络攻防中json序列化漏洞案例,fastjson远程命令执行漏洞原理。 网络攻防中的JSON序列化漏洞是指当应用程序使用JSON(JavaScript Object Notation)格式来序列化和反序列化对象时,由于不当处理或不安全的编程实践,导致攻击者能够执行恶意操作的安全漏洞。这些操作可能包括远…

成为不可替代的人,优秀到不能被忽视

一、资料描述 本套个人成长资料&#xff0c;大小30.89M&#xff0c;共有21个文件。 二、资料目录 00发刊词 成为不可替代的人.pdf 01累死你的不是工作&#xff0c;是错的职场价值观.pdf 02教你选好行业&#xff0c;远离裁员降薪.pdf 03如何选对公司&#xff0c;让高薪升值…

AJAX —— 学习(一)

目录 一、原生 AJAX &#xff08;一&#xff09;AJAX 介绍 1.理解 2.作用 3.最大的优势 4.应用例子 &#xff08;二&#xff09;XML 介绍 1.理解 2.作用 &#xff08;三&#xff09;AJAX 的特点 1.优点 2.缺点 二、HTTP 协议 &#xff08;一&#xff09;HTTP 介…

【攻防世界】ics-05

php://filter 伪协议查看源码 preg_replace 函数漏洞 1.获取网页源代码。多点点界面&#xff0c;发现点云平台设备维护中心时&#xff0c;页面发生变化。 /?pageindex 输入什么显示什么&#xff0c;有回显。 用php://filter读取网页源代码 ?pagephp://filter/readconvert.…

docker安装、调试qsign签名服务器

go-cqhttp 在 Docker 里早就部署好了&#xff0c;由于没有搭建 qsign 签名服务器&#xff0c;所以迟迟不敢上线。今天终于搞定了在 Docker 下安装 qsign 签名服务器了。这次用的docker市场里找到的镜像&#xff0c;下次找时间制作一个自己的镜像。 1 拉取和运行镜像&#xff1a…

轻薄本没有独立显卡如何运行stable diffusion

众所周知&#xff0c;Stable Diffusion WebUI 使用 GPU 模式运行。 一&#xff1a;检查自己显卡 打开任务管理器或者winR 输入dxdiag 查看自己显卡状态 很明显一般轻薄本只会带有集显&#xff0c;不能满足stable diffusion要求所以我们可以使用cup来运行stable diffusion 在…

转让1000万不良资产处置公司包变更需要多久

随着经济的发展和市场的变化&#xff0c;越来越多的公司需要进行资产的处置和转让&#xff0c;以提言公司的效益和盈利。山东不良资产处置公司作为一家专门服务于资产处置和转让的企业&#xff0c;其流程与变更步骤对于资产转让的操作至关重要。可以致电咨询我或者来公司面谈。…

电荷泵如何实现升压原来

电荷泵如何实现升压原来 某芯片自举栅极驱动内部原理图迪克森电荷泵 某芯片自举栅极驱动内部原理图 迪克森电荷泵 迪克森电荷泵&#xff08;Dickson Charge Pump&#xff09;是一种电压倍增器电路&#xff0c;可以将低电压升高到较高电压&#xff0c;相对于其他电压升压电路&a…

网站建设 之 发布ios

首先将forceDev改为false 然后执行npm run build:ios 然后用xocode安装到手机上进行测试 ##Version&#xff08;应用程序发布版本号&#xff09; 对应的就是CFBundleShortVersionString。该版本的版本号是三个时期分隔的整数组成的字符串&#xff1a; 第一个整数代表重大修…