大項目之網上書城(八)——資料庫大改&添加圖書

来源:https://www.cnblogs.com/zhangA/archive/2019/06/21/11067356.html
-Advertisement-
Play Games

那麼book表一分為n,多個子表更新數據的時候會聯動book表更新數據。然後順勢寫了個增加圖書的方法。內容不多,錯誤不少、 ...


目錄

大項目之網上書城(八)——資料庫大改&添加圖書

主要改動

今天也是各種各種各種出錯的一天啊,經歷了各種方法的重寫,各種觸發器的重寫。

那麼book表一分為n,多個子表更新數據的時候會聯動book表更新數據。然後順勢寫了個增加圖書的方法。內容不多,錯誤不少、

1.資料庫新增表

代碼

以clothing為例,為各個類都新增了一個表。

DROP TABLE IF EXISTS `clothing`;
CREATE TABLE `clothing` (
  `book_name` varchar(40) NOT NULL,
  `price` double NOT NULL,
  `describtion` varchar(200) DEFAULT NULL,
  `clazz` varchar(40) NOT NULL,
  `second_id` int(11) NOT NULL AUTO_INCREMENT,
  `book_img` blob,
  `click_num` int(11) NOT NULL,
  `buy_num` int(9) NOT NULL,
  `re_du` int(12) DEFAULT NULL,
  `count` int(6) NOT NULL,
  `is_new` int(1) NOT NULL,
  `insert_date` date NOT NULL,
  `book_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`second_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

2.資料庫新增觸發器

還是以clothing表為例,兩個方法,一個是當子表插入數據時,book表插入一條同樣的數據,2是子表更新時,book也做出相應更新。

DROP TRIGGER IF EXISTS `c_insert`;
DELIMITER ;;
CREATE TRIGGER `c_insert` AFTER INSERT ON `clothing` FOR EACH ROW begin
    insert into book(book_name,price,describtion,clazz,second_id,click_num,buy_num,count,is_new,insert_date) values(NEW.book_name,NEW.price,NEW.describtion,NEW.clazz,NEW.second_id,0,0,NEW.count,1,NEW.insert_date);
end
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `c_update`;
DELIMITER ;;
CREATE TRIGGER `c_update` AFTER UPDATE ON `clothing` FOR EACH ROW begin
    update book set book.re_du = NEW.click_num + NEW.buy_num * 100,book.click_num = NEW.click_num,book.buy_num = NEW.buy_num where clazz = new.clazz and second_id = new.second_id;
end
;;
DELIMITER ;

3.其他對BookService和BookDao的修改

代碼

因為改得代碼太多,太亂了,不好發,於是重新都發一下實現類好了。

daoimpl

package cn.edu.bdu.mc.daos.impls;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.edu.bdu.mc.beans.Book;
import cn.edu.bdu.mc.daos.BookDao;
import cn.edu.bdu.mc.utils.JDBCUtil;

public class BookDaoImpl implements BookDao {

    private DataSource dataSource = JDBCUtil.getDataSource();
    private QueryRunner queryRunner = new QueryRunner(dataSource);      

    @Override
    public Book findNewBookByPaiMing(int shu) throws SQLException {
        // TODO Auto-generated method stub
        String sql = "select * from (select * from book where is_new = 1 order by re_du desc)as book1 limit "+(shu-1)+",1";
        return queryRunner.query(sql, new BeanHandler<Book>(Book.class));
    }

    @Override
    public List<Book> findBookReMen(int page) throws SQLException {
        String sql = "select * from (select * from book order by re_du desc)as book1 limit "+(page-1)*2+",2";
        return queryRunner.query(sql, new BeanListHandler<Book>(Book.class));
    }
    
    @Override
    public void insert(Book book) throws SQLException {
        // TODO Auto-generated method stub
        String sql = "insert into "+book.getClazz()+"(book_name,price,describtion,clazz,click_num,buy_num,count,is_new,insert_date) values(?,?,?,?,0,0,?,1,?)";
        queryRunner.update(sql,book.getBook_name(),book.getPrice(),book.getDescribtion(),book.getClazz(),book.getCount(),new Date());
    }
    
    @Override
    public Book findBookById(int book_id) throws SQLException{
        String sql = "select * from book where book_id = ?";
        return queryRunner.query(sql, new BeanHandler<Book>(Book.class),book_id);
    }
    
    @Override
    public List<Book>findAllBook() throws SQLException {
        String sql = "select * from book";
        return queryRunner.query(sql, new BeanListHandler<Book>(Book.class));
    }
    
    @Override
    public void deleteById(int book_id) throws SQLException {
        String sql = "delete from book where book_id = ?";
        queryRunner.update(sql,book_id);
    }

    @Override
    public void update(Book book) throws SQLException {
        String sql = "update book set book_name = ?, price = ?, describtion = ?, clazz = ?, second_id = ?, click_num = ?, buy_num = ?, count = ?, is_new = ? where book_id = ?";
        queryRunner.update(sql,book.getBook_name(),book.getPrice(),book.getDescribtion(),book.getClazz(),book.getSecond_id(),book.getClick_num(),book.getBuy_num(),book.getCount(),book.getIs_new(),book.getBook_id());
    }

    @Override
    public void addImgByName(String book_name, String path) throws SQLException, IOException {
        // TODO Auto-generated method stub
        Connection conn = null;
        PreparedStatement ps = null;
        FileInputStream in = null;
        in = new FileInputStream(new File(path));
        conn = JDBCUtil.getConn();
        String sql = "update book set book_img = ? where book_name = ?";
        ps = conn.prepareStatement(sql);
        ps.setBinaryStream(1, in, in.available());
        ps.setString(2, book_name);
        int count = ps.executeUpdate();
        if (count > 0) {
            System.out.println("插入成功!");
        } else {
            System.out.println("插入失敗!");
        }
        JDBCUtil.release(conn, ps);
    }

    @Override
    public InputStream getImgById(int book_id) throws SQLException {
        // TODO Auto-generated method stub
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        InputStream in = null;
        try {
            conn = JDBCUtil.getConn();
            String sql = "select book_img from book where book_id = ?";
            ps = conn.prepareStatement(sql);
            ps.setInt(1, book_id);
            rs = ps.executeQuery();
            while (rs.next()) {
                in = rs.getBinaryStream("book_img");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        JDBCUtil.release(conn, ps, rs);
        return in;
    }

    @Override
    public Book findBookByClazzAndEr_id(String clazz, int er_id) throws SQLException {
        // TODO Auto-generated method stub
        String sql = "select * from "+clazz+" where second_id = ?";
        Book book = queryRunner.query(sql, new BeanHandler<Book>(Book.class),er_id);
        if(book.getBook_id()==0) {
            sql = "select * from book where clazz = ? and second_id = ?";
            book.setBook_id(queryRunner.query(sql,new BeanHandler<Book>(Book.class),clazz,er_id).getBook_id());
            sql = "update "+clazz+" set book_id = ?";
            queryRunner.update(sql,book.getBook_id());
        }
        return book;
    }

    @Override
    public void updateClazz(Book book) throws SQLException {
        // TODO Auto-generated method stub
        String sql = "update "+book.getClazz()+" set book_name = ?, price = ?, describtion = ?, clazz = ?, book_id = ?, click_num = ?, buy_num = ?, count = ?, is_new = ? where second_id = ?";
        queryRunner.update(sql,book.getBook_name(),book.getPrice(),book.getDescribtion(),book.getClazz(),book.getBook_id(),book.getClick_num(),book.getBuy_num(),book.getCount(),book.getIs_new(),book.getSecond_id());
    }

    
}

serviceimpl

package cn.edu.bdu.mc.services.impls;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import cn.edu.bdu.mc.beans.Book;
import cn.edu.bdu.mc.daos.BookDao;
import cn.edu.bdu.mc.daos.impls.BookDaoImpl;
import cn.edu.bdu.mc.services.BookService;
import cn.edu.bdu.mc.utils.JDBCUtil;

public class BookServiceImpl implements BookService {

    private DataSource dataSource = JDBCUtil.getDataSource();
    private BookDao dao = new BookDaoImpl(); 

    @Override
    public Book findNewBookByPaiMing(int shu) throws SQLException {
        // TODO Auto-generated method stub
        return dao.findNewBookByPaiMing(shu);
    }

    @Override
    public void click(int book_id) throws SQLException {
        // TODO Auto-generated method stub
        Book book = dao.findBookById(book_id);
        book.setClick_num(book.getClick_num()+1);
        dao.update(book);
        dao.updateClazz(book);
    }
    
    @Override
    public void buy(int book_id) throws SQLException {
        // TODO Auto-generated method stub
        Book book = dao.findBookById(book_id);
        book.setBuy_num(book.getBuy_num()+1);
        dao.update(book);
    }

    @Override
    public List<Book> findBookReMen(int page) throws SQLException {
        return dao.findBookReMen(page); 
    }

    @Override
    public void addImgByName(String book_name, String path) throws SQLException, IOException {
        // TODO Auto-generated method stub
        dao.addImgByName(book_name, path);
    }

    @Override
    public InputStream getImgById(int book_id) throws SQLException {
        // TODO Auto-generated method stub
        return dao.getImgById(book_id);
    }

    @Override
    public Book findBookByClazzAndEr_id(String clazz, int er_id) throws SQLException {
        // TODO Auto-generated method stub
        return dao.findBookByClazzAndEr_id(clazz, er_id);
    }

    @Override
    public List<Book> findBookByClazz(String clazz) throws SQLException {
        List<Book> list = dao.findAllBook();
        List<Book> newList = new ArrayList<>();
        //lambda表達式,emmmm,的確可讀性不太好的樣子。
        list.forEach(book->{if(book.getClazz().equals(clazz)){newList.add(book);}});
        /*
            相當於
            for (Book book : newList) {
                if(book.getClazz().equals(clazz)){
                    newList.add(book);
                }
            }
        */
        return newList;
    }

    @Override
    public void insert(String book_name, double price, String describtion, String clazz, int count)
            throws SQLException {
        // TODO Auto-generated method stub
        Book book = new Book(book_name,price,describtion,clazz,count);
        dao.insert(book);
    }

    
}

4.addBook.jsp

代碼

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>添加圖書</title>
</head>
<body style="background-color:#bbb;width:1400px;margin:0 auto">
<!-- 調用頭部頁面 -->
<div style="width:100%;height:100px;float:left">
<jsp:include page="/admin/head.jsp"></jsp:include>
</div>
<!-- 通用內容體大小 -->
<div style="width:70%;height:600px;float:left;margin-left:15%;">
    <!-- 好看的圖 -->
    <div style="width:55%;height:100%;float:left;margin-top:10%;">
        <img alt="拿書男孩" src="${pageContext.request.contextPath }/client/img/admin.jpg" style="width:90%;">
    </div>
    <!-- 登錄界面 -->
    <div style="width:45%;height:80%;float:left;margin-top:7%">
        <form action="${pageContext.request.contextPath }/AddNewBook" method="post"
        enctype="multipart/form-data" class="form-horizontal" role="form">
        <div class="form-group">
            <label for="lastname" class="col-sm-3 control-label input-lg">書名</label>
            <div class="col-sm-9">
                <input type="text" name="book_name" class="form-control input-lg"
                       placeholder="請輸入書名" style="float:left"/>
            </div>
        </div>
        <div class="form-group">
            <label for="lastname" class="col-sm-3 control-label input-lg">價格</label>
            <div class="col-sm-9">
                <input type="text" name="price" class="form-control input-lg"
                       placeholder="請輸入價格" style="float:left"/>
            </div>
        </div>
        <div class="form-group">
            <label for="lastname" class="col-sm-3 control-label input-lg">描述</label>
            <div class="col-sm-9">
            <textarea class="form-control input-lg" name="describtion" rows="2"
                       placeholder="請輸入描述" style="float:left"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label for="lastname" class="col-sm-3 control-label input-lg">類別</label>
            <div class="col-sm-9">
                <select name="clazz" class="form-control input-lg" style="float:left">
                <option value="clothing">服裝</option>
                <option value="food">食品</option>
                <option value="net_literature">網路文學</option>
                <option value="nursery">育嬰童</option>
                <option value="pai">好書拍賣</option>
                <option value="residence">家居</option>
                <option value="sport">運動戶外</option>
            </select>
            </div>
        </div>
        <div class="form-group">
            <label for="lastname" class="col-sm-3 control-label input-lg">數量</label>
            <div class="col-sm-9">
                <input type="text" name="count" class="form-control input-lg"
                       placeholder="請輸入數量" style="float:left"/>
            </div>
        </div>
        <div class="form-group">
            <label for="exampleInputFile" class="col-sm-3 control-label input-lg" style="float:left;">圖片</label>
            <div class="col-sm-9">
                <input type="file" name="img" class="form-control input-lg" style="float:left">
            </div>
        </div>
        <div class="form-group">
            <label for="firstname" class="col-sm-1 control-label input-lg"></label>
            <div class="col-sm-5">
                <input type="submit" name="submit" value="提交"
                class="form-control input-lg btn btn-primary"style="width:100%;float:left"/>
            </div>
            <div class="col-sm-5">
                <input type="reset" name="reset" value="重置" id="re"
                class="form-control input-lg btn btn-warning"style="width:100%;float:left"/>
            </div>
        </div>
      </form>
  </div>

</div>
<!-- 調用底部頁面 -->
<div style="width:100%;height:60px;float:left">
<jsp:include page="/admin/foot.jsp"></jsp:include>
</div>
</body>
</html>

效果圖

5.AddNewBookServlet

代碼

package cn.edu.bdu.mc.servlets;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

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 org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


import cn.edu.bdu.mc.services.BookService;
import cn.edu.bdu.mc.services.impls.BookServiceImpl;

/**
 * Servlet implementation class AddNewBookServlet
 */
@WebServlet("/AddNewBook")
public class AddNewBookServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddNewBookServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BookService bookService = new BookServiceImpl();
//      String book_name = request.getParameter("book_name");
//      String price = request.getParameter("price");
//      String describtion = request.getParameter("describtion");
//      String clazz = request.getParameter("clazz");
//      String count = request.getParameter("count");
//      //測試成功
//      response.getWriter().write(book_name+"<br>"+price+"<br>"+describtion+"<br>"+clazz+"<br>"+count);
        //把enctype="multipart/form-data"之後好像不能用普通方法獲取了。。
        DiskFileItemFactory factory = new DiskFileItemFactory();
        File file = new File("d:\\Target");
        if(!file.exists()) {
            file.mkdirs();
        }
        factory.setRepository(file);
        ServletFileUpload fileUpload = new ServletFileUpload(factory);
        fileUpload.setHeaderEncoding("utf-8");
        try {
            List<FileItem> fileItems = fileUpload.parseRequest(request);
            String value = null;
            String book_name = fileItems.get(0).getString("utf-8");
            Double price = Double.parseDouble(fileItems.get(1).getString("utf-8"));
            String describtion = fileItems.get(2).getString("utf-8");
            String clazz = fileItems.get(3).getString("utf-8");
            int count = Integer.parseInt(fileItems.get(4).getString("utf-8"));
            for (FileItem fileItem : fileItems) {
                if(!fileItem.isFormField()) {
                    String filename = fileItem.getName();
                    filename = filename.substring(filename.lastIndexOf("\\")+1);
                    filename = UUID.randomUUID().toString()+"_"+value+"_"+filename;
                    String webPath = "/upload/";
                    String filepath = getServletContext().getRealPath(webPath+filename);
                    File file2 = new File(filepath);
                    File file3 = new File("d:\\upload\\"+filename);
                    file3.getParentFile().mkdirs();
                    file3.createNewFile();
                    file2.getParentFile().mkdirs();
                    file2.createNewFile();
                    InputStream inputStream = fileItem.getInputStream();
                    OutputStream outputStream = new FileOutputStream(file2);
                    OutputStream outputStream2 = new FileOutputStream(file3);
                    byte[] buffer = new byte[2048];
                    int len;
                    while((len = inputStream.read(buffer)) > 0) {
                        outputStream.write(buffer, 0, len);
                        outputStream2.write(buffer, 0, len);
                    }
                    inputStream.close();
                    outputStream.close();
                    outputStream2.close();
                    fileItem.delete();
                    try {
                        bookService.insert(book_name, price, describtion, clazz, count);
                        String path = "d:/upload/"+filename;
                        bookService.addImgByName(book_name, path);
                        String htmlCode="<!DOCTYPE html>\n" + 
                                "<html>"
                                + "<head>"
                                + "<link rel=\"stylesheet\" href=\""+request.getContextPath()+"/bootstrap-3.3.7-dist/css/bootstrap.min.css\">"
                                + "</head>"
                                + "<body>"
                                + "<div style=\"position:absolute;left:44%;top:46%;height:100px;width:240px;background-color:rgba(145, 162, 196, 0.9);border:1px;text-align:center;\"id=\"quit1\">\r\n" + 
                                "   <h3>添加成功!</h3><a class=\"btn btn-info\" href=\""+request.getContextPath()+"/admin/addBook.jsp\">繼續添加</a>&nbsp;&nbsp;&nbsp;&nbsp;"
                                        +"<a class=\"btn btn-info\" href=\""+request.getContextPath()+"/client/index.jsp\">去主頁</a>\n" + 
                                "</div>"
                                + "</body>"
                                + "</html>";
                        response.getWriter().write(htmlCode);
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        } catch (FileUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  •   Kali安裝好後,預設的瀏覽器是Firefox ESR(Extended Support Release 長期支持)版本。   作為Chrome的死忠粉,當然是要下Chrome用用的。   直到我安裝之後,點擊圖標打不開Chrome,用 ...
  • 1.根據自己系統的python版本下載pip安裝包,可去官網下載相應版本的。 [root@www ~]# python ##查看python版本Python 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8. ...
  • 可以進WINDOWS的管理里查看MYSQL的服務,把它停止或以DOS下用命令停止1.如果要卸載MYSQL執行下麵命令:DOS下>mysqld -remove mysql2.啟動MYSQL: DOS下>net start mysql3.停止MYSQL: DOS下>net stop mysql你先在運行 ...
  • # cd /lib64# LD_PRELOAD=/lib64/libc-2.15.so ln -sf /lib64/libc-2.15.so libc.so.6 libc-2.15.so 這個文件名根據你系統中的文件而定,如果有多個版本so文件可以逐個嘗試 原理分析: linux調用so的庫文件時, ...
  • [TOC] 文件的軟硬鏈接 1.軟鏈接 2.硬鏈接 文件編輯vi和vim vim比vi多了高亮顯示 須先安裝軟體包yum install y vim 三種方式: 1.命令模式 可控制游標移動,對文本進行查看,翻頁,複製,粘貼,刪除,剪切等工作 [root@gong ~] vim /etc/my.cn ...
  • 首先我們先需要一款軟體,例如“apache” 安裝解壓至相應目錄“/home/aaa/apache” 開始操作:進入“/etc/init.d/”中,新建一個service服務運行腳本“tomcat”, 裡面內容寫成: 保存結束後執行“service tomcat start/stop”即可啟動/關閉 ...
  • 轉載:https://www.xj123.info/7386.html 參考文檔:https://www.zabbix.com/documentation/3.0/manpages/zabbix_get Zabbix版本從3.0之後,開始支持Zabbix server, Zabbix proxy, ...
  • 安裝KVM虛擬化 KVM需要硬體⽀持, 所以需要開啟虛擬化⽀持 硬體設備直接在BIOS設置開啟CPU虛擬化 個⼈電腦同樣進⼊BIOS開啟虛擬化⽀持 VM需要找到對應虛擬機開啟對應的VT-EPT虛擬化技術 1. 伺服器環境規劃 操作系統 主機名 IP地址 記憶體 磁碟 Centos7.6 KVM-Nod... ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...