(2-10-1)MyBatis的基础与基本使用

目录

0.前置小节

1. MyBatis 框架介绍

1.1 软件开发中的框架

1.2 使用框架的好处

1.3 SSM 开发框架

1.4 什么是 MyBatis

1.5 MyBatis 的开发流程

2. MyBatis 的开发流程

2.0 MyBatis的工作流程

2.1 引入 MyBatis 依赖

00.base(目录、pom、单元测试、Junit4)

01.Calculator

02. CalculatorTest

2.2 创建核心配置文件

00. mybatis-config.xml

01. 引入myBatis 与Mysql-jdbc 依赖

02. 添加 Mysql 数据源

03. 测试连接

04. 导入sql脚本

05. 编写 mybatis-config.xml

06.单元测试(sqlSession)

07. 创建工具类 MyBatisUtils

2.3 Mybatis 数据查询步骤

01. 编写Goods实体类

02. 创建 Mapper 文件

03. 编写select SQL 标签

04. 开启驼峰命名映射

05. 新增mapper

06. SqlSession执行select语句

07. SQL 传单参

08. SQL 传多参

3. 结果集映射查询

3.1 利用 LinkedHashMap 保存多表关联结果

00.base

01. goods.xml

02. testSelectGoodsMap()

03. 实现效果

3.2 ResultMap 结果映射

01. 新建dto 数据传输对象

02. 编写测试类

03. 运行效果

3.3 ResultMap 进一步的封装

01. Category

02. 完善GoodsDTO

03. goods.xml

04.  运行效果

4. 数据插入

4.1数据库事务 与 insertDemo

4.2 goods.xml

4.3.testInsertGoods()

4.4 新增Id无法获取

4.5 selectKey完善good.xml

4.5 useGeneratedKeys完善good.xml

4.6 selectKey与useGeneratedKeys的区别

5. 更新数据

5.1 baseDemo

5.2 goods.xml

5.3 testUpdateGoods()

6. 删除数据

6.1 baseDemo

6.2 goods.xml

6.3 deleteUpdateGoods()

7. Mybatis 预防SQL注入攻击

7.1 baseDemo

7.2 MyBatis 的两种传值方式

7.3 goods.xml

7.4 testSelectByTitle01(#{})

7.5 testSelectByTitle02()


官方文档网站:

MyBatis 中文网 官网

0.前置小节

1. MyBatis 框架介绍

1.1 软件开发中的框架

1.2 使用框架的好处

1.3 SSM 开发框架

1.4 什么是 MyBatis

1.5 MyBatis 的开发流程

2. MyBatis 的开发流程

2.0 MyBatis的工作流程

2.1 引入 MyBatis 依赖

00.base(目录、pom、单元测试、Junit4)

<?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.phdvb</groupId><artifactId>MyBatisProj</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><!--配置阿里云私服远程仓库,  当阿里云的私服没有的时候才回去官网下载--><repositories><repository><id>aliyun</id><name>aliyun</name><url>https://maven.aliyun.com/repository/public</url></repository></repositories><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency></dependencies></project>

01.Calculator
package com.phdvb.junit;public class Calculator {//加法运算public int add(int a, int b) {return a + b;}//减法运算public int substruct(int a, int b) {return a - b;}//乘法运算public int multiply(int a, int b) {return a * b;}//除法运算public int divide(int a, int b) {return a / b;}
}
02. CalculatorTest
import com.phdvb.junit.Calculator;
import org.junit.Test;public class CalculatorTest {private Calculator calculator = new Calculator();@Testpublic void test(){System.out.println(calculator.add(1, 2));System.out.println(calculator.substruct(1,2));System.out.println(calculator.multiply(1,2));System.out.println(calculator.divide(1,2));}
}

2.2 创建核心配置文件

00. mybatis-config.xml

参考demo:

01. 引入myBatis 与Mysql-jdbc 依赖

02. 添加 Mysql 数据源

03. 测试连接

04. 导入sql脚本

通过网盘分享的文件:(10.1.3)--MyBatis源代码【 全网最全it资源v:it1646】.zip
链接: https://pan.baidu.com/s/1bSao39sgwziDwHtic91bsA 提取码: 7cqp 复制这段内容后打开百度网盘手机App,操作更方便哦

05. 编写 mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- 设置默认指向的数据库--><environments default="dev"><!-- 配置环境, 不同的环境对应不同的id名字--><environment id="dev"><!-- 采用JDBC的方式对 数据库事务进行 commit/ rollback--><transactionManager type="JDBC"></transactionManager><!-- 采用连接池的方式管理数据库连接--><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://127.0.0.1:3303/phdvb?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai"/><property name="username" value="root"/><property name="password" value="123456"/></dataSource></environment><environment id="prod"><!-- 采用JDBC的方式对 数据库事务进行 commit/ rollback--><transactionManager type="JDBC"></transactionManager><!-- 采用连接池的方式管理数据库连接--><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://114.114.114.114:3303/phdvb?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai"/><property name="username" value="root"/><property name="password" value="123456"/></dataSource></environment></environments>
</configuration>
06.单元测试(sqlSession)

package com.phdvb.mybatis;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 org.junit.Test;import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;/*** Junit 单元测试 MyBatis*/
public class MyBatisTestor {@Testpublic void testSqlSessionFactory() throws IOException {// 通过 Reader 加载classPath 下的 mybatis-config.xml 核心配置文件Reader reader = Resources.getResourceAsReader("mybatis-config.xml");// 初始化sqlSessionFactory对象, 同时解析下的 mybatis-config.xml 核心配置文件SqlSessionFactory sqlSessionFactory =new SqlSessionFactoryBuilder().build(reader);System.out.println("sqlSessionFactory加载成功!");SqlSession sqlSession = null;try{// 创建 SqlSession 对象,SqlSession 是JDBC 的扩展类, 用于与数据库交互sqlSession = sqlSessionFactory.openSession();// 创建数据库连接(测试使用,正常情况下不需要手动创建)Connection connection = sqlSession.getConnection();System.out.println(connection);      //com.mysql.cj.jdbc.ConnectionImpl@2d127a61}catch (Exception e){e.printStackTrace();}finally{if(sqlSession != null){// 如果 type = "POOLED", 代表使用的是连接池,close()则是将连接回收到连接池中// 如果 type = "UNPOOLED", 代表的是直连, close()则会条用Connection.close()关闭连接sqlSession.close();}}}
}
07. 创建工具类 MyBatisUtils
package com.phdvb.mybatis.utils;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;/*** 将 MyBatisTestor 的i相关 方法 ,封装为工具类*/
public class MyBatisUtils {// 利用 static(静态) 属于类不属于对象, 且全局唯一private static SqlSessionFactory sqlSessionFactory = null;// 利用静态块 在初始化时 实例化sqkSessionFactorystatic{Reader reader = null;try {// 通过 Reader 加载classPath 下的 mybatis-config.xml 核心配置文件reader = Resources.getResourceAsReader("mybatis-config.xml");// 对sqlSessionFactory对象赋值, 同时解析下的 mybatis-config.xml 核心配置文件sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);} catch (IOException e) {e.printStackTrace();// 初始化错误时, 通过抛出异常 ExceptionInInitializerError 通知调用者throw new ExceptionInInitializerError(e);}}/*** 创建一个 新的SqlSession 对象* @return*/public static SqlSession openSession(){return sqlSessionFactory.openSession();}/*** 释放一个有效的 SqlSession  对象* @param session*/public static void closeSession(SqlSession session){if(session != null){session.close();}}
}

单元测试方法:

// 测试封装的MyBatisUtils工具类@Testpublic void testMybatisUtils(){SqlSession  sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Connection connection = sqlSession.getConnection();System.out.println(connection);}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

2.3 Mybatis 数据查询步骤

01. 编写Goods实体类
package com.phdvb.mybatis.entity;public class Goods {private Integer goodsId;            // 商品编号private String title;               // 商品标题private String subTitle;            // 子标题private Float originalCost;         // 原始价格private Float currentPrice;         // 当前价格private Float discount;             // 折扣率private Integer isFreeDelivery;     // 是否包邮(1-包邮, 0- 不包邮)private Integer categoryId;         // 分类编号public Integer getGoodsId() {return goodsId;}public void setGoodsId(Integer goodsId) {this.goodsId = goodsId;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getSubTitle() {return subTitle;}public void setSubTitle(String subTitle) {this.subTitle = subTitle;}public Float getOriginalCost() {return originalCost;}public void setOriginalCost(Float originalCost) {this.originalCost = originalCost;}public Float getCurrentPrice() {return currentPrice;}public void setCurrentPrice(Float currentPrice) {this.currentPrice = currentPrice;}public Float getDiscount() {return discount;}public void setDiscount(Float discount) {this.discount = discount;}public Integer getIsFreeDelivery() {return isFreeDelivery;}public void setIsFreeDelivery(Integer isFreeDelivery) {this.isFreeDelivery = isFreeDelivery;}public Integer getCategoryId() {return categoryId;}public void setCategoryId(Integer categoryId) {this.categoryId = categoryId;}
}
02. 创建 Mapper 文件

03. 编写select SQL 标签
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="goods"><select id="selectAll" resultType="com.phdvb.mybatis.entity.Goods">select * from t_goods order by goods_id desc limit 7;</select>
</mapper>
04. 开启驼峰命名映射

05. 新增mapper

06. SqlSession执行select语句
@Testpublic void testSelectAll() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();List<Goods> list = sqlSession.selectList("goods.selectAll");for(Goods goods : list){System.out.println(goods.getGoodsId() + "-"+ goods.getTitle());}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

07. SQL 传单参

base:

goods.xml

    <!--SQL 传参 id--><select id = "selectById" parameterType="Integer" resultType="com.phdvb.mybatis.entity.Goods">select * from t_goods where goods_id = #{value};</select>

测试方法

    @Testpublic void testSelectById() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Goods goods = sqlSession.selectOne("goods.selectById", 831);System.out.println(goods.getTitle());}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

实现效果:

08. SQL 传多参

goods.xml

    <!--多参数传递--><select id="selectByPriceRange" parameterType="java.util.Map" resultType="com.phdvb.mybatis.entity.Goods">select * from t_goodswherecurrent_price between #{minPrice} and #{maxPrice}limit 0, #{limitNum}</select>
testSelectById
    @Testpublic void selectByPriceRange() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Map param = new HashMap();param.put("minPrice", 240);param.put("maxPrice", 740);param.put("limitNum", 5);List<Goods> list = sqlSession.selectList("goods.selectByPriceRange", param);for(Goods g: list){System.out.println(g.getGoodsId() + "-"+ g.getTitle()+'-'+g.getCurrentPrice());}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

实现效果:

3. 结果集映射查询

3.1 利用 LinkedHashMap 保存多表关联结果

00.base
<!--利用 LinkedHashMap 保存多表关联结果-->
<!--1. Mybatis 会将每一条记录 包装为 LinkedHashMap对象2. 其中字段类型根据表结构自动判断3. 优点: 易于扩展,易用使用4. 缺点: 过于灵活, 无法进行编译时检查
-->
01. goods.xml
<!--利用 LinkedHashMap 保存多表关联结果--><!--1.Mybatis 会将每一条记录 包装为 LinkedHashMap对象2.其中字段类型根据表结构自动判断3. 优点: 易于扩展,易用使用4. 缺点: 过于灵活, 无法进行编译时检查--><select id="selectGoodsMap" resultType="java.util.LinkedHashMap">select gs.*, ca.category_name, '1' as test from t_goods gs, t_category ca where gs.category_id = ca.category_id;</select>
02. testSelectGoodsMap()
    @Testpublic void testSelectGoodsMap() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();List<Map> list = sqlSession.selectList("goods.selectGoodsMap");for(Map map: list){System.out.println(map);}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}
03. 实现效果

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
{goods_id=739, title=亲润 孕妇护肤品豆乳大米盈润保湿胶原蚕丝面膜(18片装), sub_title=卓效对抗孕期干燥,15分钟快速补水,补充胶原蛋白,幼滑肌肤。天然豆乳配方,温和低敏,孕产期、所有肤质适用。, original_cost=198.0, current_price=88.0, discount=0.444444, is_free_delivery=1, category_id=43, category_name=米粉, test=1}
{goods_id=740, title=爱恩幼 孕妇护肤品润养颜睡眠面膜 100g, sub_title=免洗配方,质地清透不黏腻,睡眠间为肌肤持续补充营养,并牢牢锁住水分,清晨醒来后,肌肤水润柔嫩,洋溢青春活力。, original_cost=96.0, current_price=49.0, discount=0.510417, is_free_delivery=1, category_id=44, category_name=牙胶/咬咬乐, test=1}

...

3.2 ResultMap 结果映射

01. 新建dto 数据传输对象
package com.phdvb.mybatis.dto;import com.phdvb.mybatis.entity.Goods;// dto --> 数据传输对象
public class GoodsDTO {private Goods goods = new Goods();private String categoryName;private String test;public Goods getGoods() {return goods;}public void setGoods(Goods goods) {this.goods = goods;}public String getCategoryName() {return categoryName;}public void setCategoryName(String categoryName) {this.categoryName = categoryName;}public String getTest() {return test;}public void setTest(String test) {this.test = test;}
}
02. 编写测试类
@Testpublic void testSelectGoodsDTO() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();List<GoodsDTO> list = sqlSession.selectList("goods.selectGoodsDTO");for(GoodsDTO goods: list){System.out.println(goods.getGoods().getSubTitle());}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}
03. 运行效果

3.3 ResultMap 进一步的封装

01. Category
package com.phdvb.mybatis.entity;public class Category {private Integer categoryId;private String categoryName;private Integer parentId;private Integer categoryLevel;private Integer categroyOrder;public Integer getCategoryId() {return categoryId;}public void setCategoryId(Integer categoryId) {this.categoryId = categoryId;}public String getCategoryName() {return categoryName;}public void setCategoryName(String categoryName) {this.categoryName = categoryName;}public Integer getParentId() {return parentId;}public void setParentId(Integer parentId) {this.parentId = parentId;}public Integer getCategoryLevel() {return categoryLevel;}public void setCategoryLevel(Integer categoryLevel) {this.categoryLevel = categoryLevel;}public Integer getCategroyOrder() {return categroyOrder;}public void setCategroyOrder(Integer categroyOrder) {this.categroyOrder = categroyOrder;}
}
02. 完善GoodsDTO
package com.phdvb.mybatis.dto;import com.phdvb.mybatis.entity.Category;
import com.phdvb.mybatis.entity.Goods;// dto --> 数据传输对象
public class GoodsDTO {private Goods goods = new Goods();
//    private String categoryName;private Category category = new Category();private String test;public Goods getGoods() {return goods;}public void setGoods(Goods goods) {this.goods = goods;}public Category getCategory() {return category;}public void setCategory(Category category) {this.category = category;}
//    public String getCategoryName() {
//        return categoryName;
//    }
//
//    public void setCategoryName(String categoryName) {
//        this.categoryName = categoryName;
//    }public String getTest() {return test;}public void setTest(String test) {this.test = test;}
}
03. goods.xml
    <!--结果映射--><resultMap id="rmGoods" type="com.phdvb.mybatis.dto.GoodsDTO"><!--设置主键字段与属性映射--><id property = "goods.goodsId" column="goods_id"></id><!--设置非主键字段与属性映射--><result property="goods.title" column="title"></result><result property="goods.subTitle" column="sub_title"></result><result property="goods.originalCost" column="original_cost"></result><result property="goods.currentPrice" column="current_price"></result><result property="goods.discount" column="discount"></result><result property="goods.isFreeDelivery" column="is_free_delivery"></result>
<!--        <result property="goods.categoryId" column="category_id"></result>-->
<!--        <result property="categoryName" column="category_name"></result>--><result property="category.categoryId" column="category_id"></result><result property="category.categoryName" column="category_name"></result><result property="category.parentId" column="parent_Id"></result><result property="category.categoryLevel" column="category_level"></result><result property="category.categoryOrder" column="category_order"></result><result property="test" column="test"></result></resultMap><select id="selectGoodsDTO" resultMap="rmGoods">select gs.*, ca.*, '1' as test from t_goods gs, t_category ca where gs.category_id = ca.category_id;</select>
04.  运行效果

4. 数据插入

4.1数据库事务 与 insertDemo

4.2 goods.xml

<!--插入数据--><insert id="insertGoods" parameterType="com.phdvb.mybatis.entity.Goods">insert into t_goods(title, sub_title, original_cost, current_price, discount, is_free_delivery, category_id)values (#{title}, #{subTitle}, #{originalCost}, #{currentPrice}, #{discount}, #{isFreeDelivery}, #{categoryId})</insert>

4.3.testInsertGoods()

@Testpublic void testInsertGoods() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Goods goods = new Goods();goods.setTitle("华为蓝牙耳机");goods.setSubTitle("feel good!");goods.setOriginalCost(109f);goods.setCurrentPrice(99f);goods.setDiscount(0.6f);goods.setIsFreeDelivery(1);goods.setCategoryId(43);int rows = sqlSession.insert("goods.insertGoods", goods);// 提交事务 数据sqlSession.commit();System.out.println(goods.getGoodsId() + "-"+ goods.getTitle());}catch (Exception e){if(sqlSession != null){// 回滚事务sqlSession.rollback();}throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

4.4 新增Id无法获取

4.5 selectKey完善good.xml

<!--插入数据--><insert id="insertGoods" parameterType="com.phdvb.mybatis.entity.Goods">insert into t_goods(title, sub_title, original_cost, current_price, discount, is_free_delivery, category_id)values (#{title}, #{subTitle}, #{originalCost}, #{currentPrice}, #{discount}, #{isFreeDelivery}, #{categoryId})<selectKey resultType="Integer" keyProperty="goodsId" order="AFTER">select last_insert_id();</selectKey></insert>

4.5 useGeneratedKeys完善good.xml

 <!--useGeneratedKeys完善插入数据--><insert id="insertGoods"parameterType="com.phdvb.mybatis.entity.Goods"useGeneratedKeys="true"keyProperty="goodsId"keyColumn="goods_id">insert into t_goods(title, sub_title, original_cost, current_price, discount, is_free_delivery, category_id)values (#{title}, #{subTitle}, #{originalCost}, #{currentPrice}, #{discount}, #{isFreeDelivery}, #{categoryId})</insert>

4.6 selectKey与useGeneratedKeys的区别

5. 更新数据

5.1 baseDemo

5.2 goods.xml

<!--更新操作--><update id="updateGoods" parameterType="com.phdvb.mybatis.entity.Goods">update t_goodssettitle =  #{title},sub_title = #{subTitle},original_cost = #{originalCost},current_price = #{currentPrice},discount = #{discount},is_free_delivery = #{isFreeDelivery},category_id = #{categoryId}wheregoods_id = #{goodsId}</update>

5.3 testUpdateGoods()

@Testpublic void testUpdateGoods() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Goods goods = sqlSession.selectOne("goods.selectById", 739);goods.setTitle("更新为华为蓝牙耳机");sqlSession.update("goods.updateGoods", goods);// 提交事务 数据sqlSession.commit();System.out.println(goods.getGoodsId() + "-"+ goods.getTitle());}catch (Exception e){if(sqlSession != null){// 回滚事务sqlSession.rollback();}throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

6. 删除数据

6.1 baseDemo

6.2 goods.xml

    <!--删除数据--><delete id="deleteGoods" parameterType="Integer">delete from t_goods where goods_id = #{value}</delete>

6.3 deleteUpdateGoods()

@Testpublic void deleteUpdateGoods() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();int num = sqlSession.delete("goods.deleteGoods", 739);// 提交事务 数据sqlSession.commit();}catch (Exception e){if(sqlSession != null){// 回滚事务sqlSession.rollback();}throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

7. Mybatis 预防SQL注入攻击

7.1 baseDemo

7.2 MyBatis 的两种传值方式

7.3 goods.xml

    <!--测试SQL注入--><select id="selectByTitle" parameterType="java.util.Map" resultType="com.phdvb.mybatis.entity.Goods">select * from t_goods where title = #{title}</select><select id="selectByTitleAndOrder" parameterType="java.util.Map" resultType="com.phdvb.mybatis.entity.Goods">select * from t_goods where title = ${title}</select>

7.4 testSelectByTitle01(#{})

@Testpublic void testSelectByTitle01() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Map param = new HashMap();param.put("title","'爱恩幼 孕妇护肤品润养颜睡眠面膜 100g'");List<Goods> list = sqlSession.selectList("goods.selectByTitle", param);for(Goods goods: list){System.out.println(goods.getSubTitle() + ":" + goods.getDiscount());}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

没有输出

7.5 testSelectByTitle02()
@Testpublic void testSelectByTitle02() throws Exception{SqlSession sqlSession = null;try{sqlSession = MyBatisUtils.openSession();Map param = new HashMap();param.put("title","'爱恩幼 孕妇护肤品润养颜睡眠面膜 100g'");List<Goods> list = sqlSession.selectList("goods.selectByTitleAndOrder", param);for(Goods goods: list){System.out.println(goods.getSubTitle() + ":" + goods.getDiscount());}}catch (Exception e){throw e;}finally{MyBatisUtils.closeSession(sqlSession);}}

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

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

相关文章

StarRocks集群部署

Starrocks 是一款基于 MPP 架构的高性能实时分析型数据库&#xff0c;专为 OLAP&#xff08;联机分析处理&#xff09;场景 设计&#xff0c;尤其擅长处理海量数据的实时分析、复杂查询和多维统计。 硬件 CPU&#xff1a;StarRocks依靠AVX2指令集充分发挥其矢量化能力。因此&am…

【CPP】自己实现一个CPP小工具demo,可以扩展其他选项

自己写CPP脚本小工具1. 思路描述2. 代码实现2.1 代码文件CppTool.cpp2.2 CMakeLists.txt3. 工具示例3.1 帮助信息3.2 工具用法3.3 实际使用1. 思路描述 实现一个简单的命令行工具。内容包括&#xff1a; 命令帮助信息参数检查&#xff0c;参数解析等功能。执行其他命令。将指…

如何使用嵌入模型创建本地知识库Demo

为data目录下的txt文档用阿里百炼的文本嵌入模型创建一个本地知识库import os from llama_index.core import ,Settings, SimpleDirectoryReader, VectorStoreIndex from llama_index.core.node_parser import SentenceSplitter from llama_index.llms.dashscope import DashSc…

SpringBoot 整合 Langchain4j:系统提示词与用户提示词实战详解

> 掌握提示词工程的核心技巧,让你的AI应用效果提升300%! **真实痛点**:为什么同样的模型,别人的应用精准专业,而你的却答非所问?关键在于提示词工程!本文将揭秘如何通过系统提示词与用户提示词的巧妙配合,打造专业级AI应用。 --- ### 一、Langchain4j 核心概念…

Sklearn 机器学习 邮件文本分类 加载邮件数据

💖亲爱的技术爱好者们,热烈欢迎来到 Kant2048 的博客!我是 Thomas Kant,很开心能在CSDN上与你们相遇~💖 本博客的精华专栏: 【自动化测试】 【测试经验】 【人工智能】 【Python】 Sklearn 机器学习 邮件文本分类 - 加载邮件数据 在自然语言处理(NLP)中,邮件文本分…

腾讯云开发小程序工具箱使用心得

一、核心优势与使用体验 作为首批使用腾讯云开发&#xff08;CloudBase&#xff09;工具箱的开发者&#xff0c;我深刻感受到其通过CloudBase AI与MCP服务重构开发范式的创新价值。结合微信小程序开发场景&#xff0c;该平台在以下维度表现突出&#xff1a; 1. AI驱动的全栈开发…

机械加工元件——工业精密制造的璀璨明珠

在工业制造的宏大画卷中&#xff0c;机械加工元件犹如璀璨的明珠&#xff0c;以其卓越的性能和精湛的工艺&#xff0c;为各行各业的发展注入了源源不断的动力。它们虽形态各异&#xff0c;功能不同&#xff0c;却在无数产品中携手合作&#xff0c;展现出科技与柔性的完美融合。…

【八股】Redis-中小厂精要八股

Redis 基础 redis为什么这么快 (高) [!NOTE] 最首要的是Redis是纯内存操作, 比磁盘要快3个数量级同时在与内存操作中采用了非阻塞I/O多路复用机制来提高并发量并且基于Redis的IO密集型&#xff0c;采用单线程操作, 免去了线程切换开销Redis 内置了多种优化过后的数据结构实现…

C++字符串(string)操作解析:从基础到进阶

1. 字符串基础&#xff1a;大小与容量cppvoid test1() {string s1("Hello World");cout << "size : " << s1.size() << endl; // 输出字符串长度cout << "capacity " << s1.capacity() << endl; // 输出字…

蘑兔音乐:音乐创作的魔法棒

在这个充满创意与可能的时代&#xff0c;人人都有一颗渴望表达音乐之心。但传统音乐创作&#xff0c;复杂的乐理、昂贵的设备&#xff0c;总让人望而却步。别担心&#xff01;蘑兔 AI 音乐强势来袭&#xff0c;它就是那个能让音乐小白也能搞创作的神奇工具&#xff01;​灵感模…

从传统到智能:RFID 技术如何重构压缩机生产线

从传统到智能&#xff1a;RFID 技术如何重构压缩机生产线在工业 4.0 与中国制造 2025 战略的深入推进下&#xff0c;作为空调核心部件的压缩机制造业正加速从传统生产模式向智能化转型。压缩机生产以高精度、大批量为显著特点&#xff0c;长期面临生产数据断层、柔性化不足、质…

HTML5二十四节气网站源码

一. 二十四节气文化主题网站概述 本网站以中国传统文化瑰宝“二十四节气”为核心&#xff0c;通过现代Web技术打造沉浸式文化体验平台&#xff0c;融合视觉美学与交互创新&#xff0c;全方位展现节气的自然规律与人文内涵。网站采用响应式布局设计&#xff0c;适配多终端设备&…

微服务架构实战指南:从单体应用到云原生的蜕变之路

&#x1f31f; Hello&#xff0c;我是蒋星熠Jaxonic&#xff01; &#x1f308; 在浩瀚无垠的技术宇宙中&#xff0c;我是一名执着的星际旅人&#xff0c;用代码绘制探索的轨迹。 &#x1f680; 每一个算法都是我点燃的推进器&#xff0c;每一行代码都是我航行的星图。 &#x…

超越Transformer:大模型架构创新的深度探索

引言&#xff1a; 以GPT、Claude、Gemini等为代表的大语言模型&#xff08;LLMs&#xff09;已成为人工智能领域的核心驱动力。它们基于Transformer架构构建&#xff0c;在理解和生成人类语言方面展现出惊人的能力。然而&#xff0c;随着模型规模指数级增长和对更长上下文、更高…

完整设计 之 智能合约系统:主题约定、代理协议和智能合约 (临时命名)--腾讯元宝答问

本文要点和任务整体设计&#xff08;符号学 &#xff1a;为了诠释学实践运用 形。而上理论&#xff0c;将自己作为 两者结合的 条带 &#xff09;&#xff0c;包括三部分&#xff1a;内核&#xff08;设置-组态-主动把握的操作&#xff09;是认知学&#xff08;语义&#xff09…

同创物流学习记录2·电车光电

灯在闪烁&#xff0c;照到你前面的东西了&#xff0c;它可以照前面&#xff0c;可以照6米远。你那个电车前面五六米感应到东西了&#xff0c;它就会减速&#xff0c;然后到3米的样子&#xff0c;它会再减速。然后再到1米2的样子&#xff0c;它就会停下来。电车前侧光电这个区域…

linux I2C核心、总线与设备驱动

一、 linux I2C体系结构linux的I2C体系结构分为3个组成部分1&#xff09;I2C核心I2C核心提供了I2C总线驱动与设备驱动的注册、注销方法&#xff0c;I2C通信方法&#xff08;即Algorithm&#xff09;上层的与具体适配器无关的代码及其探测设备、检测设备地址的上层代码等…

跑实验记录

1.下载git&#xff08;base) mqmq-MS-7A59:~/桌面$ sudo apt update && sudo apt install git2.克隆项目&#xff08;base) mqmq-MS-7A59:~/桌面$ sudo apt update && sudo apt install git3.canda创建环境(base) mqmq-MS-7A59:~$ conda create -n HyTE python…

微软动手了,联合OpenAI + Azure 云争夺AI服务市场

❝开头还是介绍一下群&#xff0c;如果感兴趣PolarDB ,MongoDB ,MySQL ,PostgreSQL ,Redis, OceanBase, Sql Server等有问题&#xff0c;有需求都可以加群群内有各大数据库行业大咖&#xff0c;可以解决你的问题。加群请联系 liuaustin3 &#xff0c;&#xff08;共3300人左右 …

Reading Coach-微软推出的免费AI阅读教练

本文转载自&#xff1a;Reading Coach-微软推出的免费AI阅读教练 - Hello123工具导航 ** 一、智能阅读辅助工具 Reading Coach 是微软推出的 AI 驱动阅读训练平台&#xff0c;通过个性化故事生成与实时发音反馈&#xff0c;帮助学生提升阅读流利度与词汇量。平台采用自适应学…