JAVA后端框架--【Mybatis】

news2024/9/27 6:44:24

框架

框架就是对技术的封装,将基础的技术进行封装,让程序员快速使用,提高开发效率

java后端框架

mybatis

对jdbc进行封装

背景介绍

mybatis是apache下面的一个开源项目,名为ibatis,2010年开发团队转移到谷歌旗下,更名为mybatis

mybatis是一个优秀的数据持久性框架(dao层 数据访问层 数据持久性)

对jdbc进行封装,避免了jdbc中手动设置参数,手动映射结果的操作

mybatis将jdbc中接口进行封装,提供了它自己的类和接口实现。

mybatis可以使用xml配置和注解的方式,将数据库中记录自动映射到java对象中,

是一种orm实现(对象关系映射)将可以自动映射到对象中的这种框架,也称为orm框架

mybatis还提供了动态sql和数据缓存功能

mybatis搭建
1.创建mven项目

2.导入mybatis依赖的jar
 <dependency>
           <groupId>org.mybatis</groupId>
           <artifactId>mybatis</artifactId>
           <version>3.4.2</version>
       </dependency>
3.创建一个全局的mybatis配置文件,配置数据库进行链接

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
    <!--为类配置别名-->
    <typeAliases>
        <package name="com.wph.mybatis.model"/>
    </typeAliases>

    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://127.0.0.1:3306/ssmdb?serverTimezone=Asia/Shanghai" />
                <property name="username" value="root" />
                <property name="password" value="root"/>
            </dataSource>
        </environment>
    </environments>

    <!--注册映射文件-->
    <mappers>
        <mapper resource="Mappers/AdminMapper.xml"></mapper>
    </mappers>
</configuration>
4.创建数据库,创建表

create database ssmdb

create table admin(
id int primary key auto_increment,
account varchar(10),
password varchar(10),
gender varchar(10)
)

5.创建一个访问接口,定义方法
package com.wph.mybatis.dao;

import com.wph.mybatis.model.Admin;
import org.apache.ibatis.annotations.Param;

public interface AdminDao {
    Admin findAdminbyid(int id);

    Admin findAdminbyAccount(String account);

    Admin login(@Param("acc") String account,@Param("pwd") String password);

    Admin login1(Admin admin);

    void deleteadmin(int id);

    void insert(Admin admin);

        void update(Admin admin);
}
6.创建接口对应映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wph.mybatis.dao.AdminDao">
    <update id="update" parameterType="Admin">
        update admin set account=#{account},password=#{password},gender=#{gender} where id=#{id}
    </update>
    <select id="findAdminbyid" parameterType="int" resultType="Admin">
            select * from admin where id = #{id}
    </select>

    <select id="findAdminbyAccount" parameterType="String" resultType="Admin">
            select * from admin where account = #{account}
    </select>
    <select id="login" resultType="Admin">
        select * from admin where account=#{acc} and password =#{pwd}
    </select>
    <select id="login1" resultType="Admin">
        select * from admin where account=#{account} and password =#{password}
    </select>
    <delete id="deleteadmin" parameterType="int">
        delete from admin where id=#{id}
    </delete>

    <!--useGeneratedKeys="true" keyProperty="id" keyColumn="id"-->
    <insert id="insert" parameterType="Admin" >
        insert into admin(account,password,gender) values (#{account},#{password},#{gender})
    </insert>
</mapper>
7.测试 MyBatis

读取配置文件 Reader reader = Resources.getResourceAsReader("mybatis-config.xml"); 创建 SqlSessionFactory SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);

创建 SqlSession SqlSession sqlSession = sessionFactory.openSession();

获得接口代理对象 sqlSession.getMapper(接口.class); sqlSession .close();

package com.wph.mybatis.Test;

import com.wph.mybatis.dao.AdminDao;
import com.wph.mybatis.model.Admin;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class test {
    public static void main(String[] args) throws IOException {
        //1.mybatis读取配置文件
        Reader reader= Resources.getResourceAsReader("mabiatis.xml");
        //2.创建SqlSeaaionFactory ,负责创建SqlSession对象
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);
        //3.创建SqlSession对象
        SqlSession sqlSession=sqlSessionFactory.openSession();
        //创建接口的代理对象
        AdminDao adminDao =sqlSession.getMapper(AdminDao.class);
        Admin admin=adminDao.findAdminbyid(1);//让代理对象帮我们调用映射文件与此接口中相同名称的方法
        System.out.println(admin);
        sqlSession.close();//关闭会话对象
    }
}

关闭 API 接口说明 SqlSessionFactory 接口 使用 SqlSessionFactory 来创建 SqlSession,一旦创建 SqlSessionFactory 就 会在整个应用过程中始终存在。由于创建开销较大,所以没有理由去销毁再创建 它,一个应用运行中也不建议多次创建 SqlSessionFactory。 SqlSession 接口 Sqlsession 意味着创建与数据库链接会话,该接口中封装了对数据库操作的方 法,与数据库会话完成后关闭会话。

package com.wph.mybatis.Test;

import com.wph.mybatis.dao.AdminDao;
import com.wph.mybatis.model.Admin;
import com.wph.mybatis.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class test3 {

    /*
    单元测试,程序员使用的测试方法,以方法为单位测试
    使用junit组件实现单元测试
    */
    @Test
    public  void  insert(){
        Admin admin=new Admin();
          admin.setAccount("aaa");
          admin.setPassword("123");
          admin.setGender("男");
        SqlSession sqlSession= MyBatisUtil.getSqlsession();
        AdminDao adminDao=sqlSession.getMapper(AdminDao.class);

        adminDao.insert(admin);
        sqlSession.commit();//提交数据库事务,当我们的程序代码执行没有任何问题时,再向数据库发送提交事务操作,数据库真正执行
                           //sql,出现异常则不提交,新增,修改,删除完毕后,都需要手动提交事务
        sqlSession.close();
        /*
        * 数据库事务:是数据库的一个管理机制,是对一次链接数据库过程的管理,
        *           保证一次操作中,执行的多条sql,要么都成功执行,要么都不执行
        * 转账: 链接到数据库
        *   1.先从A账户捡钱sql11
        *   其他代码逻辑(可能出现异常)
        * 2.再向B账户加钱 sql2
        * 提交事务  数据库才会真正的在数据库执行这一次操作中多条sql
        * */
    }

    @Test
    public void delete(){
        SqlSession sqlSession= MyBatisUtil.getSqlsession();
        AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
        adminDao.deleteadmin(1);
        sqlSession.commit();
        sqlSession.close();

    }
    @Test
    public void update(){
        Admin admin=new Admin();
        admin.setAccount("ddd");
        admin.setPassword("666");
        admin.setGender("女");
        admin.setId(1);
        SqlSession sqlSession= MyBatisUtil.getSqlsession();
        AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
        adminDao.update(admin);
    }
}

 

数据库连接池

链接数据库每次访问数据库时候,创建一个Cinnection,用完关闭,但是访问量大了后,每次都要创建新的连接对象,用完关闭,比较耗时

使用数据库连接池,在池(集合)中事先创建一些链接对象,用完不销毁,还回到池中这样就减小频繁创建销毁链接对象。

package com.wph.mybatis.Test;

import com.wph.mybatis.dao.AdminDao;
import com.wph.mybatis.model.Admin;
import com.wph.mybatis.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

public class test2 {
    public static void main(String[] args) {
        //SqlSession是每次与数据库链接会话对象,用完关闭
        SqlSession sqlSession= MyBatisUtil.getSqlsession();
        AdminDao adminDao=sqlSession.getMapper(AdminDao.class);
        adminDao.findAdminbyid(1);
        Admin admin=adminDao.findAdminbyAccount("admin");
        System.out.println(admin);
        //Admin admin=adminDao.login("admin", "111");
        //System.out.println(admin);
        /*Admin admin1=new Admin();
        admin1.setAccount("admin");
        admin1.setPassword("111");
        Admin admin2=adminDao.login1(admin1);*/
        sqlSession.close();//关闭链接对象,如果使用数据库连接功能,本质上没有关闭,回到池中
    }
}
 增删改查

唯一标识" useGeneratedKeys="把新增加的主键赋值到自己定义的 keyProperty " keyProperty=“ 接收主键的属性 parameterType="参数类型">

insert into admin(account,password)values(#{account},#{password})

<!--useGeneratedKeys="true" keyProperty="id" keyColumn="id"-->
    <insert id="insert" parameterType="Admin" >
        insert into admin(account,password,gender) values (#{account},#{password},#{gender})
    </insert>

修改 "唯一标识" parameterType=“参数类型">

 <update id="update" parameterType="Admin">
        update admin set account=#{account},password=#{password},gender=#{gender} where id=#{id}
    </update>

update admin set account= #{account},password= #{password} where id= #{id}

删除 "唯一标识" parameterType="参数类型"> delete from admin where id= #{id}

 <delete id="deleteadmin" parameterType="int">
        delete from admin where id=#{id}
    </delete>

查询 唯一标识" resultType="返回结果集类型"> select * from admin where id= #{id}

 <resultMap id="adminMap" type="Admin">
        <id column="adminid" property="id"></id>
        <result column="account" property="account"></result>
    </resultMap>
    <select id="findadmin" resultMap="adminMap">
        select id adminid ,account from admin
    </select>
#{} 和${}区别

#{} 占位符,是经过预编译的,编译好 SQL 语句再取值,#方式能够防止 sql 注入

#{}:delete from admin where id=#{id}

结果: delete from admin where id = ?

${}会将将值以字符串形式拼接到 sql 语句,

${ }方式无法防止 Sql 注入 ${}: delete from admin where id=’${id}’

结果: delete from admin where id=’1’ 一般是#{ } 向 sql 传值使用, 而使用${ }向 sql 传列名

 <select id="login1" resultType="Admin">
        select * from admin where account=#{account} and password =#{password}
    </select>
    <select id="findbyid" parameterType="java.lang.String" resultType="java.lang.Integer">
        select id from admin where account = ${account}
    </select>
#{}  是占位符,是采用预编译方式向sql中传值,可以防止sql注入,如果我们往sql中传值,使用#{}

${} 是将内容直接拼接到sql语句中,一般不用于向sql中传值,一般用于向sql动态传递列名

区别:

底层实现不同

#{} 采用预编译方式,防止sql注入更加安全

${} 采用字符串拼接,直接将值拼接到sql中

使用场景不同

#{}一般用于向sql中列传值

${}一般用于向sql动态传递列 例如 排序时 order by 后面的列名是可以改变的
特殊处理定义 resultMap

(1). resutlMap 的 id 属性是 resutlMap 的唯一标识,本例中定义为 “adminResultMap”

(2). resutlMap 的 type 属性是映射的 POJO 类型

(3). id 标签映射主键,result 标签映射非主键

(4). property 设置对象属性名称,column 映射查询结果的列名称 

 多表关联处理结果集

resultMap 元素中 association , collection 元素. Collection 关联元素处理一对多关联

 

public class Student {
    private int id;
    private String name;
    private int num;
    private  String gender;
    private int majorid;
    private  Major major;
}
--------------------------------------
public class Major {
    private  int id;
    private String name;
    private List<Student> students;
}
-------------------------------------
  <resultMap id="studentMap" type="Student">
        <id column="id" property="id"></id>
        <result column="num" property="num"></result>
        <result column="name" property="name"></result>
        <result column="gender" property="gender"></result>
        <!--映射关联数据 专业名称-->
        <association property="major" javaType="Major">
            <result column="mname" property="name"></result>
        </association>
    </resultMap>

    <select id="findStudentbyid" resultMap="studentMap">
        select s.id,s.num,s.name,s.gender,m.name mname
        from student s inner join major m on s.majorid=m.id where s.id =#{id}
    </select>
    <select id="findStudents" resultMap="studentMap">
 select s.id,s.num,s.name,s.gender,m.name mname
        from student s inner join major m on s.majorid=m.id </select>
<resultMap id="majorMap" type="Major">
    <id column="id" property="id"></id>
    <result column="name" property="name"></result>
    <collection property="students" javaType="list" ofType="Student">
        <result column="num" property="num"></result>
        <result column="sname" property="name"></result>
    </collection>
</resultMap>
    <select id="findmajorbyid" parameterType="int" resultMap="majorMap">
        select m.id,m.name,s.num,s.name sname
        from major m inner join student s on m.id =s.majorid where m.id=#{id}
    </select>

    <select id="findmajorall" parameterType="int" resultMap="majorMap">
        select m.id,m.name,s.num,s.name sname
        from major m inner join student s on m.id =s.majorid
    </select>
嵌套查询

将一个多表关联查询拆分为多次查询,先查询主表数据,然后查询关联表数据.

(1). select:指定关联查询对象的 Mapper Statement ID 为 findDeptByID

(2). column="dept_id":关联查询时将 dept_id 列的值传入 findDeptByID, 并将 findDeptByID 查询的结果映射到 Emp 的 dept 属性中

(3).collection 和 association 都需要配置 select 和 column 属性,两者配置方法 相同 

 <!--
    =============================================================
    关联查询方式2:嵌套查询  先查询主表(学生表)
    -->

    <resultMap id="studentMap1" type="Student">
        <id column="id" property="id"></id>
        <result column="num" property="num"></result>
        <result column="name" property="name"></result>
        <result column="gender" property="gender"></result>
        <association property="major" javaType="Major" select="findmajorid" column="majorid"></association>
    </resultMap>
    <select id="findbuid" resultMap="studentMap1">
        select id,num,name,gender,majorid from student where id=#{id} ;
    </select>
    <!--嵌套查询学生关联专业-->
    <select id="findmajorid" resultType="Major">
        select name from major where  id=#{majorid}
    </select>

 

  <resultMap id="majorMap1" type="Major">
        <id column="id" property="id"></id>
        <result column="name" property="name"></result>
        <collection property="students" javaType="list" ofType="Student" select="findStudents" column="id"></collection>
    </resultMap>
    <select id="findmajor" resultMap="majorMap1">
        select id,name from major
    </select>
    <select id="findStudents" resultType="Student">
        select num,name from student where majorid =#{id}
    </select>
Mybatis 动态 SQL

MyBatis 的一个强大的特性之一通常是它的动态 SQL 能力。

如果你有使用 JDBC 或其他 相似框架的经验,你就明白条件地串联 SQL 字符串在一起是多么 的痛苦,确保不能忘了空格或在列表的最后省略逗号。

动态 SQL 可以彻底处理 这种痛苦。

MyBatis 中用于实现动态 SQL 的元素主要有:

If wheretrim set choose (when, otherwise) foreach 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wph.mybatis.dao.TeacherDao">
    <!--
    动态sql中添加逻辑判断
       可以在sql中添加逻辑判断
       if  test 属性条件成立 执行if 标签体,不成立就不执行
       where 标签 当where标签 if 语句有条件成立时,就会动态添加where关键字,
          还可以删除where后面紧跟着的关键字
    -->
  <!--  <select id="teachers" resultType="Teacher">
        select * from teacher
        <where>
            <if test="num!=null">
                num = #{num}
            </if>
            <if test="name!=null">
                and name=#{name}
            </if>
            <if test="gender!=null">
                and gender=#{gender}
            </if>
        </where>
    </select>-->

    <select id="teachers" resultType="Teacher">
        select * from teacher
       <trim prefix="where" prefixOverrides="and|or">
           <choose>
               <when test="name!=null">
                   name =#{name}
               </when>
               <otherwise>
                   name='王老师'
               </otherwise>
           </choose>
       </trim>
    </select>

    <select id="findTeacher" resultType="Teacher">
        select
        <foreach item="col" collection="list" separator=",">
            ${col}
        </foreach>
        from teacher
    </select>

    <update id="updateTeacher" parameterType="Teacher">
        update teacher
        <set>
            <if test="num!=null">
                num=#{num},
            </if>
            <if test="name!=null">
                name=#{name},
            </if>
            <if test="gender!=null">
                gender =#{gender}
            </if>
        </set>

        where id=#{id}
    </update>

    <delete id="deleteTeacher">
        delete from teacher where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            ${col}
        </foreach>
        from teacher
    </delete>

    </mapper>

If 元素

if 标签可以对传入的条件进行判断

<where>元素会进行判断,如果它包含的标签中有返回值的话,它就插入一个 ‘where’。

此外,如果标签返回的内容是以 AND 或 OR 开头,它会剔除掉 AND 或 OR。

trim 元素 where 标签,其实用 trim 也可以表示,当 WHERE 后紧随 AND 或则 OR 的时候,就去除 AND 或者 OR。prefix 前缀,prefixOverrides 覆盖首部指定 内容

Set 元素可以把最后一个逗号去掉

• foreach 元素

主要用在构建 in 条件中,它可以在 SQL 语句中进行迭代一个集合。foreach 元素的属性主要有 item,index,collection,open,separator,close。

item 表示集合中每一个元素进行迭代时的别名,index 指定一个名字,用于 表示在迭代过程中,每次迭代到的位置,open 表示该语句以什么开始, separator 表示在每次进行迭代之间以什么符号作为分隔符,close 表示以什 么结束,在使用 foreach 的时候最关键的也是最容易出错的就是 collection 属性,该属性是必须指定的,但是在不同情况下,该属性的值是不一样的。 – 如果传入的是单参数且参数类型是一个 List 的时候,collection 属 性值为 list – 如果传入的是单参数且参数类型是一个 array 数组的时候, collection 的属性值为 array

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

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

相关文章

unity3d拼图__附带资源

要达到吸附效果则需要每个拼图上挂载碰撞体 达到整张图片的替换效果需要选中所有拼图部件把材质球拖上去 、 制作材料球 脚本挂载到随便一个空物体上 using System.Collections; using System.Collections.Generic; using UnityEngine;public class PinTu : MonoBehaviour …

Qt编写贪吃蛇小游戏完整项目

文章目录 前言一、Qt环境准备二、编写思路三、编写代码1、开始游戏界面代码1.1、绘制界面1.2、界面基本配置 2、选择难度界面代码3、游戏房间界面制作3.1、界面基础配置3.2、提前配置类中的成员变量3.2.1、QRectF 3.3、检测游戏是否结束的方法3.4、蛇移动的实现3.4.1、蛇向上移…

智慧农业——生成式人工智能如何改变农业

在数字化转型时代&#xff0c;农业不再仅仅与土壤、水和阳光有关。随着生成式人工智能的出现&#xff0c;农业正变得更加智能、高效&#xff0c;并且越来越以数据为主导。从以前所未有的准确度预测作物产量到开发抗病植物品种&#xff0c;生成式人工智能使农民能够做出精确的决…

c语言个人笔记

linux嵌入式C语言 课程链接: [史上最强最细腻的linux嵌入式C语言学习教程李慧芹老师] 0. gcc与vim的使用 gcc 指令 -Wall:显示所有警告 gcc默认的警告包括真正的错误&#xff1a;error和 告警warning 执行过程 c源代码.c -> 预处理(E) -> 编译(S) -> 汇编©.o…

Clickhouse集群化(五)clickhouse语法学习

1. 基础 1.1. 建表建库 CREATE DATABASE IF NOT EXISTS helloworld use default; CREATE TABLE IF NOT EXISTS system_cpu_info (uuid String, -- 主机的唯一标识符source String, -- 数据来源标识resource_pool Strin…

011_IO体系

Java的IO流是实现输入/输出的基础&#xff0c;它可以方便地实现数据的输入/输出操作&#xff0c;在Java中把不同的输入/输出源抽象表述为"流"。 流是一组有顺序的&#xff0c;有起点和终点的字节集合&#xff0c;是对数据传输的总称或抽象。即数据在两设备间的传输称…

代码随想录 刷题记录-18 动态规划(1)基本理论及习题

一、基本理论 什么是动态规划 动态规划&#xff0c;英文&#xff1a;Dynamic Programming&#xff0c;简称DP&#xff0c;如果某一问题有很多重叠子问题&#xff0c;使用动态规划是最有效的。 所以动态规划中每一个状态一定是由上一个状态推导出来的&#xff0c;这一点就区分…

码云 云片滑块 分析

声明: 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;抓包内容、敏感网址、数据接口等均已做脱敏处理&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01; 有相关问题请第一时间头像私信联系我…

小乌龟运动控制-3两只小乌龟

系列文章目录 提示&#xff1a;这里可以添加系列文章的所有文章的目录&#xff0c;目录需要自己手动添加 例如&#xff1a;第一章 Python 机器学习入门之pandas的使用 提示&#xff1a;写完文章后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目…

【自动驾驶】决策规划算法 | 数学基础(一)五次多项式详解

写在前面&#xff1a; &#x1f31f; 欢迎光临 清流君 的博客小天地&#xff0c;这里是我分享技术与心得的温馨角落。&#x1f4dd; 个人主页&#xff1a;清流君_CSDN博客&#xff0c;期待与您一同探索 移动机器人 领域的无限可能。 &#x1f50d; 本文系 清流君 原创之作&…

Mysql系列—3.体系架构

目录 Mysql体系结构 Connectors&#xff1a; 连接池和线程管理&#xff1a; SQL Interface&#xff1a; Parser&#xff08;查询解析器&#xff09;&#xff1a; Optimizer&#xff08;优化器&#xff09;&#xff1a; Caches&#xff08;缓存&#xff09;&#xff1a; …

Clickhouse集群化(四)使用clickhouse-operator部署clickhouse集群

clickhouse operator实际下就是帮助我们自动化的生产一些clickhouse配置文件信息&#xff0c;在目录/etc/clickhouse-server/的config.d conf.d users.d 1.1. 部署clickhouse operateor 下载clickhouse-operator.yaml文件 wget https://raw.githubusercontent.com/Altinity/…

Vue3 前端导出Excel表格 Xlsx格式

介绍 xlsx 是一个用于处理 Excel 文件的流行库。可以你读取、生成和操作 Excel 文件&#xff08;.xlsx 格式&#xff09;&#xff0c;提供了强大的功能来处理工作表和单元格数据。可以轻松地将 JSON 数据转换为 Excel 表格&#xff0c;也可以从 Excel 文件中读取数据。 安装 …

【Linux篇】网络请求和下载与端口

目录 1. 网络请求和下载 1.1 ping命令 1.2 wget命令 1.3 curl命令 2. 端口 2.1 查看端口占用 使用nmap命令&#xff0c;安装nmap&#xff1a;yum -y install nmap 可以通过netstat命令&#xff0c;查看指定端口的占用情况。 3. 进程管理 3.1 进程 3.2 查看进程 3.3 …

Llama 4B剪枝蒸馏实战

大型语言模型 (LLM) 因其有效性和多功能性&#xff0c;如今已成为自然语言处理和理解领域的主导力量。LLM&#xff08;例如 Llama 3.1 405B 和 NVIDIA Nemotron-4 340B&#xff09;在许多具有挑战性的任务中表现出色&#xff0c;包括编码、推理和数学。然而&#xff0c;它们的部…

异步编程之std::future(二): std::future和std::promise原理

目录 1.引言 2.源码分析 2.1.std::promise的源码实现 2.2.std::future的源码实现 2.3.关联状态对象的代码实现 3.整个类图 4.future和promise之间的并发安全和线程同步 5.总结 1.引言 异步编程之std::future(一): 使用-CSDN博客 在std::future(一)中详…

【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range

【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range 环境 linux diffusers 0.30.0问题详情 报错详情 from diffusers import KolorsPipelineTraceback (most recent call last):File "Kolors/demo.py", line 6, in <module>pi…

Vue(2)——Vue指令

目录 v-html v-show和v-if v-else和v-else-if v-on v-bind v-for v-model v-html 设置元素的innerHTML <body><div id"app"><div v-html"msg"></div></div><script src"https://cdn.jsdelivr.net/npm/vue2.…

大模型从入门到精通——基于智谱AI和LangChain实现RAG应用(一)

基于智谱AI和LangChain实现RAG应用(一) 1. 使用 LangChain 调用智谱 GLM 1.1 自定义chatglm #!/usr/bin/env python # -*- encoding: utf-8 -*-from typing import Any, List, Mapping, Optional, Dict from langchain_core.callbacks.manager import CallbackManagerForLLM…

统一身份认证服务(CAS)系统实现SSO认识

一、前言 CAS&#xff08;Central Authentication Service&#xff09;即中央认证服务&#xff0c;是 Yale 大学发起的一个企业级开源项目&#xff0c;旨在为 Web 应用系统提供一种可靠的 SSO 解决方案&#xff0c;它是一个企业级的开源单点认证登录解决方案&#xff0c;采用ja…