草庐IT

SpringMVC笔记

Login_X's Blogs 2023-04-17 原文

SpringMVC

一、SpringMVC介绍

1.什么是MVC

是一种软件架构的思想,将软件按照模型、视图、控制器来划分

  • M:Model,模型层,指工程中的JavaBean,作用是处理数据
    • JavaBean
      • 一类称为实体类Bean:专门存储业务数据的,如 Student、User 等
      • 一类称为业务处理 Bean:指 Service 或 Dao 对象,专门用于处理业务逻辑和数据访问。
  • V:View,视图层,指工程中的html或jsp等页面,作用是与用户进行交互,展示数据
  • C:Controller,控制层,指工程中的servlet,作用是接收请求和响应浏览器

MVC工作流程: 用户通过视图层发送请求到服务器,在服务器中请求被Controller接收,Controller调用相应的Model层处理请求,处理完毕将结果返回到Controller,Controller再根据请求处理的结果找到相应的View视图,渲染数据后最终响应给浏览器

2.什么是SpringMVC

是Spring的一个后续产品,是Spring的一个子项目

SpringMVC 是 Spring 为表述层开发提供的一整套完备的解决方案。目前业界普遍选择了 SpringMVC 作为 Java EE 项目表述层开发的首选。

三层架构:表述层(或表示层)、业务逻辑层、数据访问层,表述层表示前台页面和后台servlet

3.SpringMVC的优点

  • 轻量级,基于MVC框架
  • 易上手,易理解,功能强大
  • 具备IOC和AOP
  • 完全基于注解开发

二、工程创建

1.开发环境

idea:2019.3.5

tomcat:9.0.59

Spring:5.3.22

Maven:3.6.1

2.基于注解的SpringMVC框架开发步骤总结

  1. 新建项目(可以直接选择webapp的模板)
  2. 补全目录
  3. 修改pom.xml,添加SpringMVC和Servlet依赖
  4. 添加springmvc.xml配置文件,指定包扫描,添加视图解析器
  5. 删除web.xml文件,新建web.xml(版本过低有些功能不支持)
  6. web.xml中注册springmvc框架
  7. webapp下新建admin目录,在目录下新建main.jsp页面,删除index.jsp再添加index.jsp页面
  8. 开发控制器(Servlet)
  9. 添加tomcat测试功能

实例

DemoAction.java

package com.xust.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DemoAction {
    @RequestMapping("/demo.action")
    public String demo(){
        System.out.println("服务器被访问到了。。。。。");
        return "main";  //直接跳到/admin/mian.jsp页面
    }
}

springmvc.xml

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

    <!--添加包扫描-->
    <context:component-scan base-package="com.xust.controller"></context:component-scan>
    <!--添加视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--配置前缀-->
        <property name="prefix" value="/admin/"></property>
        <!--配置后缀-->
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <!--注册SpringMVC框架-->
    <servlet>
        <servlet-name>springmvc</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>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>
</web-app>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xust</groupId>
  <artifactId>spring_001_demo</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!--添加SpringMVC的依赖-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.1</version>
    </dependency>
    <!--添加servlet依赖-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <!--资源文件-->
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
        </includes>
      </resource>
    </resources>
  </build>
</project>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/demo.action">访问服务器</a>
</body>
</html>

三、RequestMapping注解

将请求和处理请求的控制器方法关联起来,建立映射关系。

SpringMVC 接收到指定的请求,就会来找到在映射关系中对应的控制器方法来处理这个请求。

  1. 此注解加在方法前,可以为此方法注册一个可以访问的名称(路径)。

  2. 此注解加在类前,相当于虚拟路径,对不同类进行区分

如:我在前面例子中类名前加@RequestMapping("/zar"),那么index.jsp中就要改为

${pageContext.request.contextPath}/zar/demo.action

  1. 此注解可区分Get请求和Post请求

区分请求举例

<form action="${pageContext.request.contextPath}/req.action" method="get">
    <input type="submit" value="提交">
</form>
package com.xust.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ReqAction {
    @RequestMapping(value = "/req.action",method = RequestMethod.GET)
    public String req(){
        System.out.println("我是处理get请求的。。。。。。。。。。");
        return "main";
    }

    @RequestMapping(value = "/req.action",method = RequestMethod.POST)
    public String req1(){
        System.out.println("我是处理post请求的。。。。。。。。。。");
        return "main";
    }
}

四、五种数据提交方式的优化

1.单个数据提交

自动注入并且类型转换

<form action="${pageContext.request.contextPath}/one.action">
    姓名:<input name="myname"><br>
    年龄:<input name="myage"><br>
    <input type="submit" value="提交">
</form>
package com.xust.controller;

import com.xust.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DataSubmitAction {
    @RequestMapping("/one.action")
    public String one(String myname,int myage){     //自动注入并且类型转换
        System.out.println("myname="+myname+",myage="+(myage+100));
        return "main";
    }
}

2.对象封装提交数据

保证jsp中的name和类中的成员变量名称相同

在提交请求中,保证请求参数的名称与实体类中成员变量名称一致,则可以自动提交数据,自动类型转换,自动封装数据到对象中。

<h2>2.对象封装数据提交</h2>
<form action="${pageContext.request.contextPath}/two.action">
    姓名:<input name="name"><br>
    年龄:<input name="age"><br>
    <input type="submit" value="提交">
</form>
package com.xust;

public class Users {
    private String name;
    private int age;

    public Users(){}

    public Users(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Users{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
package com.xust.controller;

import com.xust.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DataSubmitAction {
    @RequestMapping("/two.action")
    public String two(Users u){
        System.out.println(u);
        return "main";
    }
}

3.动态占位符提交

仅限于超链接或地址栏提交数据

一杠一值,一杠一大括号,使用注解来解析

<h2>3.动态占位符提交</h2>
<a href="${pageContext.request.contextPath}/three/张三/22.action">动态提交</a>
package com.xust.controller;

import com.xust.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DataSubmitAction {
    @RequestMapping("/three/{name}/{age}.action")
    public String three(
            @PathVariable
            String name,
            @PathVariable
            int age){
        System.out.println("name="+name+",age="+(age+100));
        return "main";
    }
}
//如果@RequestMapping中是{uname},下边可以用@PathVariable(“uname)

4.映射名称不一致

提交请求参数与action方法的形参名称不一致,使用注解@RequestParam来解析

<h2>4.参数名称不一致</h2>
<form action="${pageContext.request.contextPath}/four.action">
    姓名:<input name="name"><br>
    年龄:<input name="age"><br>
    <input type="submit" value="提交">
</form>
package com.xust.controller;

import com.xust.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class DataSubmitAction {
    @RequestMapping("/four.action")
    public String four(
            @RequestParam("name")
            String uname,
            @RequestParam("age")
            int uage){
        System.out.println("uname="+uname+",uage="+(uage+100));
        return "main";
    }
}

5.手工提取数据

<h2>5.手工提取数据</h2>
<form action="${pageContext.request.contextPath}/five.action">
    姓名:<input name="name"><br>
    年龄:<input name="age"><br>
    <input type="submit" value="提交">
</form>
package com.xust.controller;

import com.xust.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;

@Controller
public class DataSubmitAction {
    @RequestMapping("/five.action")
    public String five(HttpServletRequest request){
        String name=request.getParameter("name");
        int age=Integer.parseInt(request.getParameter("age"));
        System.out.println("name="+name+",age="+(age+100));
        return "main";
    }
}

五、中文编码过滤器配置

在web.xml最前面加如下配置

<!--中文编码过滤器配置-->
<filter>
    <filter-name>encode</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <!--
        配置参数
        private String encoding;
        private boolean forceRequestEncoding;
        private boolean forceResponseEncoding;
    -->
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceRequestEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>forceResponseEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encode</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

六、action方法返回值

  • String:客户端资源地址,自动拼接前缀和后缀,还可以屏蔽自动拼接字符串,可以指定返回路径。

  • Object:返回json格式对象,自动将对象或集合转为json,使用jackson工具进行转换,必须添加jackson依赖,一般用于ajax请求。

  • void:无返回值,一般用于ajax请求。

  • 基本数据类型:用于ajax请求。

  • ModelAndView:返回数据和视图对象,现在用的很少。

七、ajax请求返回学生集合

  1. 添加jackson依赖
  2. 在webapp目录下新建js目录,添加jQuery函数库
  3. 在index.jsp导入函数库
  4. 在action上添加注解@ResponseBody,用来处理ajax请求
  5. 在springmvc.xml添加注解驱动< mvc:annotationdriven/ >,它用来解析@ResponseBody注解

八、请求转发和重定向

转发可以携带数据,重定向不行

redirect和forward都可以屏蔽前后缀,但前者在重定向时使用,地址栏发生变化,后者在转发时使用,地址栏不变

1.请求转发页面(默认)

地址栏不变

<a href="${pageContext.request.contextPath}/one.action">1.请求转发页面(默认)</a>
@Controller
public class StudentListAction {
    @RequestMapping("/one.action")
    public String one(){
        return "main";      //默认是请求转发,使用视图解析器拼接前缀后缀进行页面跳转
    }
}

2.请求转发action

地址栏不变

<a href="${pageContext.request.contextPath}/two.action">2.请求转发action</a>
@Controller
public class StudentListAction {
    @RequestMapping("/two.action")
    public String two(){
        //forward可以屏蔽前缀和后缀字符串的拼接
        return "forward:/other.action";
    }
}
@Controller
public class OtherAction {
    @RequestMapping("/other.action")
    public String other(){
        return "main";
    }
}

3.重定向页面

地址栏变为.../admin/main.jsp

<a href="${pageContext.request.contextPath}/three.action">3.重定向页面</a>
@Controller
public class StudentListAction {
    @RequestMapping("/three.action")
    public String three(){
        //redirect可以屏蔽前缀和后缀字符串的拼接
        return "redirect:/admin/main.jsp";
    }
}

4.重定向action

地址栏变为.../other.action

<a href="${pageContext.request.contextPath}/four.action">4.重定向action</a>
@Controller
public class StudentListAction {
    @RequestMapping("/four.action")
    public String four(){
        //redirect可以屏蔽前缀和后缀字符串的拼接
        return "redirect:/other.action";
    }
}
@Controller
public class OtherAction {
    @RequestMapping("/other.action")
    public String other(){
        return "main";
    }
}

九、SpringMVC默认参数类型

不需要创建,直接拿来用

  • HttpServletRequest
  • HttpServletResponse
  • HttpSession
  • Model
  • Map
  • ModelMap

Model、Map、ModelMap和Request一样,都使用请求作用域进行数据传递,所以服务器端的跳转必须是请求转发。

默认参数传递实例

index.jsp

<a href="${pageContext.request.contextPath}/data.action?name=zar">访问服务器进行数据携带跳转</a>

main.jsp

<h2>显示数据</h2>
${requestStudent}<br>
${sessionStudent}<br>
${modelStudent}<br>
${mapStudent}<br>
${modelStudent}<br>
上面是从action传来的,从index.jsp传来的数据name为${param.name}

Student.java

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

DataAction.java

@Controller
public class DataAction {
    @RequestMapping("/data.action")
    public String data(HttpServletRequest request,
                       HttpServletResponse response,
                       HttpSession session,
                       Model model,
                       Map map,
                       ModelMap modelMap
                       ){
        //做一个数据传到main.jsp
        Student stu1=new Student("张三",21);
        //传递数据
        request.setAttribute("requestStudent",stu1);
        session.setAttribute("sessionStudent",stu1);
        model.addAttribute("modelStudent",stu1);
        map.put("mapStudent",stu1);
        modelMap.addAttribute("modelStudent",stu1);
        return "main";
    }
}

十、日期处理

1.日期的提交处理

(1)单个日期处理

要使用DataTimeFormat,此注解必须搭配springmvc.xml中的<mvc:annotationdriven >标签。

可以在方法参数上使用,也可以在类中成员变量的setXXX()方法或属性定义上使用,但是这种方法在每个用到日期类型的地方都要添加一次,比较麻烦,在下面只演示第一种情况。

<form action="${pageContext.request.contextPath}/mydate.action">
    日期:<input type="date" name="mydate"><br>
    <input type="submit" value="提交">
</form>
@Controller
public class MyDateAction {
    SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
    @RequestMapping("/mydate.action")
    public String mydate(
            @DateTimeFormat(pattern = "yyyy-MM-dd") //将String注入给Date
            Date mydate){
        System.out.println(mydate);
        System.out.println(sf.format(mydate));
        return "show";
    }
}

(2)类中全局日期处理

不使用@DateTimeFormat注解,使用@InitBinder注解,不需要绑定<mvc:annotationdriven >驱动

@Controller
public class MyDateAction {

    SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");     //固定格式
    //注册一个全局的日期处理的注解
    @InitBinder
    public void intiBinder(WebDataBinder dataBinder){
        dataBinder.registerCustomEditor(Date.class,new CustomDateEditor(sf,true));
    }
    @RequestMapping("/mydate.action")
    public String mydate(Date mydate){
        System.out.println(mydate);
        System.out.println(sf.format(mydate));
        return "show";
    }
}

2.日期的显示处理

如果是单个日期对象,直接转为好看的字符串进行显示

如果是List中的实体类对象的成员变量是日期类型,则必须用jstl进行显示

步骤:添加依赖Jstl,页面上导入标签库,使用标签显示数据

(1)在Json文件中日期显示

在类中成员getXXX()方法上使用注解@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

(2)Jsp页面的日期显示

添加依赖

<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

jsp导入标签库

<%--导入jstl核心标签库--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--导入jstl格式化标签库--%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

实例

<h2>集合</h2>
<table width="800px" border="1">
    <tr>
        <th>姓名</th>
        <th>生日</th>
    </tr>
    <c:forEach items="${list}" var="stu">
        <tr>
            <th>${stu.name}</th>
            <th>${stu.birthday}----- <fmt:formatDate value="${stu.birthday}" pattern="yyyy-MM-dd"></fmt:formatDate></th>
        </tr>
    </c:forEach>
</table>
public class Users {
    private String name;
    private Date birthday;

    public Users() {
    }

    public Users(String name, Date birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Users{" +
                "name='" + name + '\'' +
                ", birthday=" + birthday +
                '}';
    }
}
@Controller
public class MyDateAction {

    SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");     //固定格式

    @RequestMapping("/datelist.action")
    public String datelist(HttpServletRequest request) throws ParseException {
        Users u1=new Users("张三",sf.parse("2001-07-06"));
        Users u2=new Users("李四",sf.parse("2001-07-07"));
        Users u3=new Users("王五",sf.parse("2001-07-08"));
        List<Users> list=new ArrayList<>();
        list.add(u1);
        list.add(u2);
        list.add(u3);
        request.setAttribute("list",list);
        return "show";
    }
}

WEB-INF目录

此目录下动态资源,不可直接访问,只能通过请求转发的方式进行访问。

去后缀

在web.xml中将.action改为/,访问时网址栏可省略.action后缀

登录业务实现

<h2>登录</h2>
<form action="${pageContext.request.contextPath}/login">
    姓名:<input name="name"><br>
    密码:<input type="password" name="pwd"><br>
    <input type="submit" value="登录">
</form>
${msg}
@Controller
public class WebinfAction {
    @RequestMapping("/showLogin")
    public String showLogin(){
        System.out.println("访问login.jsp");
        return "login";
    }
    //登录的业务判断
    @RequestMapping("/login")
    public String login(String name, String pwd, HttpServletRequest request){
        if("zar".equalsIgnoreCase(name)&&"123".equalsIgnoreCase(pwd)){
            return "main";
        } else{
            request.setAttribute("msg","用户名或密码错误");
            return "login";
        }
    }
}

拦截器

上面虽然已经实现了登录功能,但是通过修改地址栏可以跳过登录,安全性不够。

拦截器就是针对请求和响应添加额外的处理。在请求和响应过程中添加预处理,后处理和最终处理。

拦截器执行时机

  • preHandle():请求被处理前操作
  • postHandle:在请求被处理后,但结果还没有被渲染之前操作,可以改变响应结果
  • afterCompletion:所有请求响应结束后执行善后工作,清理对象,关闭资源

拦截器实现的两种方式

  1. 继承HandlerInterceptorAdapter的父类

  2. 实现HandlerInterceptor接口,推荐使用实现接口的方式

拦截器实现步骤

  1. 改造登录方法,在session中存储用户信息,用于权限验证
  2. 开发拦截器功能,实现HandlerInterceptor接口,重写preHandle()方法
  3. 在springmvc.xml中注册拦截器

实例

<h2>登录</h2>
<form action="${pageContext.request.contextPath}/login">
    姓名:<input name="name"><br>
    密码:<input type="password" name="pwd"><br>
    <input type="submit" value="登录">
</form>
${msg}
@Controller
    @RequestMapping("/showMain")
    public String showMain(){
        System.out.println("访问main.jsp");
        return "main";
    }
    @RequestMapping("/showLogin")
    public String showLogin(){
        System.out.println("访问login.jsp");
        return "login";
    }
    //登录的业务判断
    @RequestMapping("/login")
    public String login(String name, String pwd, HttpServletRequest request){
        if("zar".equalsIgnoreCase(name)&&"123".equalsIgnoreCase(pwd)){
            //在session中存储用户信息,用于权限验证
            request.getSession().setAttribute("users",name);
            return "main";
        } else{
            request.setAttribute("msg","用户名或密码错误");
            return "login";
        }
    }
}
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //是否登录过的判断
        if (request.getSession().getAttribute("users")==null){
            //没登录
            request.setAttribute("msg","请先登录再访问");
            request.getRequestDispatcher("WEB-INF/jsp/login.jsp").forward(request,response);
            return false;
        }
        return true;//放行请求
    }
}
<!--注册拦截器-->
<mvc:interceptors>
    <mvc:interceptor>
        <!--映射要拦截的请求-->
        <mvc:mapping path="/**"/>
        <!--设置要放行的请求-->
        <mvc:exclude-mapping path="/showLogin"/>
        <mvc:exclude-mapping path="/login"/>
        <!--配置具体拦截器功能的类-->
        <bean class="com.xust.interceptor.LoginInterceptor"></bean>
    </mvc:interceptor>
</mvc:interceptors>

有关SpringMVC笔记的更多相关文章

  1. LC滤波器设计学习笔记(一)滤波电路入门 - 2

    目录前言滤波电路科普主要分类实际情况单位的概念常用评价参数函数型滤波器简单分析滤波电路构成低通滤波器RC低通滤波器RL低通滤波器高通滤波器RC高通滤波器RL高通滤波器部分摘自《LC滤波器设计与制作》,侵权删。前言最近需要学习放大电路和滤波电路,但是由于只在之前做音乐频谱分析仪的时候简单了解过一点点运放,所以也是相当从零开始学习了。滤波电路科普主要分类滤波器:主要是从不同频率的成分中提取出特定频率的信号。有源滤波器:由RC元件与运算放大器组成的滤波器。可滤除某一次或多次谐波,最普通易于采用的无源滤波器结构是将电感与电容串联,可对主要次谐波(3、5、7)构成低阻抗旁路。无源滤波器:无源滤波器,又称

  2. Unity Shader 学习笔记(5)Shader变体、Shader属性定义技巧、自定义材质面板 - 2

    写在之前Shader变体、Shader属性定义技巧、自定义材质面板,这三个知识点任何一个单拿出来都是一套知识体系,不能一概而论,本文章目的在于将学习和实际工作中遇见的问题进行总结,类似于网络笔记之用,方便后续回顾查看,如有以偏概全、不祥不尽之处,还望海涵。1、Shader变体先看一段代码......Properties{ [KeywordEnum(on,off)]USL_USE_COL("IsUseColorMixTex?",int)=0 [Toggle(IS_RED_ON)]_IsRed("IsRed?",int)=0}......//中间省略,后续会有完整代码 #pragmamulti_c

  3. Tcl脚本入门笔记详解(一) - 2

    TCL脚本语言简介•TCL(ToolCommandLanguage)是一种解释执行的脚本语言(ScriptingLanguage),它提供了通用的编程能力:支持变量、过程和控制结构;同时TCL还拥有一个功能强大的固有的核心命令集。TCL经常被用于快速原型开发,脚本编程,GUI和测试等方面。•实际上包含了两个部分:一个语言和一个库。首先,Tcl是一种简单的脚本语言,主要使用于发布命令给一些互交程序如文本编辑器、调试器和shell。由于TCL的解释器是用C\C++语言的过程库实现的,因此在某种意义上我们又可以把TCL看作C库,这个库中有丰富的用于扩展TCL命令的C\C++过程和函数,所以,Tcl是

  4. 计算机网络笔记:TCP三次握手和四次挥手过程 - 2

    TCP是面向连接的协议,连接的建立和释放是每一次面向连接的通信中必不可少的过程。TCP连接的管理就是使连接的建立和释放都能正常地进行。三次握手TCP连接的建立—三次握手建立TCP连接①若主机A中运行了一个客户进程,当它需要主机B的服务时,就发起TCP连接请求,并在所发送的分段中用SYN=1表示连接请求,并产生一个随机发送序号x,如果连接成功,A将以x作为其发送序号的初始值:seq=x。主机B收到A的连接请求报文,就完成了第一次握手。客户端发送SYN=1表示连接请求客户端发送一个随机发送序号x,如果连接成功,A将以x作为其发送序号的初始值:seq=x②主机B如果同意建立连接,则向主机A发送确认报

  5. 华为数通笔记VXLAN&BGP EVPN - 2

    VXLAN简介定义RFC定义了VLAN扩展方案VXLAN(VirtualeXtensibleLocalAreaNetwork,虚拟扩展局域网)。VXLAN采用MACinUDP(UserDatagramProtocol)封装方式,是NVO3(NetworkVirtualizationoverLayer3)中的一种网络虚拟化技术。目的随着网络技术的发展,云计算凭借其在系统利用率高、人力/管理成本低、灵活性/可扩展性强等方面表现出的优势,已经成为目前企业IT建设的新趋势。而服务器虚拟化作为云计算的核心技术之一,得到了越来越多的应用。服务器虚拟化技术的广泛部署,极大地增加了数据中心的计算密度;同时,为

  6. [蓝桥杯单片机]学习笔记——串口通信的基本原理与应用 - 2

    目录一、原理部分1、什么是串行通信(1)并行通信与串行通信(2)串行通信的制式(3)串行通信的主要方式  2、配置串口(1)SCON和PCON:串行口1的控制寄存器(2)SBUF:串行口数据缓冲寄存器 (3)AUXR:辅助寄存器​编辑(4)ES、PS:与串行口1中断相关的寄存器(5)波特率设置  3、串口框架编写二、程序案例一、原理部分1、什么是串行通信(1)并行通信与串行通信微控制器与外部设备的数据通信,根据连线结构和传送方式的不同,可以分为两种:并行通信和串行通信。并行通信:数据的各位同时发送与接收,每个数据位使用一条导线,这种方式传输快,但是需要多条导线进行信号传输。串行通信:数据一位一

  7. 【微服务笔记23】使用Spring Cloud微服务组件从0到1搭建一个微服务工程 - 2

    这篇文章,主要介绍如何使用SpringCloud微服务组件从0到1搭建一个微服务工程。目录一、从0到1搭建微服务工程1.1、基础环境说明(1)使用组件(2)微服务依赖1.2、搭建注册中心(1)引入依赖(2)配置文件(3)启动类1.3、搭建配置中心(1)引入依赖(2)配置文件(3)启动类1.4、搭建API网关(1)引入依赖(2)配置文件(3)启动类1.5、搭建服务提供者(1)引入依赖(2)配置文件(3)启动类1.6、搭建服务消费者(1)引入依赖(2)配置文件(3)启动类1.7、运行测试一、从0到1搭建微服务工程1.1、基础环境说明(1)使用组件这里主要是使用的SpringCloudNetflix

  8. 论文笔记:InternImage—基于可变形卷积的视觉大模型,超越ViT视觉大模型,COCO 新纪录 64.5 mAP! - 2

    目录文章信息写在前面Background&MotivationMethodDCNV2DCNV3模型架构Experiment分类检测文章信息Title:InternImage:ExploringLarge-ScaleVisionFoundationModelswithDeformableConvolutionsPaperLink:https://arxiv.org/abs/2211.05778CodeLink:https://github.com/OpenGVLab/InternImage写在前面拿到文章之后先看了一眼在ImageNet1k上的结果,确实很高,超越了同等大小下的VAN、RepLK

  9. uniapp+uview开发微信小程序学习笔记(一) - 2

    文章目录前言一、注册小程序二、项目创建三、运行项目四、其他配置最后前言此次项目开发使用uniapp和uview进行开发,需要用到的开发工具为HBuilderX和微信开发者工具,具体的安装方式见官网,小程序注册见微信公众平台。一、注册小程序注册在微信公众平台注册小程序,按照提示注册完后会发配一个appid和密钥,需要复制保存好。完善信息设置=>基本设置,填写小程序基本信息,包括名称、头像、介绍及服务范围等。第三方设置根据开发需求添加插件授权。成员管理管理=>成员管理,点击编辑或下拉选择添加成员,输入微信号添加新的项目成员,只有成员可以进行真机测试。体验成员可以使用发布的体验版。开发设置开发=>开

  10. ESP32学习笔记(七) 复位和时钟 - 2

    ESP32学习笔记(七)复位和时钟目录:ESP32学习笔记(一)芯片型号介绍ESP32学习笔记(二)开发环境搭建VSCode+platformioESP32学习笔记(三)硬件资源介绍ESP32学习笔记(四)串口通信ESP32学习笔记(五)外部中断ESP32学习笔记(六)定时器ESP32学习笔记(七)复位和时钟1.复位2.系统时钟2.1时钟树2.2时钟源从时钟树可以看出时钟源共七种ESP32的时钟源分别来自外部晶振、内部PLL或振荡电路具体地说,这些时钟源为:2.2.1快速时钟PLL_CLK320MHz或480MHz内部PLL时钟XTL_CLK2~40MHz外部晶振时钟,模组板载的是40MHz晶

随机推荐