首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

黑马MyBatis(配套源码)

后端 46.71KB 31 需要积分: 1
立即下载

资源介绍:

http://t.csdnimg.cn/fAEpc
package com.itheima.test; import com.itheima.mapper.BrandMapper; import com.itheima.pojo.Brand; 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.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.HashMap; import java.util.List; import java.util.Map; public class MyBatisTest { @Test public void testSelectAll() throws IOException { //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 List brands = brandMapper.selectAll(); System.out.println(brands); //5. 释放资源 sqlSession.close(); } @Test public void testSelectById() throws IOException { //接收参数 int id = 1; //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 Brand brand = brandMapper.selectById(id); System.out.println(brand); //5. 释放资源 sqlSession.close(); } @Test public void testSelectByCondition() throws IOException { //接收参数 int status = 1; String companyName = "华为"; String brandName = "华为"; // 处理参数 companyName = "%" + companyName + "%"; brandName = "%" + brandName + "%"; //封装对象 /* Brand brand = new Brand(); brand.setStatus(status); brand.setCompanyName(companyName); brand.setBrandName(brandName);*/ Map map = new HashMap(); // map.put("status" , status); map.put("companyName", companyName); // map.put("brandName" , brandName); //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 //List brands = brandMapper.selectByCondition(status, companyName, brandName); // List brands = brandMapper.selectByCondition(brand); List brands = brandMapper.selectByCondition(map); System.out.println(brands); //5. 释放资源 sqlSession.close(); } @Test public void testSelectByConditionSingle() throws IOException { //接收参数 int status = 1; String companyName = "华为"; String brandName = "华为"; // 处理参数 companyName = "%" + companyName + "%"; brandName = "%" + brandName + "%"; //封装对象 Brand brand = new Brand(); //brand.setStatus(status); brand.setCompanyName(companyName); //brand.setBrandName(brandName); //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 //List brands = brandMapper.selectByCondition(status, companyName, brandName); // List brands = brandMapper.selectByCondition(brand); List brands = brandMapper.selectByConditionSingle(brand); System.out.println(brands); //5. 释放资源 sqlSession.close(); } @Test public void testAdd() throws IOException { //接收参数 int status = 1; String companyName = "波导手机"; String brandName = "波导"; String description = "手机中的战斗机"; int ordered = 100; //封装对象 Brand brand = new Brand(); brand.setStatus(status); brand.setCompanyName(companyName); brand.setBrandName(brandName); brand.setDescription(description); brand.setOrdered(ordered); //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //SqlSession sqlSession = sqlSessionFactory.openSession(true); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 brandMapper.add(brand); //提交事务 sqlSession.commit(); //5. 释放资源 sqlSession.close(); } @Test public void testAdd2() throws IOException { //接收参数 int status = 1; String companyName = "波导手机"; String brandName = "波导"; String description = "手机中的战斗机"; int ordered = 100; //封装对象 Brand brand = new Brand(); brand.setStatus(status); brand.setCompanyName(companyName); brand.setBrandName(brandName); brand.setDescription(description); brand.setOrdered(ordered); //1. 获取SqlSessionFactory String resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); //2. 获取SqlSession对象 SqlSession sqlSession = sqlSessionFactory.openSession(); //SqlSession sqlSession = sqlSessionFactory.openSession(true); //3. 获取Mapper接口的代理对象 BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class); //4. 执行方法 brandMapper.add(brand); Integer id = brand.getId(); System.out.println(id); //提交事务 sqlSession.commit(); //5. 释放资源 sqlSession.close(); } @Test public void testUpdate() throws IOException { //接收参数 int status = 0; String companyName = "波导手机"; String brandName = "波导"; String description = "波导手机,手机中的战斗机"; int ordered = 200; int id = 6; //

资源文件列表:

mybatis-demo.zip 大约有89个文件
  1. mybatis-demo/
  2. mybatis-demo/.idea/
  3. mybatis-demo/.idea/.gitignore
  4. mybatis-demo/.idea/compiler.xml 649B
  5. mybatis-demo/.idea/dataSources/
  6. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca/
  7. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca/storage_v2/
  8. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca/storage_v2/_src_/
  9. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca/storage_v2/_src_/schema/
  10. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca/storage_v2/_src_/schema/information_schema.FNRwLQ.meta 76B
  11. mybatis-demo/.idea/dataSources/f8d210f4-a914-4aab-bd44-e81ebacf9fca.xml 28.73KB
  12. mybatis-demo/.idea/dataSources.local.xml 1001B
  13. mybatis-demo/.idea/dataSources.xml 542B
  14. mybatis-demo/.idea/jarRepositories.xml 880B
  15. mybatis-demo/.idea/libraries/
  16. mybatis-demo/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml 682B
  17. mybatis-demo/.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml 661B
  18. mybatis-demo/.idea/libraries/Maven__junit_junit_4_13.xml 569B
  19. mybatis-demo/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_46.xml 688B
  20. mybatis-demo/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml 646B
  21. mybatis-demo/.idea/libraries/Maven__org_mybatis_mybatis_3_5_5.xml 614B
  22. mybatis-demo/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_20.xml 627B
  23. mybatis-demo/.idea/misc.xml 390B
  24. mybatis-demo/.idea/modules.xml 271B
  25. mybatis-demo/.idea/mybatisx/
  26. mybatis-demo/.idea/mybatisx/templates.xml 293B
  27. mybatis-demo/.idea/workspace.xml 9.63KB
  28. mybatis-demo/mybatis-demo.iml 1.5KB
  29. mybatis-demo/pom.xml 1.85KB
  30. mybatis-demo/src/
  31. mybatis-demo/src/main/
  32. mybatis-demo/src/main/java/
  33. mybatis-demo/src/main/java/com/
  34. mybatis-demo/src/main/java/com/itheima/
  35. mybatis-demo/src/main/java/com/itheima/mapper/
  36. mybatis-demo/src/main/java/com/itheima/mapper/BrandMapper.java 1.4KB
  37. mybatis-demo/src/main/java/com/itheima/mapper/UserMapper.java 1.95KB
  38. mybatis-demo/src/main/java/com/itheima/MyBatisDemo.java 1.08KB
  39. mybatis-demo/src/main/java/com/itheima/MyBatisDemo2.java 1.29KB
  40. mybatis-demo/src/main/java/com/itheima/pojo/
  41. mybatis-demo/src/main/java/com/itheima/pojo/Brand.java 1.83KB
  42. mybatis-demo/src/main/java/com/itheima/pojo/User.java 1.27KB
  43. mybatis-demo/src/main/resources/
  44. mybatis-demo/src/main/resources/com/
  45. mybatis-demo/src/main/resources/com/itheima/
  46. mybatis-demo/src/main/resources/com/itheima/mapper/
  47. mybatis-demo/src/main/resources/com/itheima/mapper/BrandMapper.xml 6.52KB
  48. mybatis-demo/src/main/resources/com/itheima/mapper/UserMapper.xml 717B
  49. mybatis-demo/src/main/resources/logback.xml 870B
  50. mybatis-demo/src/main/resources/mybatis-config.xml 1.69KB
  51. mybatis-demo/src/test/
  52. mybatis-demo/src/test/java/
  53. mybatis-demo/src/test/java/com/
  54. mybatis-demo/src/test/java/com/itheima/
  55. mybatis-demo/src/test/java/com/itheima/test/
  56. mybatis-demo/src/test/java/com/itheima/test/MyBatisTest.java 10.61KB
  57. mybatis-demo/src/test/java/com/itheima/test/UserMapperTest.java 2.16KB
  58. mybatis-demo/target/
  59. mybatis-demo/target/classes/
  60. mybatis-demo/target/classes/com/
  61. mybatis-demo/target/classes/com/itheima/
  62. mybatis-demo/target/classes/com/itheima/mapper/
  63. mybatis-demo/target/classes/com/itheima/mapper/BrandMapper.class 722B
  64. mybatis-demo/target/classes/com/itheima/mapper/BrandMapper.xml 6.52KB
  65. mybatis-demo/target/classes/com/itheima/mapper/UserMapper.class 663B
  66. mybatis-demo/target/classes/com/itheima/mapper/UserMapper.xml 717B
  67. mybatis-demo/target/classes/com/itheima/MyBatisDemo.class 1.52KB
  68. mybatis-demo/target/classes/com/itheima/MyBatisDemo2.class 1.66KB
  69. mybatis-demo/target/classes/com/itheima/pojo/
  70. mybatis-demo/target/classes/com/itheima/pojo/Brand.class 2.01KB
  71. mybatis-demo/target/classes/com/itheima/pojo/User.class 1.75KB
  72. mybatis-demo/target/classes/logback.xml 870B
  73. mybatis-demo/target/classes/mybatis-config.xml 1.69KB
  74. mybatis-demo/target/generated-sources/
  75. mybatis-demo/target/generated-sources/annotations/
  76. mybatis-demo/target/generated-test-sources/
  77. mybatis-demo/target/generated-test-sources/test-annotations/
  78. mybatis-demo/target/maven-status/
  79. mybatis-demo/target/maven-status/maven-compiler-plugin/
  80. mybatis-demo/target/maven-status/maven-compiler-plugin/compile/
  81. mybatis-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/
  82. mybatis-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst 191B
  83. mybatis-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst 425B
  84. mybatis-demo/target/test-classes/
  85. mybatis-demo/target/test-classes/com/
  86. mybatis-demo/target/test-classes/com/itheima/
  87. mybatis-demo/target/test-classes/com/itheima/test/
  88. mybatis-demo/target/test-classes/com/itheima/test/MyBatisTest.class 5.81KB
  89. mybatis-demo/target/test-classes/com/itheima/test/UserMapperTest.class 2.04KB
0评论
提交 加载更多评论
其他资源 安装python库太慢怎么办&&pip添加国内镜像
1.4、安装python库太慢怎么办&&pip添加国内镜像 其实你只要加个参数 -i,可能就会让下载速度上升 10 倍,比如: pip install django -i https://pypi.tuna.tsinghua.edu.cn/simple 后面的地址可以换成国内的 pip 镜像: 清华(推荐):https://pypi.tuna.tsinghua.edu.cn/simple/ 中科大:https://pypi.mirrors.ustc.edu.cn/simple/ 阿里云:https://mirrors.aliyun.com/pypi/simple/ 豆瓣:http://pypi.douban.com/simple/ 注意:公司限制网络的原因,先看看那个网站能打开再用。
MP-BGP L3VPN Option-A跨域(HCL)
Option A跨域也叫做背靠背跨域,即两个AS的边界路由器ASBR互相作为PE和CE。 ASBR和ASBR通过背靠背的方式互联,ASBR同时也是各自所在AS的PE设备,两个ASBR都把对端看做自己的CE设备,为每一个VPN创建一个VPN实例,通过划分子接口的方式,每个子接口分别绑定一个VPN实例。 ASBR之间不需要任何标签,不用运行LDP,ASBR之间是纯IP转发;ASBR之间可以运行多种路由协议,包括BGP、OSPF、静态等。目前实际网络中, 使用静态路由的配置居多。从转发层来看,针对某个VPN的数据包在ASBR之间是纯IP转发,不带任何标签,就像PE和CE之间转发一样。 优点:简单实用,ASBR之间不需要运行MPLS,跨域的VPN数量较小的情况下优先使用。 缺点:ASBR需要为每个VPN创建一个VPN实例,需要管理和维护所有VPN路由,如果VPN数量众多,导致ASBR的VPNV4的路由表空间过于庞大,资源开销大,如果跨多个域,配置工作量很大,扩展性差。
2024最新去除水印小程序源码文件
2024最新去除水印小程序源码文件
JAVA 基于局域网的聊天室系统(源代码+论文).zip
这是“JAVA 基于局域网的聊天室系统(源代码+论文)”,仅供学习参考,请勿商用。
NET8环境WebAPI使用JWT的Demo
主要阐述在net8环境,webapi中使用JWT的入门级别的Demo,让初学者能够先初步了解什么是JWT,以及如何使用
乐摄图网站导航源码.zip
二次元乐摄图网站导航源码纯html源码分享,只要修改html源码内的链接即可。 源码下载地址:www.00818.cn/1036.html
python3.6版本scrapy框架的Twisted依赖
python3.6版本scrapy框架的Twisted依赖
导师评价+模板材料+学术专利.zip
研究生导师评价,可以作为参考使用。 同时包含复试一些常见的资料:成绩证明,个人陈述,简历,高校logo等