SpringMVC(1)

来源:https://www.cnblogs.com/ki16/archive/2019/07/20/11218942.html
-Advertisement-
Play Games

SpringMVC第一天 1. SpringMVC概述 1.1. 什麼是Spring MVC SpringMVC是Spring框架內置的MVC的實現.SpringMVC就是一個Spring內置的MVC框架. MVC框架,它解決WEB開發中常見的問題(參數接收、文件上傳、表單驗證、國際化、等等),而且 ...


SpringMVC第一天

1. SpringMVC概述

1.1. 什麼是Spring MVC

SpringMVCSpring框架內置的MVC的實現.SpringMVC就是一個Spring內置的MVC框架.

MVC框架,它解決WEB開發中常見的問題(參數接收、文件上傳、表單驗證、國際化、等等),而且使用簡單,與Spring無縫集成。 支持 RESTful風格的 URL 請求 。

採用了鬆散耦合可插拔組件結構,比其他 MVC 框架更具擴展性和靈活性。

 

1.2. SpringMVC的作用

MVC模式:(Model-View-Controller):為瞭解決頁面代碼和後臺代碼的分離.

2. SpringMVC底層實現

在沒有使用SpringMVC之前我們都是使用的Servlet在做Web開發。但是使用Servlet開發在接受請求數據參數,數據共用,頁面跳轉等操作相對比較複雜。

 

SpringMVC底層就是的ServletSpringMVC就是對Servlet進行更深層次的封裝

 

2.1. 回顧MVC模式

回顧什麼是mvc模式   

   模型model(javabean),  視圖view(jsp/img)   控制器Controller(Action/servlet)   C存在的目的.就是為了保證MV的一致性

   M發生改變時,C可以把M中的新內容更新到V.

  

2.1.1. 原始MVC 模式

MVC模式最早開始是在CS 架構上面 20世紀70+年代

面為原始的mvc模式.

目前web應用中,99%的項目都會使用mvc模式開發.

 

 

 

2.1.2. WEB開發的MVC

WEB開發從20世紀90+年代開始,也是使用MVC模式。在最原始的MVC上有一些改進

優秀的框架改變了這種模式,將model更廣泛的使用,這樣會比原始的mvc好多了.

像現在一些優秀的mvc的框架,Struts2springMVC

在客戶端提交也使用了模型來請求參數

spring MVC 也實現的相關的功能

 

 

 

3. 入門案例 -xml 配置

3.1. 準備工作

創建動態Web項目

 

 

3.2. 步驟

3.3. 準備jar

 

 

3.4. SpringMVC開發相關jar

spring-web-4.3.3.RELEASE.jar         spring web項目的支持。

spring-webmvc-4.3.2RELEASE.jar   spring mvc核心包。

 

 

 

3.5. 編寫Controller控制器(與以前servlet類似)

public class HelloController implements Controller  {

@Override

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

ModelAndView mv = new ModelAndView();

mv.addObject("username", "師姐");

mv.setViewName("/WEB-INF/hello/hello.jsp");

return mv;

}

}

3.6. springmvc.xml配置 Controller

<!--

name : 給當前控制器取的一個名字,相當於Servlet中的資源名稱,以便瀏覽器訪問,必須以斜杠/開頭

建議使用 name屬性,不要使用id,因為早期版本 id 不支持特殊字元 如 /斜杠

  -->

<bean name="/hello" class="cn.zj.springmvc.HelloController"/>

3.7. 配置spring mvc核心(前端)控制器,並且初始化spring容器。 web.xml配置.

<!-- 配置前端控制器 :所有的請求都會經過此控制器,讓後通過此控制器分發到各個控制器(總控)

總控其實就是Servlet,SpringMVC底層就是使用Servlet編寫的

 -->

<servlet>

<servlet-name>springMVC</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<!-- 讀取SpringMVC的配置文件 -->

<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>springMVC</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

3.8. 啟動項目

 

 

3.9. 訪問項目

 

 

 

 

4. SpringMVC的全註解開發

4.1. SpringIOC 註解

註解

說明

@Component

通用組件註解(一般配置其他非三層相關的類)

@Controller

表現層(控制層)

@Service

業務邏輯層(服務Service)

@Resposotory

數據持久層(DAO)

 

4.2. SpringMVC使用註解步驟

4.2.1. Spring mvc 採用註解方式(需要導入aop的包)

 

 

 

4.2.2. 通過註解方式註冊控制器,配置需要掃描的根目錄

<context:component-scan base-package="cn.zj.springmvc"/>

4.2.3. 支持所有mvc註解支持。支持json

<mvc:annotation-driven/>

4.2.4. 在核心類上添加@Controller 註解

4.2.5. 在方法上添加@RequestMapping("/hello")註解

4.3. 案例代碼

@Controller

public class AnnotationController  {

//@RequestMapping(value= {"/method1","/method2"})

@RequestMapping("method1")

public ModelAndView mehtod1() {

ModelAndView mv = new ModelAndView();

mv.addObject("username", "喬峰");

mv.setViewName("/WEB-INF/anno/index.jsp");

return mv;

}

}

 

 

 

 

 

5. SpringMVC執行流程和原理

 

SpringMVC流程:

01、用戶發送出請求到前端控制器DispatcherServlet

02DispatcherServlet收到請求調用HandlerMapping(處理器映射器)。

03HandlerMapping找到具體的處理器(可查找xml配置或註解配置),生成處理器對象及處理器攔截器(如果有),再一起返回給DispatcherServlet

04DispatcherServlet調用HandlerAdapter(處理器適配器)。

05HandlerAdapter經過適配調用具體的處理器(Handler/Controller)。

06Controller執行完成返回ModelAndView對象。

07HandlerAdapterController執行結果ModelAndView返回給DispatcherServlet

08DispatcherServletModelAndView傳給ViewReslover(視圖解析器)。

09ViewReslover解析後返回具體View(視圖)。

10DispatcherServlet根據View進行渲染視圖(即將模型數據填充至視圖中)。

11DispatcherServlet響應用戶。

 

 

 

涉及組件分析:

1、前端控制器DispatcherServlet(不需要程式員開發),由框架提供,在web.xml中配置。

作用:接收請求,響應結果,相當於轉發器,中央處理器。

 

2、處理器映射器HandlerMapping(不需要程式員開發),由框架提供。

作用:根據請求的url查找Handler(處理器/Controller),可以通過XML和註解方式來映射。

 

3、處理器適配器HandlerAdapter(不需要程式員開發),由框架提供。

作用:按照特定規則(HandlerAdapter要求的規則)去執行Handler

 

4、處理器Handler(也稱之為Controller,需要工程師開發)

註意:編寫Handler時按照HandlerAdapter的要求去做,這樣適配器才可以去正確執行Handler

作用:接受用戶請求信息,調用業務方法處理請求,也稱之為後端控制器。

 

5、視圖解析器ViewResolver(不需要程式員開發),由框架提供

作用:進行視圖解析,把邏輯視圖名解析成真正的物理視圖。

SpringMVC框架支持多種View視圖技術,包括:jstlViewfreemarkerViewpdfView等。

 

6、視圖View(需要工程師開發)

作用:把數據展現給用戶的頁面

View是一個介面,實現類支持不同的View技術(jspfreemarkerpdf等)

具體組件的配置相關,請查閱

spring-webmvc-4.3.2.RELEASE.jar

下麵

/org/springframework/web/servlet/DispatcherServlet.properties 的相關配置

HanderMapping 請求映射處理器

    作用:根據不同的請求選擇最合適的處理器(自己編寫的控制器),請求映射處理器可以配置多個,誰最先匹配就執行誰。

    Spring MVC預設:/org/springframework/web/servlet/DispatcherServlet.properties

   org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\

  org.springframework.web.servlet.do.annotation.DefaultAnnotationHandlerMapping

  BeanNameUrlHandlerMapping:處理通過<bean name="/xxx">註冊的控制器。控制器需要實現Controller介面。

 

  DefaultAnnotationHandlerMapping:處理通過註解@Controller(類標簽) 及@RequestMapping(方法標簽) 註冊的控制器。 該請求映射處理器已經在Spring 3.2 版本過時,替換為RequestMappingHandlerMapping。

  

  spring 中提供的映射處理器:

org.springframework.web.servlet.handler.SimpleUrlHandlerMapping   簡單url請求映射處理器。

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

        <property name="mappings">

      <value>

      /helloworld=helloworldController

      /helloworld002=helloworldController

      </value>

       </property>

     </bean>

org.springframework.web.servlet.do.method.annotation.RequestMappingHandlerMapping  採用註解方式請求映射處理器。

HandlerAdapter 處理器適配

HandlerAdapter 處理器適配:

   作用: 支持多種類型的處理器,如何來執行"處理器(控制器)“;

     Spring MVC預設:

    org.springframework.web.servlet.HandlerAdapter=

org.springframework.web.servlet.do.HttpRequestHandlerAdapter,\

org.springframework.web.servlet.do.SimpleControllerHandlerAdapter,\

org.springframework.web.servlet.do.annotation.AnnotationMethodHandlerAdapter

 

    org.springframework.web.servlet.do.HttpRequestHandlerAdapter 處理實現了HttpRequestHandler對應的控制器。

     核心代碼:

          public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)

throws Exception {

 

((HttpRequestHandler) handler).handleRequest(request, response);

return null;

}

 

   org.springframework.web.servlet.do.SimpleControllerHandlerAdapter 處理實現了Controller對應的控制器。

 

      public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)

throws Exception {

 

return ((Controller) handler).handleRequest(request, response);

}

    

    org.springframework.web.servlet.do.annotation.AnnotationMethodHandlerAdapter  處理通過註解方式的控制器。 3.2中已過時,替換為org.springframework.web.servlet.do.method.annotation.RequestMappingHandlerAdapter

ViewResolver 視圖解析器

   作用:根據不同的視圖,響應不同的結果,比如普通的jsp或json.

   Spring mvc預設:

   org.springframework.web.servlet.ViewResolver=

org.springframework.web.servlet.view.InternalResourceViewResolver

   

   InternalResourceViewResolver : 支持預設視圖,採用forward,redirect。

   視圖名:

          不寫首碼預設為"轉發"

          視圖名字元串首碼:

    forward:/xxx.jsp 採用轉發。

          redirect:/xxx.jsp  採用重定向。

 

        new ModelAndView("forward:/userList");

        new ModelAndView("redirect:/userList");

    

   註冊視圖解析器:

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

  <property name="prefix" value="/WEB-INF/" />

  <property name="suffix" value=".jsp" />

 </bean>

6. 對靜態資源訪問

我們這樣的配置有這樣一個問題

Web根路徑添加index.html,然後不能訪問,原因是什麼呢?為什麼此時在配置前端控制器的URL模式(<url-pattern>)寫成 / 就不行呢?

 

原因:

Tomcat中處理靜態資源訪問的servletdefault)的映射路徑為/.

在啟動項目的時候,在Tomcat中的web.xml是先載入的,項目的web.xml是後載入的,如果配置了相同的映射路徑,後面的會覆蓋前者.

也就是說,SpringMVC中的DispatcherServlet的映射路徑覆蓋了Tomcat預設對靜態資源的處理的路徑。

如果SpringMVC要配置為/,那麼就得設置Dispatcherservlet對靜態資源進行支持。

 

Tomcat /confg/web.xml  103

<servlet>

        <servlet-name>default</servlet-name>

        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>

        <init-param>

            <param-name>debug</param-name>

            <param-value>0</param-value>

        </init-param>

        <init-param>

            <param-name>listings</param-name>

            <param-value>false</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

</servlet>

    <servlet-mapping>

        <servlet-name>default</servlet-name>

        <url-pattern>/</url-pattern>

    </servlet-mapping>

 

解決方案:需要在SpringMVC的配置文件中添加對靜態資源的訪問

<mvc:default-servlet-handler/>

-----------------------------------------------------------------------------------------

<mvc:default-servlet-handler/> 將在 SpringMVC 上下文中定義一個 DefaultServletHttpRequestHandler,它會對進入 DispatcherServlet  的請求進行篩查,如果發現是沒有經過映射的請求,就將該請求交由 Tomcat預設的 Servlet 處理,如果不是靜態資源的請求,才由 DispatcherServlet  繼續處理

-----------------------------------------------------------------------------------------

 //*的區別:

/  會匹配url請求/index,也會匹配靜態資源*.js,*.html, 不會匹配*.jsp文件。

/* 會匹配url請求/index,也會匹配靜態資源*.js,*.html,  會匹配*.jsp文件。

實際開發中一般推薦使用  *.尾碼  如  *.do *.action *.do

<servlet-mapping>

<servlet-name>springMVC</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

 

7. Spring請求響應

7.1. @RequestMapping

@RequestMapping註解主要是設置SpringMVC請求的映射路徑

所謂的映射路徑,就是匹配請求路徑和執行方法關係的路徑.

 

請求路徑:http://localhost:8080/springmvc/method1.do

映射路徑:@RequestMapping(value="/method1")

 

@RequestMapping 用於貼在控制器的類上或者方法上面

如果是貼在控制器的類上面,那麼在訪問這個類的方法之前必須先加上類上的對應的名稱

類似於 項目下麵的 模塊名稱

如果貼在方法上面,就是訪問此方法的資源名稱

@Controller

@RequestMapping("/request")  //訪問時候必須加上,類似模塊名稱

public class RequestController {

@RequestMapping(value="/method1") //資源名稱

public void method1() {

}

}

訪問地址  : http://localhost:8080/springmvc/request/method1.do

 

7.2. 兩種限制

SpringMVC支持對請求的限制.如果不滿足限制的條件,就不讓訪問執行方法.

 

這樣做,大大提高了執行方法的安全性.

 

主要的限制有兩種:(method)方法限制,參數限制

7.2.1. 方法限制

就是設置請求的method類型.如果發送過來的請求與方法設置的method不一樣,就不能訪問執行方法.

 

請求method : GET , POST

  <form action="${pageContext.request.contextPath }/login.do" method="get">

    <input type="submit" value="登錄">

  </form>

 

/**

 * 接收的請求,必須是POST

 * @return

 */

@RequestMapping(value="login",method=RequestMethod.POST)

public String login(){

System.out.println("-登錄-");

return "/login.jsp";

}

 

前臺發送的是GET請求,而方法限制是POST請求,所以請求無法執行方法

 

 

 

方法限制可以配置多個參數

@RequestMapping(value="login",method={RequestMethod.GET,RequestMethod.POST})

public String login(){

System.out.println("-登錄-");

return "/login.jsp";

}

7.2.2. 參數限制

1.就是請求裡面必須包括哪些參數,或不包括哪些哪些.

2.參數包括哪些值,不包括哪些值

 

限制參數格式:

1.參數必須包括:params={"username","password"}

2.參數不能包括:params={"!userid"}

3參數值必須是指定的值:params={"username=zhangsan"})

4.參數值必須不是指定的值:params={"userid!=123"})

 

請求:沒有後臺方法指定的參數

<h4>登錄頁面</h4>

<form action="${pageContext.request.contextPath}/request/method1.do" method="post">

賬號:<input name="username"><br>

密碼:<input type="password" name="pwd"><br>

<button type="submit">登錄</button>

</form>

 

後臺代碼

/**

 * 需求:登錄時必須包括用戶名,密碼

 * @return

 */

@RequestMapping(value="login2",params={"username","password"})

public String login2(){

System.out.println("-登錄-");

return "/login.jsp";

}

如果前臺請求沒有指定後臺要求的參數,會報錯.

 

7.3. Spring方法參數可以註入的類型

SpringMVC的方法預設可以註入 JavaWeb開發常用的數據共用對象

HttpServletRequest

HttpServletResponse

HttpSession

獲取這些共用對象以後,就可以向之前的Servlet一樣,做任何數據共用以及頁面跳轉操作

 

/*

 * Spring的方法預設可以註入 JavaWeb開發常用的數據共用對象

HttpServletRequest

HttpServletResponse

 * HttpSession 以後開發 按需註入

 */

@RequestMapping(value = "/method0")

public void method0(HttpServletRequest req,

HttpServletResponse resp,

HttpSession session) {

//TODO

}

 

8. 數據綁定

8.1. 數據綁定是什麼

SpringMVC裡面,所謂的數據綁定就是將請求帶過來的表單數據綁定到執行方法的參數變數.

 

實際開發中,SpringMVC作為表現層框架,肯定會接受前臺頁面傳遞過來的參數,SpringMVC提供了豐富的接受參數的方法

8.2. 原始方式request.getParameter() 瞭解

SpringMVC可以註入HttpServletRequest對象,直接使用getParameter參數接受

<!--  原始方式request.getParameter() -->

<fieldset>

<legend> 原始方式request.getParameter()</legend>

<form action="${pageContext.request.contextPath}/request/method1.do" method="get">

賬號: <input name="username"><br>

年齡: <input name="age"><br>

<button type="submit">提交</button>

</form>

</fieldset>

@RequestMapping(value="/method1",method=RequestMethod.POST) //資源名稱

public void method1(HttpServletRequest req,HttpServletResponse resp,HttpSession session) {

 //原始方式request.getParameter()

String username = req.getParameter("username");

String age = req.getParameter("age");

System.out.println(username);

System.out.println(age);

}

8.3. 方法形參與前臺參數同名

在請求方法形參上,聲明和表單欄位名相同的參數名(可以自動同名匹配,然後進行封裝)

<fieldset>

<legend>方法形參與前臺參數同名</legend>

<form action="${pageContext.request.contextPath}/request/method2.do" method="post">

賬號: <input name="username"><br>

年齡: <input name="age"><br>

<button type="submit">提交</button>

</form>

</fieldset>

//方法形參與前臺參數同名

@RequestMapping(value="/method2",method=RequestMethod.POST)

public ModelAndView method2(String username,String age) {

System.out.println(username);

System.out.println(age);

return null;

}

8.4. 方法形參與前臺參數同名

<fieldset>

<legend>方法形參與前臺參數不同名</legend>

<form action="${pageContext.request.contextPath}/request/method3.do" method="post">

賬號: <input name="name"><br>

年齡: <input name="age"><br>

<button type="submit">提交</button>

</form>

</fieldset>

// 方法形參與前臺參數不同同名

// 解決方案使用 : @RequestParam("前臺表單對應的名")

@RequestMapping(value = "/method3", method = RequestMethod.POST)

public ModelAndView method3(@RequestParam("name") String username, String age) {

System.out.println(username);

System.out.println(age);

return null;

}

 

8.5. 接受數組

<fieldset>

<legend>接收數組或集合</legend>

<form action="${pageContext.request.contextPath}/request/method4.do" method="post">

賬號: <input name="name"><br>

年齡: <input name="age"><br>

愛好: <input type="checkbox" name="hobbys" value="java">java

<input type="checkbox" name="hobbys" value="html">html<br>

<button type="submit">提交</button>

</form>

</fieldset>

// 接受數組

@RequestMapping(value = "/method4", method = RequestMethod.POST)

public ModelAndView method4(String[] hobbys) {

System.out.println(Arrays.toString(hobbys));

return null;

}

8.6. 對象傳參

後臺並不能直接接受集合參數,需要將集合設置到對應的JavaBean,通過JavaBean接受集合參數

Pojo對象

public class User {

private String username;

private String password;

private String email;

private String phone;

private String[] hobby;

}

<fieldset>

<legend>接受對象,表單參數名必須和後臺pojo對象對應的屬性名相同</legend>

<form action="${pageContext.request.contextPath}/request/method5.do" method="get">

賬號: <input name="username"><br>

密碼: <input type="password" name="password"><br>

郵箱: <input name="email"><br>

電話: <input name="phone"><br>

愛好:<input type="checkbox" name="hobby" value="java">java

<input type="checkbox" name="hobby" value="C">C

<input type="checkbox" name="hobby" value="C++">C++<br/>

<button type="submit">提交</button>

</form>

</fieldset>

// 對象傳參->對象中有集合

@RequestMapping(value = "/method5", method = RequestMethod.POST)

public ModelAndView method4(User user) {

System.out.println(user);

return null;

}

8.7. 接受參數封裝成Map集合

<fieldset>

<legend>接受參數封裝成Map集合</legend>

<form action="${pageContext.request.contextPath}/request/method6.do" method="post">

賬號: <input name="username"><br>

密碼: <input name="password"><br>

郵箱: <input name="email"><br>

電話: <input name="phone"><br>

</form>

</fieldset>

// 接受參數封裝成Map集合

@RequestMapping(value = "/method6", method = RequestMethod.POST)

public ModelAndView method6(@RequestParam Map<String,Object> map) {

System.out.println("map:"+map);

return null;

}

 

8.8. RESTful風格支持

8.8.1. RESTFUL 風格介紹

REST(英文:Representational State Transfer,簡稱

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

-Advertisement-
Play Games
更多相關文章
  • 本片文章將為您詳細講解在Vue中,父給子傳值、子給父傳值以及兄弟之間傳值方式! 父傳子;父組件 父傳子;子組件 需要註意的是,父組件傳值給子組件,如果子組件不需要修改父組件的參數,可以使用這種方式!如果子組件要修改父組件中的參數,父組件必須用引用類型的參數傳給子組件! 子傳父;父組件 子傳父;子組件 ...
  • Node.js插件(addons) Node.js 插件是用 C++ 編寫的動態鏈接共用對象,可以使用 require() 函數載入到 Node.js 中,且像普通的 Node.js 模塊一樣被使用。 它們主要用於為運行在 Node.js 中的 JavaScript 與 C/C++ 庫之間提供介面。 ...
  • 1、foreach foreach迴圈對不能使用return來停止迴圈 2、filter item對象就是遍曆數組中的一個元素,includes是es6中的新方法,在search方法中直接返回新數組 3、findIndex 返回true後index就可以獲取到匹配的元素在進行刪除 4、some 如果 ...
  • 摘要: JS引擎開始升級了... 原文: "技術棧中的愛馬仕?Facebook發佈全新JavaScript引擎:Hermes" 作者:Carson_Ho "Fundebug" 經授權轉載,版權歸原作者所有。 前言 目前,用戶的流暢體驗是用戶能長期使用某個移動客戶端應用App的重要指標之一,因此,移動 ...
  • 前端開發工程師不僅僅要掌握一些基礎的美工設計等還要懂得網頁設計類的HTML JavaScript和css,這三種能力缺一不可,雖不要求你特別的精通,但至少要熟練的掌握,能夠運用自己所瞭解的這些技術和知識解決工作中遇到的問題,而不是頻繁的請教別人。 我們常說IT行業技術更新較快,這是事實,但也給能提高 ...
  • 補充:header,fotter,article,section都是div語義化的結果 歡迎評論😀 ...
  • 示例代碼托管在: "http://www.github.com/dashnowords/blogs" 博客園地址: "《大史住在大前端》原創博文目錄" 華為雲社區地址: "【你要的前端打怪升級指南】" [TOC] 一. 大作業說明 通讀完上一篇博文中提及的教程,覺得應該搞個大作業鞏固一下所學的知識, ...
  • 在購買了一個房子後,如果是毛坯房,肯定不合適直接入住的。需要對它進行裝修:地面找平貼地磚、批牆貼牆紙、弔頂裝訂以及買需要的傢具,住進去以後也可能根據需要再添加或者去掉一些傢具或者修改一些東西。所以的這一切,都是為了住起來舒服,也就是更好試用這個房子。這個裝修過程,基本上就是裝飾模式需要做的事情。 引 ...
一周排行
    -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.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...