JavaWeb寵物管理系統(tǒng)

成品展示:


image.png

用到的技術(shù):

Java+JSP+Mysql+Servlet+JDBC+JSTL+EL表達(dá)式+jQuery+Json

層次結(jié)構(gòu):

image.png

dao層:數(shù)據(jù)訪問(wèn)層
entity層:實(shí)體類(lèi)層
service層:業(yè)務(wù)邏輯層
servlet層:MVC結(jié)構(gòu)中的控制層

每層結(jié)構(gòu):

image.png

dao層:

BaseDao類(lèi):BaseDAO一般是提供從數(shù)據(jù)庫(kù) 增加磕蒲、刪除、修改記錄拧咳、查詢(xún)所有記錄扒怖、查詢(xún)符合某個(gè)條件記錄锦针、取得某條記錄等方法的底層數(shù)據(jù)操作自定義類(lèi)学歧。

petDao接口:制定增刪改查的標(biāo)準(zhǔn)淋样。

petDaoimpl類(lèi):petDao接口的實(shí)現(xiàn)類(lèi)胳螟,實(shí)現(xiàn)增刪改查的方法惦积。

entity層:

Pet類(lèi):pet實(shí)體類(lèi)接校。

service層:

petservice接口:制定增刪改查的業(yè)務(wù)邏輯標(biāo)準(zhǔn)。

petserviceimpl類(lèi):petservice接口的實(shí)現(xiàn)類(lèi)狮崩,實(shí)現(xiàn)增刪改查的業(yè)務(wù)邏輯蛛勉。

servlet層:

petServlet類(lèi):當(dāng)客戶(hù)機(jī)發(fā)送請(qǐng)求至服務(wù)器時(shí),服務(wù)器將請(qǐng)求信息轉(zhuǎn)發(fā)給Servlet睦柴,Servlet處理請(qǐng)求并生成響應(yīng)內(nèi)容并傳給Web服務(wù)器诽凌,然后再由Web服務(wù)器將響應(yīng)返回給客戶(hù)端。

Web:

js文件夾:存放JavaScript文件坦敌。

WEB-INF文件夾:WEB-INF是用來(lái)存儲(chǔ)服務(wù)端配置文件信息和在服務(wù)端運(yùn)行的類(lèi)文件的侣诵,它下面的東西不允許客戶(hù)端直接訪問(wèn)的。

.jsp文件:用java實(shí)現(xiàn)的動(dòng)態(tài)網(wǎng)頁(yè)恬试。


image.png

代碼:

BaseDao類(lèi):

package dao;


import java.sql.*;

public class BaseDao {
    
    private String driver="com.mysql.cj.jdbc.Driver";
    private String url="jdbc:mysql://localhost:3306/lcz?useUnicode=true&characterEncoding=utf-8";
    private String user="root";
    private String pwd="root";
    
    protected Connection conn=null;  
    protected PreparedStatement ps = null;   
    protected ResultSet rs = null;   
    
    public Connection getConnection() {
            try {
                Class.forName(driver);
                conn = DriverManager.getConnection(url,user,pwd);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        return conn;
    }

    public void close(Connection conn,PreparedStatement ps,ResultSet rs){
        try {
            if(rs != null){
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
            if(conn != null){
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    

      protected int executeUpdate(String sql, Object... params){
            int result = 0;
            try {
                conn = getConnection();
                ps = conn.prepareStatement(sql);
                if(params!=null){
                     for (int i = 0; i < params.length; i++) {
                         ps.setObject(i + 1, params[i]);
                     }
                }
                result = ps.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                //???
                close(conn, ps, rs);
            }
            return result;
        }
        
      protected ResultSet executeQuery(String sql, Object... params){
            try {
                conn = getConnection();
                ps = conn.prepareStatement(sql);
                if(params!=null){
                     for (int i = 0; i < params.length; i++) {
                         ps.setObject(i + 1, params[i]);
                     }
                }
                rs = ps.executeQuery();
                
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return rs;
        }
}

petDao接口:

package dao;

import entity.Pet;

import java.util.List;

public interface petDao {
    
    /**
     * @return
     * 顯示全部寵物信息
     */
    List<Pet>allPet();
    
    
    List<Pet>byType(int type);
    /**
     *添加寵物信息
     * @return
     */
    boolean addPet(Pet pet);
    
    /**
     * @param name
     * @return
     * 根據(jù)姓名判斷寵物是否重復(fù)
     */
    boolean isFlag(String name);
    
    /**
     * 根據(jù)ID獲取寵物信息
     * @param id
     * @return
     */
    Pet getById(int id);
    
    /**
     * 修改寵物信息
     * @param pet
     * @return
     */
    boolean update(Pet pet);
    
    /**
     * 刪除寵物
     * @param id
     * @return
     */
    boolean delete(int id);
    
}

petDaoimpl類(lèi):

package dao.impl;

import dao.BaseDao;
import dao.petDao;
import entity.Pet;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class petDaoImpl extends BaseDao implements petDao {

    @Override
    public List<Pet> allPet() {
        List<Pet> list = new ArrayList<Pet>();
        String sql = "SELECT * FROM pet";

        rs = executeQuery(sql);
        try {
            while (rs.next()) {
                Pet p = new Pet();
                p.setId(rs.getInt(1));
                p.setName(rs.getString(2));
                p.setPetBreed(rs.getInt(3));
                p.setSex(rs.getInt(4));
                p.setBirthday(rs.getString(5));
                list.add(p);
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            close(conn, ps, rs);
        }
        return list;
    }

    @Override
    public boolean addPet(Pet pet) {
        String sql = "INSERT INTO pet VALUES(NULL,?,?,?,?,?)";
        int n = super.executeUpdate(sql, pet.getName(), pet.getPetBreed(), pet.getSex(), pet.getBirthday(),
                pet.getDescription());
        return n > 0 ? true : false;
    }

    @Override
    public boolean isFlag(String name) {
        String sql = "SELECT * FROM pet WHERE petname=?";
        rs = executeQuery(sql, name);
        boolean flag = false;
        try {
            if (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            close(conn, ps, rs);
        }
        return flag;
    }

    @Override
    public List<Pet> byType(int type) {
        // TODO Auto-generated method stub
        List<Pet> list = new ArrayList<Pet>();
        String sql = "SELECT * FROM pet WHERE petBreed=?";
        rs = executeQuery(sql, type);
        try {
            while (rs.next()) {
                Pet p = new Pet();
                p.setId(rs.getInt(1));
                p.setName(rs.getString(2));
                p.setPetBreed(rs.getInt(3));
                p.setSex(rs.getInt(4));
                p.setBirthday(rs.getString(5));
                list.add(p);
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            close(conn, ps, rs);
        }
        return list;
    }

    @Override
    public Pet getById(int id) {

        String sql = "SELECT * FROM pet WHERE petId=?";
        rs = executeQuery(sql, id);
        try {
            if (rs.next()) {
                Pet p = new Pet();
                p.setId(rs.getInt(1));
                p.setName(rs.getString(2));
                p.setPetBreed(rs.getInt(3));
                p.setSex(rs.getInt(4));
                p.setBirthday(rs.getString(5));
                p.setDescription(rs.getString(6));
                return p;
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            close(conn, ps, rs);
        }
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean update(Pet pet) {
        // TODO Auto-generated method stub
        String sql = "update pet set petName=?,petBreed=?,petSex=?,birthday=?,description=? where petId=?";
        int n = super.executeUpdate(sql, pet.getName(), pet.getPetBreed(), pet.getSex(), pet.getBirthday(),
                pet.getDescription(), pet.getId());
        return n > 0 ? true : false;
    }

    @Override
    public boolean delete(int id) {
        // TODO Auto-generated method stub
        // TODO Auto-generated method stub
        String sql = "delete from pet where petId=?";
        int n = super.executeUpdate(sql, id);
        return n > 0 ? true : false;
    }

}

Pet類(lèi):

package entity;

public class Pet {
    private int id;
    private String name;
    private int sex;
    private int petBreed;
    private String  birthday;
    private String description;
    
    
    public int getPetBreed() {
        return petBreed;
    }
    public void setPetBreed(int petBreed) {
        this.petBreed = petBreed;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getSex() {
        return sex;
    }
    public void setSex(int sex) {
        this.sex = sex;
    }
    public String getBirthday() {
        return birthday;
    }
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public Pet(String name, int sex, int petBreed, String birthday, String description) {
        super();
        this.name = name;
        this.sex = sex;
        this.petBreed = petBreed;
        this.birthday = birthday;
        this.description = description;
    }
    public Pet() {
        super();
    }
    public Pet(int id, String name, int sex, int petBreed, String birthday, String description) {
        super();
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.petBreed = petBreed;
        this.birthday = birthday;
        this.description = description;
    }
    
}

petservice接口:

package service;

import entity.Pet;

import java.util.List;

public interface petService {

    List<Pet>allPet();
    
    List<Pet>byType(int type);
    
    boolean addPet(Pet pet);
    
    boolean isFlag(String name);
    
    Pet getById(int id);
    

    boolean update(Pet pet);
    

    boolean delete(int id);
    
}

petserviceimpl類(lèi):

package service.impl;

import dao.impl.petDaoImpl;
import dao.petDao;
import entity.Pet;
import service.petService;

import java.util.List;

public class petServiceImpl implements petService {
    petDao dao=new petDaoImpl();
    @Override
    public List<Pet> allPet() {
        return dao.allPet();
    }

    @Override
    public boolean addPet(Pet pet) {
        return dao.addPet(pet);
    }

    @Override
    public boolean isFlag(String name) {
        return dao.isFlag(name);
    }

    @Override
    public List<Pet> byType(int type) {
        return dao.byType(type);
    }

    @Override
    public Pet getById(int id) {
        return dao.getById(id);
    }

    @Override
    public boolean update(Pet pet) {
        
        return dao.update(pet);
    }

    @Override
    public boolean delete(int id) {
        return dao.delete(id);
    }

}

petServlet類(lèi):

package servlet;

import entity.Pet;
import service.impl.petServiceImpl;
import service.petService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Servlet implementation class petServlet
 */
@WebServlet("/petServlet")
public class petServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        // 獲取temp值
        String temp = request.getParameter("temp");
        petService service = new petServiceImpl();
        PrintWriter out = response.getWriter();
        if (temp.equals("getAll")) {
            // 查詢(xún)?nèi)啃畔?            String petBreed = request.getParameter("petBreed");
            List<Pet> list = service.allPet();
            request.setAttribute("list", list);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else if (temp.equals("bytype")) {
            String type = request.getParameter("type");
            List<Pet> list = null;
            if (type == "") {
                list = service.allPet();
            } else {
                list = service.byType(Integer.parseInt(type));
            }

            request.setAttribute("list", list);
            request.getRequestDispatcher("main.jsp").forward(request, response);
        } else if (temp.equals("getname")) {
            // 獲取昵稱(chēng)
            String name = request.getParameter("name");
            if (service.isFlag(name)) {
                out.print(true);
            } else {
                out.print(false);
            }
        } else if (temp.equals("add")) {
            // 添加信息
            String name = request.getParameter("name");
            String type = request.getParameter("type");
            String sex = request.getParameter("sex");
            String date = request.getParameter("date");
            String description = request.getParameter("description");
            Pet pet = new Pet(name, Integer.parseInt(sex),Integer.parseInt(type),  date, description);

            if (service.addPet(pet)) {
                out.print("<script>alert('添加成功! ');location.href='petServlet?temp=getAll';</script>");
            } else {
                out.print("<script>alert('添加失敗! ');location.href='add.jsp';</script>");
            }
        } else if(temp.equals("toUpdate")){

            int id = Integer.parseInt(request.getParameter("id"));
            Pet pet = service.getById(id);
            request.setAttribute("pet", pet);
            request.getRequestDispatcher("/update.jsp").forward(request, response);

        } else if(temp.equals("update")){

            int id = Integer.parseInt(request.getParameter("id"));
            String name = request.getParameter("name");
            int type = Integer.parseInt(request.getParameter("type"));
            int sex = Integer.parseInt(request.getParameter("sex"));
            String date = request.getParameter("date");
            String description = request.getParameter("description");
            Pet pet = new Pet(id,name,sex,type,date,description);
            if (service.update(pet)) {
                out.print("<script>alert('修改成功! ');location.href='petServlet?temp=getAll';</script>");
            } else {
                out.print("<script>alert('修改失敗! ');location.href='petServlet?temp=toUpdate&id="+id+";</script>");
            }
        }else if(temp.equals("delete")){

            int id = Integer.parseInt(request.getParameter("id"));
            if (service.delete(id)) {
                out.print("<script>alert('刪除成功! ');location.href='petServlet?temp=getAll';</script>");
            } else {
                out.print("<script>alert('刪除失敗! ');location.href='petServlet?temp=getAll';</script>");
            }
        }
        out.flush();
        out.close();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

add頁(yè)面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
    //獲取項(xiàng)目路徑
    String path = request.getContextPath();
    //協(xié)議名+主機(jī)名+服務(wù)器端口號(hào)+項(xiàng)目名
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
        
    </style>
    </head>
    <body>
    <h2>寵物新增</h2>
        <form action="petServlet?temp=add" method="post">
            <p>昵稱(chēng):<input type="text" name="name"  id="name"/> <span id="pname"></span></p>
            <p>品種:<select name="type" id="type">
                <option value="">請(qǐng)選擇</option>
                    <option value="1">狗</option>
                    <option value="2">貓</option>
                    <option value="3">鳥(niǎo)</option>
                    <option value="4">兔</option>
            </select></p>
            <p>性別:
                <input type="radio" name="sex" value="2">雌
                <input type="radio" name="sex" value="1">雄
            </p>
            <p>出生日期:<input type="text" name="date" id="date"/> yyyy-MM-dd格式</p>
            <p>寵物描述:<textarea name="description" id="description"  cols="40"   rows="4"   style="OVERFLOW:   hidden"></textarea></p>
            <input type="submit" id="btn" value="保存"/> 
            <input type="button" value="重置"  />
        </form>
        <script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
        
        
            $(function(){
                $("#name").blur(function(){
                    
                    var name = $(this).val();
                    //發(fā)送ajax請(qǐng)求
                    $.ajax({
                        url:"petServlet",
                        data:{"temp":"getname","name":name},
                        type:"get",
                        dataType:"json",
                        success:function(result){
                            if(result){
                                alert("昵稱(chēng)已存在");
                                //禁用提交按鈕
                                $("#btn").attr("disabled",true);
                            }else{
                                alert("昵稱(chēng)可用");
                                //解除提交按鈕的禁用
                                $("#btn").attr("disabled",false);
                            }
                        }
                    });
                })
                
                
                //表單驗(yàn)證
                $("form").submit(function(){
                    if (checkname() && checktype() && checkdate()) {
                        return true;
                    }else{
                        return false;
                    }
                })
                
                function checkname(){
                    var name=$("#name").val();
                    if (name=="") {
                        alert("寵物昵稱(chēng)不能為空")
                        return false;
                    }
                    return true;
                }
                
                function checktype(){
                    var type=$("#type").val();
                    if (type=="") {
                        alert("請(qǐng)選擇寵物類(lèi)型")
                        return false;
                    }
                    return true;
                }
                
                
                function checkdate(){
                    var date=$("#date").val();
                    if (date=="") {
                        alert("寵物出生日期不能為空")
                        return false;
                    }
                    var reg = /^(19\d{2}|20[01]\d|2020)-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/;
                    if(!reg.test(saleStarting)){
                        alert("寵物出生日期格式不正確");
                        return false;
                    }
                    return true;
                }
                
            })
        </script>
    </body>
</html>

index頁(yè)面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
    //獲取項(xiàng)目路徑
    String path = request.getContextPath();
    //協(xié)議名+主機(jī)名+服務(wù)器端口號(hào)+項(xiàng)目名
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            window.location.href="petServlet?temp=getAll";
        })
    </script>
    </body>
</html>

main頁(yè)面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>  
     <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
 <%
    //獲取項(xiàng)目路徑
    String path = request.getContextPath();
    //協(xié)議名+主機(jī)名+服務(wù)器端口號(hào)+項(xiàng)目名
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style>
            * {
                margin: 0px auto;
                text-align: center;
            }
             p {
                
                text-align:center;
            }
        </style>
    </head>

    <body>
        <form action="petServlet?temp=bytype" method="post">
            <p> 品種
                <select name="type">
                    <option value="">請(qǐng)選擇</option>
                    <option value="1">狗</option>
                    <option value="2">貓</option>
                    <option value="3">鳥(niǎo)</option>
                    <option value="4">兔</option>
                </select> <input type="submit" value="查詢(xún)" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="add.jsp">新增寵物</a>
            </p>
        </form>

        <table border="1" width="700px" style="text-align: center;">
            <tr>
                <th>寵物昵稱(chēng)</th>
                <th>種類(lèi)</th>
                <th>出生日期</th>
                <th>性別</th>
                <th>操作</th>

            </tr>
            <c:forEach items="${list }" var="p">
                <tr>
                    <td>${p.name}</td>
                    <td>
                        <c:choose>
                            <c:when test="${p.petBreed==1 }">狗</c:when>
                            <c:when test="${p.petBreed==2 }">貓</c:when>
                            <c:when test="${p.petBreed==3 }">鳥(niǎo)</c:when>
                            <c:otherwise>
                                兔
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td> ${fn:substring(p.birthday, 0, 10)}</td>
                    <td>
                        <c:if test="${p.sex eq 1}">雄</c:if>
                        <c:if test="${p.sex eq 2}">雌</c:if>
                    </td>
                    <td>
                        <a href="petServlet?temp=toUpdate&id=${p.id }">編輯</a>
                        <a href="petServlet?temp=delete&id=${p.id }" style="color:red">刪除</a>
                    </td>

                </tr>
            </c:forEach>
        </table>
        <script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            $(function() {
                
                $("table tr:even").css("background", "#9ECEF8");
                $("table tr:first").css("background", "darkgrey");
            })
        </script>

    </body>

    </body>
</html>

update頁(yè)面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>  
     <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
 <%
    //獲取項(xiàng)目路徑
    String path = request.getContextPath();
    //協(xié)議名+主機(jī)名+服務(wù)器端口號(hào)+項(xiàng)目名
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
        
    </style>
    </head>
    <body>
    <h2>寵物編輯</h2>
        <form action="petServlet?temp=update" method="post">
            <input type="hidden" id="id" name="id" value="${pet.id }"}/>
            <p>昵稱(chēng):<input type="text" name="name"  id="name" value="${pet.name}" /> <span id="pname"></span></p>
            <p>品種:<select name="type" id="type">
                <option value="">請(qǐng)選擇</option>
                    
                    <option value="1" <c:if test='${pet.petBreed == 1}'>selected</c:if>>狗</option>
                    <option value="2" <c:if test='${pet.petBreed == 2}'>selected</c:if>>貓</option>
                    <option value="3" <c:if test='${pet.petBreed == 3}'>selected</c:if>>鳥(niǎo)</option>
                    <option value="4" <c:if test='${pet.petBreed == 4}'>selected</c:if>>兔</option>
            </select></p>
            <p>性別:
                <input type="radio" name="sex" value="2" <c:if test='${pet.sex == 2}'>checked</c:if>>雌
                <input type="radio" name="sex" value="1" <c:if test='${pet.sex == 1}'>checked</c:if>>雄
            </p>
            <p>出生日期:<input type="text" name="date" id="date" value="${pet.birthday}" /> yyyy-MM-dd格式</p>
            <p>寵物描述:<textarea name="description" id="description"  cols="40"   rows="4"   style="OVERFLOW:   hidden">${pet.description }</textarea></p>
            <input type="submit" id="btn" value="保存"/> 
            <input type="button" value="重置"  />
        </form>
        <script src="js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
        
        
            $(function(){
                
                
                //表單驗(yàn)證
                $("form").submit(function(){
                    if (checkname() && checktype() && checkdate()) {
                        return true;
                    }else{
                        return false;
                    }
                })
                
                function checkname(){
                    var name=$("#name").val();
                    if (name=="") {
                        alert("寵物昵稱(chēng)不能為空")
                        return false;
                    }
                    return true;
                }
                
                function checktype(){
                    var type=$("#type").val();
                    if (type=="") {
                        alert("請(qǐng)選擇寵物類(lèi)型")
                        return false;
                    }
                    return true;
                }
                
                
                function checkdate(){
                    var date=$("#date").val();
                    if (date=="") {
                        alert("寵物出生日期不能為空")
                        return false;
                    }
                    var reg = /^(19\d{2}|20[01]\d|2020)-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/;
                    if(!reg.test(saleStarting)){
                        alert("寵物出生日期格式不正確");
                        return false;
                    }
                    return true;
                }
                
            })
        </script>
    </body>
</html>

數(shù)據(jù)庫(kù):


image.png
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for pet
-- ----------------------------
DROP TABLE IF EXISTS `pet`;
CREATE TABLE `pet`  (
  `petId` int(20) NOT NULL AUTO_INCREMENT COMMENT '寵物ID',
  `petName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '寵物名稱(chēng)',
  `petBreed` int(11) NOT NULL COMMENT '寵物種類(lèi):1狗窝趣,2貓,3鳥(niǎo)训柴,4兔',
  `petSex` int(11) NOT NULL COMMENT '寵物性別',
  `birthday` date NOT NULL COMMENT '生日',
  `description` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '描述',
  PRIMARY KEY (`petId`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of pet
-- ----------------------------
INSERT INTO `pet` VALUES (1, '小白', 1, 2, '2020-11-02', '');
INSERT INTO `pet` VALUES (2, '小毛', 2, 2, '2020-11-01', '');
INSERT INTO `pet` VALUES (3, '鸚鵡', 3, 1, '2020-11-01', '');
INSERT INTO `pet` VALUES (4, '小黃', 1, 2, '2020-11-01', '');
INSERT INTO `pet` VALUES (5, '小黑', 1, 1, '2020-11-01', '');
INSERT INTO `pet` VALUES (6, '嘖嘖', 4, 1, '2020-11-01', '');
INSERT INTO `pet` VALUES (8, '毛毛', 4, 1, '2020-01-01', '');

SET FOREIGN_KEY_CHECKS = 1;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末哑舒,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子幻馁,更是在濱河造成了極大的恐慌洗鸵,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,884評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件仗嗦,死亡現(xiàn)場(chǎng)離奇詭異膘滨,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)稀拐,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,755評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)火邓,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人德撬,你說(shuō)我怎么就攤上這事铲咨。” “怎么了蜓洪?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,369評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵纤勒,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我隆檀,道長(zhǎng)摇天,這世上最難降的妖魔是什么粹湃? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,799評(píng)論 1 285
  • 正文 為了忘掉前任,我火速辦了婚禮泉坐,結(jié)果婚禮上为鳄,老公的妹妹穿的比我還像新娘。我一直安慰自己腕让,他們只是感情好济赎,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,910評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著记某,像睡著了一般司训。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上液南,一...
    開(kāi)封第一講書(shū)人閱讀 50,096評(píng)論 1 291
  • 那天壳猜,我揣著相機(jī)與錄音,去河邊找鬼滑凉。 笑死统扳,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的畅姊。 我是一名探鬼主播咒钟,決...
    沈念sama閱讀 39,159評(píng)論 3 411
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼若未!你這毒婦竟也來(lái)了朱嘴?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,917評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤粗合,失蹤者是張志新(化名)和其女友劉穎萍嬉,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體隙疚,經(jīng)...
    沈念sama閱讀 44,360評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡壤追,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,673評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了供屉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片行冰。...
    茶點(diǎn)故事閱讀 38,814評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖伶丐,靈堂內(nèi)的尸體忽然破棺而出悼做,到底是詐尸還是另有隱情,我是刑警寧澤撵割,帶...
    沈念sama閱讀 34,509評(píng)論 4 334
  • 正文 年R本政府宣布贿堰,位于F島的核電站辙芍,受9級(jí)特大地震影響啡彬,放射性物質(zhì)發(fā)生泄漏羹与。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,156評(píng)論 3 317
  • 文/蒙蒙 一庶灿、第九天 我趴在偏房一處隱蔽的房頂上張望纵搁。 院中可真熱鬧,春花似錦往踢、人聲如沸腾誉。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,882評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)利职。三九已至,卻和暖如春瘦癌,著一層夾襖步出監(jiān)牢的瞬間猪贪,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,123評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工讯私, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留热押,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,641評(píng)論 2 362
  • 正文 我出身青樓斤寇,卻偏偏與公主長(zhǎng)得像桶癣,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子娘锁,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,728評(píng)論 2 351

推薦閱讀更多精彩內(nèi)容