首页下载资源后端黑马MyBatis(配套源码)

ZIP黑马MyBatis(配套源码)

YOLO15946.71KB需要积分:1

资源文件列表:

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

资源介绍:

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; //
100+评论
captcha