├── README.md ├── j-mybatis ├── multiple │ ├── j-dynamic-base │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ └── dynamic │ │ │ │ │ ├── JDynamicBaseApplication.java │ │ │ │ │ ├── controller │ │ │ │ │ ├── ComputerController.java │ │ │ │ │ ├── ExamController.java │ │ │ │ │ ├── PlayerController.java │ │ │ │ │ ├── SoftwareController.java │ │ │ │ │ └── VideogameController.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── ComputerEntity.java │ │ │ │ │ ├── ExamEntity.java │ │ │ │ │ ├── PlayerEntity.java │ │ │ │ │ ├── SoftwareEntity.java │ │ │ │ │ └── VideogameEntity.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── ComputerMapper.java │ │ │ │ │ ├── ExamMapper.java │ │ │ │ │ ├── PlayerMapper.java │ │ │ │ │ ├── SoftwareMapper.java │ │ │ │ │ └── VideogameMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── IComputerService.java │ │ │ │ │ ├── IExamService.java │ │ │ │ │ ├── IPlayerService.java │ │ │ │ │ ├── ISoftwareService.java │ │ │ │ │ ├── IVideogameService.java │ │ │ │ │ └── impl │ │ │ │ │ ├── ComputerServiceImpl.java │ │ │ │ │ ├── ExamServiceImpl.java │ │ │ │ │ ├── PlayerServiceImpl.java │ │ │ │ │ ├── SoftwareServiceImpl.java │ │ │ │ │ └── VideogameServiceImpl.java │ │ │ └── resources │ │ │ │ ├── application.properties │ │ │ │ └── mapper │ │ │ │ ├── ComputerMapper.xml │ │ │ │ ├── ExamMapper.xml │ │ │ │ ├── PlayerMapper.xml │ │ │ │ ├── SoftwareMapper.xml │ │ │ │ └── VideogameMapper.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── dynamic │ │ │ ├── DsTest.java │ │ │ └── SourcesTest.java │ ├── j-multiple-base │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ └── multiple │ │ │ │ │ ├── JMultipleBaseApplication.java │ │ │ │ │ ├── d1 │ │ │ │ │ ├── Dbcp2Config.java │ │ │ │ │ ├── controller │ │ │ │ │ │ ├── ComputerController.java │ │ │ │ │ │ └── SoftwareController.java │ │ │ │ │ ├── entity │ │ │ │ │ │ ├── ComputerEntity.java │ │ │ │ │ │ └── SoftwareEntity.java │ │ │ │ │ ├── mapper │ │ │ │ │ │ ├── ComputerMapper.java │ │ │ │ │ │ └── SoftwareMapper.java │ │ │ │ │ └── service │ │ │ │ │ │ ├── IComputerService.java │ │ │ │ │ │ ├── ISoftwareService.java │ │ │ │ │ │ └── impl │ │ │ │ │ │ ├── ComputerServiceImpl.java │ │ │ │ │ │ └── SoftwareServiceImpl.java │ │ │ │ │ ├── d2 │ │ │ │ │ ├── C3p0Config.java │ │ │ │ │ ├── controller │ │ │ │ │ │ ├── StudentController.java │ │ │ │ │ │ └── StudentcardController.java │ │ │ │ │ ├── entity │ │ │ │ │ │ ├── StudentEntity.java │ │ │ │ │ │ └── StudentcardEntity.java │ │ │ │ │ ├── mapper │ │ │ │ │ │ ├── StudentMapper.java │ │ │ │ │ │ └── StudentcardMapper.java │ │ │ │ │ └── service │ │ │ │ │ │ ├── IStudentService.java │ │ │ │ │ │ ├── IStudentcardService.java │ │ │ │ │ │ └── impl │ │ │ │ │ │ ├── StudentServiceImpl.java │ │ │ │ │ │ └── StudentcardServiceImpl.java │ │ │ │ │ └── d3 │ │ │ │ │ ├── DruidConfig.java │ │ │ │ │ ├── controller │ │ │ │ │ ├── PlayerController.java │ │ │ │ │ └── VideogameController.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── PlayerEntity.java │ │ │ │ │ └── VideogameEntity.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── PlayerMapper.java │ │ │ │ │ └── VideogameMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── IPlayerService.java │ │ │ │ │ ├── IVideogameService.java │ │ │ │ │ └── impl │ │ │ │ │ ├── PlayerServiceImpl.java │ │ │ │ │ └── VideogameServiceImpl.java │ │ │ └── resources │ │ │ │ ├── application.properties │ │ │ │ ├── d1.properties │ │ │ │ ├── d2.properties │ │ │ │ ├── d3.properties │ │ │ │ └── mapper │ │ │ │ ├── d1 │ │ │ │ ├── ComputerMapper.xml │ │ │ │ └── SoftwareMapper.xml │ │ │ │ ├── d2 │ │ │ │ ├── StudentMapper.xml │ │ │ │ └── StudentcardMapper.xml │ │ │ │ └── d3 │ │ │ │ ├── PlayerMapper.xml │ │ │ │ └── VideogameMapper.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── multiple │ │ │ └── data │ │ │ ├── D1Test.java │ │ │ └── SourcesTest.java │ └── pom.xml ├── plus │ ├── j-mybatis-annotation-plus-generator │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ └── Application.java │ │ │ └── resources │ │ │ │ ├── META-INF │ │ │ │ └── mybatis │ │ │ │ │ ├── ComputerMapper.xml │ │ │ │ │ └── SoftwareMapper.xml │ │ │ │ ├── application.properties │ │ │ │ └── templates │ │ │ │ ├── controller.java.btl │ │ │ │ ├── controller.java.ftl │ │ │ │ ├── controller.java.vm │ │ │ │ ├── entity.java.btl │ │ │ │ ├── entity.java.ftl │ │ │ │ ├── entity.java.vm │ │ │ │ ├── entity.kt.btl │ │ │ │ ├── entity.kt.ftl │ │ │ │ ├── entity.kt.vm │ │ │ │ ├── mapper.java.btl │ │ │ │ ├── mapper.java.ftl │ │ │ │ ├── mapper.java.vm │ │ │ │ ├── mapper.xml.btl │ │ │ │ ├── mapper.xml.ftl │ │ │ │ ├── mapper.xml.vm │ │ │ │ ├── service.java.btl │ │ │ │ ├── service.java.ftl │ │ │ │ ├── service.java.vm │ │ │ │ ├── serviceImpl.java.btl │ │ │ │ ├── serviceImpl.java.ftl │ │ │ │ └── serviceImpl.java.vm │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── dao │ │ │ └── generator │ │ │ ├── GeneratorDemo.java │ │ │ └── GeneratorDemo1.java │ ├── j-mybatis-annotation-plus │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ ├── Application.java │ │ │ │ │ ├── MybatisPlusConfig.java │ │ │ │ │ ├── domain │ │ │ │ │ ├── Computer.java │ │ │ │ │ └── Software.java │ │ │ │ │ ├── dto │ │ │ │ │ └── SoftwareDto.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── ComputerMapper.java │ │ │ │ │ └── SoftwareMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── ComputerService.java │ │ │ │ │ ├── SoftwareService.java │ │ │ │ │ └── impl │ │ │ │ │ ├── ComputerServiceImpl.java │ │ │ │ │ └── SoftwareServiceImpl.java │ │ │ └── resources │ │ │ │ ├── META-INF │ │ │ │ └── mybatis │ │ │ │ │ ├── ComputerMapper.xml │ │ │ │ │ └── SoftwareMapper.xml │ │ │ │ ├── application.properties │ │ │ │ └── templates │ │ │ │ ├── controller.java.btl │ │ │ │ ├── controller.java.ftl │ │ │ │ ├── controller.java.vm │ │ │ │ ├── entity.java.btl │ │ │ │ ├── entity.java.ftl │ │ │ │ ├── entity.java.vm │ │ │ │ ├── entity.kt.btl │ │ │ │ ├── entity.kt.ftl │ │ │ │ ├── entity.kt.vm │ │ │ │ ├── mapper.java.btl │ │ │ │ ├── mapper.java.ftl │ │ │ │ ├── mapper.java.vm │ │ │ │ ├── mapper.xml.btl │ │ │ │ ├── mapper.xml.ftl │ │ │ │ ├── mapper.xml.vm │ │ │ │ ├── service.java.btl │ │ │ │ ├── service.java.ftl │ │ │ │ ├── service.java.vm │ │ │ │ ├── serviceImpl.java.btl │ │ │ │ ├── serviceImpl.java.ftl │ │ │ │ └── serviceImpl.java.vm │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── dao │ │ │ └── generator │ │ │ ├── MapperDemo.java │ │ │ ├── add │ │ │ └── ComputerAdd.java │ │ │ └── query │ │ │ └── wrapper │ │ │ ├── ComputerMapperDemo.java │ │ │ └── page │ │ │ └── PageDemo.java │ ├── j-mybatis-annotation │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ ├── Application.java │ │ │ │ │ ├── dao │ │ │ │ │ └── ComputerMapper.java │ │ │ │ │ └── entity │ │ │ │ │ ├── Computer.java │ │ │ │ │ └── Soft_ware.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── dao │ │ │ └── ComputerTest.java │ ├── j-mybatis-cache │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ └── cache │ │ │ │ │ ├── Application.java │ │ │ │ │ ├── ApplicationContextUtils.java │ │ │ │ │ ├── MybatisPlusRedisCache.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── ComputerEntity.java │ │ │ │ │ ├── SoftwareEntity.java │ │ │ │ │ └── dto │ │ │ │ │ │ └── CpDto.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── ComputerMapper.java │ │ │ │ │ └── SoftwareMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── IComputerService.java │ │ │ │ │ ├── ISoftwareService.java │ │ │ │ │ └── impl │ │ │ │ │ ├── ComputerServiceImpl.java │ │ │ │ │ └── SoftwareServiceImpl.java │ │ │ └── resources │ │ │ │ ├── application.properties │ │ │ │ └── xml │ │ │ │ ├── ComputerMapper.xml │ │ │ │ └── SoftwareMapper.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── cache │ │ │ ├── ComputerTest.java │ │ │ ├── RedisTest.java │ │ │ └── SoftwareTest.java │ ├── j-mybatis-redis-cache │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── jachs │ │ │ │ │ └── mybatis │ │ │ │ │ └── cache │ │ │ │ │ ├── Application.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── ComputerEntity.java │ │ │ │ │ ├── SoftwareEntity.java │ │ │ │ │ └── dto │ │ │ │ │ │ └── CpDto.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── ComputerMapper.java │ │ │ │ │ └── SoftwareMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── IComputerService.java │ │ │ │ │ ├── ISoftwareService.java │ │ │ │ │ └── impl │ │ │ │ │ ├── ComputerServiceImpl.java │ │ │ │ │ └── SoftwareServiceImpl.java │ │ │ └── resources │ │ │ │ ├── application.properties │ │ │ │ ├── redis.properties │ │ │ │ └── xml │ │ │ │ ├── ComputerMapper.xml │ │ │ │ └── SoftwareMapper.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── jachs │ │ │ └── mybatis │ │ │ └── cache │ │ │ ├── ComputerTest.java │ │ │ └── SoftwareTest.java │ ├── mybatis-plus-join-demo │ │ ├── README.md │ │ ├── join-demo │ │ │ ├── README.md │ │ │ ├── pom.xml │ │ │ └── src │ │ │ │ ├── main │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── github │ │ │ │ │ │ └── yulichang │ │ │ │ │ │ └── join │ │ │ │ │ │ ├── Application.java │ │ │ │ │ │ ├── config │ │ │ │ │ │ └── MybatisPlusConfig.java │ │ │ │ │ │ ├── dto │ │ │ │ │ │ └── UserDTO.java │ │ │ │ │ │ ├── entity │ │ │ │ │ │ ├── AreaDO.java │ │ │ │ │ │ ├── UserAddressDO.java │ │ │ │ │ │ └── UserDO.java │ │ │ │ │ │ ├── enums │ │ │ │ │ │ └── Sex.java │ │ │ │ │ │ └── mapper │ │ │ │ │ │ ├── AreaMapper.java │ │ │ │ │ │ ├── UserAddressMapper.java │ │ │ │ │ │ └── UserMapper.java │ │ │ │ └── resources │ │ │ │ │ ├── application.yml │ │ │ │ │ └── db │ │ │ │ │ ├── data.sql │ │ │ │ │ └── schema.sql │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── github │ │ │ │ └── yulichang │ │ │ │ └── join │ │ │ │ └── JoinTest.java │ │ └── mapping-demo │ │ │ ├── README.md │ │ │ ├── pom.xml │ │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── github │ │ │ │ │ └── yulichang │ │ │ │ │ └── mapping │ │ │ │ │ ├── Application.java │ │ │ │ │ ├── config │ │ │ │ │ └── MybatisPlusConfig.java │ │ │ │ │ ├── entity │ │ │ │ │ ├── UserAddressDO.java │ │ │ │ │ └── UserDO.java │ │ │ │ │ ├── enums │ │ │ │ │ └── Sex.java │ │ │ │ │ ├── mapper │ │ │ │ │ ├── UserAddressMapper.java │ │ │ │ │ └── UserMapper.java │ │ │ │ │ └── service │ │ │ │ │ ├── UserService.java │ │ │ │ │ └── UserServiceImpl.java │ │ │ └── resources │ │ │ │ ├── application.yml │ │ │ │ └── db │ │ │ │ ├── data.sql │ │ │ │ └── schema.sql │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── yulichang │ │ │ └── mapping │ │ │ └── MappingTest.java │ └── pom.xml └── xml │ ├── j-mybatis-xml-file │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── jachs │ │ │ │ └── mybatis │ │ │ │ ├── Application.java │ │ │ │ ├── dao │ │ │ │ ├── ComputerMapper.java │ │ │ │ └── SoftwareMapper.java │ │ │ │ ├── dto │ │ │ │ └── SoftWareDto.java │ │ │ │ ├── entity │ │ │ │ ├── Computer.java │ │ │ │ └── Software.java │ │ │ │ ├── vo │ │ │ │ └── SoftWareVo.java │ │ │ │ └── xml │ │ │ │ ├── ComputerMapper.xml │ │ │ │ └── SoftwareMapper.xml │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── forEach.png │ │ │ └── readme │ │ └── test │ │ └── java │ │ └── com │ │ └── jachs │ │ └── mybatisc │ │ └── dao │ │ ├── PagehelperDemo.java │ │ ├── complex │ │ ├── ForEachTest.java │ │ └── SoftwareQueryDemo.java │ │ ├── paser │ │ ├── Demo1.java │ │ ├── Demo2.java │ │ └── util │ │ │ ├── MyBatisSql.java │ │ │ └── MyBatisSqlUtils.java │ │ └── simple │ │ ├── ComputerAddDemo.java │ │ ├── SoftwareAddDemo.java │ │ └── query │ │ └── ComputerQueryDemo.java │ ├── j-mybatis-xml-generator │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── jachs │ │ │ ├── mybatis │ │ │ └── MybatisGeneratorApp.java │ │ │ └── springmybatis │ │ │ ├── dao │ │ │ ├── ComputerMapper.java │ │ │ └── SoftwareMapper.java │ │ │ ├── entity │ │ │ ├── Computer.java │ │ │ └── Software.java │ │ │ └── xml │ │ │ ├── ComputerMapper.xml │ │ │ └── SoftwareMapper.xml │ │ └── resources │ │ └── generator.xml │ └── pom.xml ├── spring-mybatis ├── pom.xml ├── spring-mybatis-plus │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── jachs │ │ │ │ └── springmybatis │ │ │ │ ├── entity │ │ │ │ ├── ComputerEntity.java │ │ │ │ └── SoftwareEntity.java │ │ │ │ └── mapper │ │ │ │ ├── ComputerMapper.java │ │ │ │ └── SoftwareMapper.java │ │ └── resources │ │ │ ├── jdbc.properties │ │ │ ├── spring.xml │ │ │ └── xml │ │ │ ├── ComputerMapper.xml │ │ │ └── SoftwareMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── jachs │ │ └── springmybatis │ │ └── ComputerMapperTest.java └── spring-mybatis-xml │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── jachs │ │ │ └── springmybatis │ │ │ ├── dao │ │ │ ├── ComputerMapper.java │ │ │ └── SoftwareMapper.java │ │ │ └── entity │ │ │ ├── Computer.java │ │ │ └── Software.java │ └── resources │ │ ├── jdbc.properties │ │ ├── spring.xml │ │ └── xml │ │ ├── ComputerMapper.xml │ │ └── SoftwareMapper.xml │ └── test │ └── java │ └── com │ └── jachs │ └── springmybatis │ └── ComputerMapperTest.java └── xml ├── pom.xml └── src ├── main └── java │ ├── com │ └── jachs │ │ └── xml │ │ ├── App.java │ │ ├── configer │ │ └── mybatis-config.xml │ │ ├── entity │ │ ├── Computer.java │ │ ├── Exam.java │ │ └── Software.java │ │ ├── mapper │ │ ├── ComputerMapper.java │ │ └── SoftwareMapper.java │ │ └── xml │ │ ├── ComputerMapper.xml │ │ ├── ExamMapper.xml │ │ └── SoftwareMapper.xml │ └── readme └── test └── java └── com └── jachs └── xml ├── Annotation.java ├── Mapper1.java └── Select1.java /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![OSCS Status](https://www.oscs1024.com/platform/badge/ZhanChaoHan/spring-boot-mybatis.git.svg?size=large)](https://www.murphysec.com/dr/ImX7znaHGomibLFW0P) 3 | [![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=ZhanChaoHan)](https://github.com/ZhanChaoHan/github-readme-stats) 4 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | j-multiple 8 | 1.0 9 | 10 | 11 | j-dynamic-base 12 | 13 | 动态数据源注解配置 14 | Demo project for Spring Boot 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | com.baomidou 23 | dynamic-datasource-spring-boot-starter 24 | ${dynamic-datasource-spring-boot-starter.version} 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/JDynamicBaseApplication.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 8 | 9 | @SpringBootApplication(exclude = { 10 | DataSourceAutoConfiguration.class, 11 | DataSourceTransactionManagerAutoConfiguration.class, 12 | HibernateJpaAutoConfiguration.class}) 13 | public class JDynamicBaseApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(JDynamicBaseApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/controller/ComputerController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/computerEntity") 18 | public class ComputerController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/controller/ExamController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/examEntity") 18 | public class ExamController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/controller/PlayerController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/playerEntity") 18 | public class PlayerController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/controller/SoftwareController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/softwareEntity") 18 | public class SoftwareController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/controller/VideogameController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/videogameEntity") 18 | public class VideogameController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/entity/ComputerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("computer") 22 | public class ComputerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("computerId") 27 | private String computerId; 28 | 29 | @TableField("computerName") 30 | private String computerName; 31 | 32 | @TableField("computerPrice") 33 | private Long computerPrice; 34 | 35 | @TableField("madeTime") 36 | private LocalDateTime madeTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/entity/ExamEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-12 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("exam") 21 | public class ExamEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("examId") 26 | private Integer examId; 27 | 28 | @TableField("examName") 29 | private String examName; 30 | 31 | @TableField("score") 32 | private Object score; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/entity/PlayerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("player") 22 | public class PlayerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "pID", type = IdType.AUTO) 27 | private Long pID; 28 | 29 | @TableField("level") 30 | private Integer level; 31 | 32 | @TableField("playerUserName") 33 | private String playerUserName; 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/entity/SoftwareEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-12 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("software") 21 | public class SoftwareEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("softWareId") 26 | private String softWareId; 27 | 28 | @TableField("softWareName") 29 | private String softWareName; 30 | 31 | @TableField("cFKId") 32 | private String cFKId; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/entity/VideogameEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("videogame") 22 | public class VideogameEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "gameId", type = IdType.AUTO) 27 | private Long gameId; 28 | 29 | @TableField("gameName") 30 | private String gameName; 31 | 32 | @TableField("gamePrice") 33 | private Integer gamePrice; 34 | 35 | @TableField("pID") 36 | private Long pID; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.mapper; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ComputerEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.dynamic.datasource.annotation.DS; 8 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 没有@DS 默认数据源
15 | * @DS("dsName") dsName可以为组名也可以为具体某个库的名称
16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @DS("d1") 20 | @Mapper 21 | public interface ComputerMapper extends BaseMapper { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/mapper/ExamMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.mapper; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ExamEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface ExamMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/mapper/PlayerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.mapper; 2 | 3 | import com.jachs.mybatis.dynamic.entity.PlayerEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface PlayerMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.mapper; 2 | 3 | import com.jachs.mybatis.dynamic.entity.SoftwareEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface SoftwareMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/mapper/VideogameMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.mapper; 2 | 3 | import com.jachs.mybatis.dynamic.entity.VideogameEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface VideogameMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/IComputerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ComputerEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IComputerService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/IExamService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ExamEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IExamService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/IPlayerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service; 2 | 3 | import com.jachs.mybatis.dynamic.entity.PlayerEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IPlayerService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/ISoftwareService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service; 2 | 3 | import com.jachs.mybatis.dynamic.entity.SoftwareEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface ISoftwareService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/IVideogameService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service; 2 | 3 | import com.jachs.mybatis.dynamic.entity.VideogameEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IVideogameService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service.impl; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ComputerEntity; 4 | import com.jachs.mybatis.dynamic.mapper.ComputerMapper; 5 | import com.jachs.mybatis.dynamic.service.IComputerService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class ComputerServiceImpl extends ServiceImpl implements IComputerService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/impl/ExamServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service.impl; 2 | 3 | import com.jachs.mybatis.dynamic.entity.ExamEntity; 4 | import com.jachs.mybatis.dynamic.mapper.ExamMapper; 5 | import com.jachs.mybatis.dynamic.service.IExamService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class ExamServiceImpl extends ServiceImpl implements IExamService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/impl/PlayerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service.impl; 2 | 3 | import com.jachs.mybatis.dynamic.entity.PlayerEntity; 4 | import com.jachs.mybatis.dynamic.mapper.PlayerMapper; 5 | import com.jachs.mybatis.dynamic.service.IPlayerService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class PlayerServiceImpl extends ServiceImpl implements IPlayerService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/impl/SoftwareServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service.impl; 2 | 3 | import com.jachs.mybatis.dynamic.entity.SoftwareEntity; 4 | import com.jachs.mybatis.dynamic.mapper.SoftwareMapper; 5 | import com.jachs.mybatis.dynamic.service.ISoftwareService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class SoftwareServiceImpl extends ServiceImpl implements ISoftwareService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/java/com/jachs/mybatis/dynamic/service/impl/VideogameServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic.service.impl; 2 | 3 | import com.jachs.mybatis.dynamic.entity.VideogameEntity; 4 | import com.jachs.mybatis.dynamic.mapper.VideogameMapper; 5 | import com.jachs.mybatis.dynamic.service.IVideogameService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class VideogameServiceImpl extends ServiceImpl implements IVideogameService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.dynamic.primary=master 2 | spring.datasource.dynamic.strict=false 3 | 4 | spring.datasource.dynamic.datasource.master.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 5 | spring.datasource.dynamic.datasource.master.username=root 6 | spring.datasource.dynamic.datasource.master.password=123456 7 | spring.datasource.dynamic.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver 8 | 9 | spring.datasource.dynamic.datasource.d1.url=jdbc:mysql://localhost:3306/t1?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 10 | spring.datasource.dynamic.datasource.d1.username=root 11 | spring.datasource.dynamic.datasource.d1.password=123456 12 | spring.datasource.dynamic.datasource.d1.driver-class-name=com.mysql.cj.jdbc.Driver 13 | 14 | spring.datasource.dynamic.datasource.d2.url=jdbc:mysql://localhost:3306/t2?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 15 | spring.datasource.dynamic.datasource.d2.username=root 16 | spring.datasource.dynamic.datasource.d2.password=123456 17 | spring.datasource.dynamic.datasource.d2.driver-class-name=com.mysql.cj.jdbc.Driver 18 | 19 | mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/mapper/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/mapper/ExamMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/mapper/PlayerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/mapper/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/main/resources/mapper/VideogameMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-dynamic-base/src/test/java/com/jachs/mybatis/dynamic/DsTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dynamic; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 10 | import com.jachs.mybatis.dynamic.entity.ComputerEntity; 11 | import com.jachs.mybatis.dynamic.mapper.ComputerMapper; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest 19 | public class DsTest { 20 | @Autowired 21 | private ComputerMapper computerMapper; 22 | 23 | @Test 24 | public void test1() { 25 | computerMapper.selectList(null).forEach(cp->{ 26 | System.out.println(cp.toString()); 27 | }); 28 | } 29 | 30 | @Test 31 | public void test2() { 32 | ComputerEntity ce=new ComputerEntity(); 33 | 34 | ce.setComputerId("ckck"); 35 | ce.setComputerName("测试"); 36 | ce.setComputerPrice(18293L); 37 | ce.setMadeTime(LocalDateTime.now()); 38 | 39 | computerMapper.insert(ce); 40 | } 41 | /*** 42 | * 先添加一条测试数据,然后修改mapper的Ds测试这条数据切换ds后是否能查 43 | */ 44 | @Test 45 | public void test3() { 46 | LambdaQueryWrapperwrapper=new LambdaQueryWrapper(); 47 | 48 | wrapper.eq(ComputerEntity::getComputerId, "ckck"); 49 | 50 | ComputerEntity cp=computerMapper.selectOne(wrapper); 51 | 52 | System.out.println(cp.toString()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | j-multiple 8 | 1.0 9 | 10 | 11 | j-multiple-base 12 | 13 | 多数据源注解配置 14 | Demo project for Spring Boot 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/JMultipleBaseApplication.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 8 | 9 | @SpringBootApplication(exclude = { 10 | DataSourceAutoConfiguration.class, 11 | DataSourceTransactionManagerAutoConfiguration.class, 12 | HibernateJpaAutoConfiguration.class}) 13 | public class JMultipleBaseApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(JMultipleBaseApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/controller/ComputerController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-11 15 | */ 16 | @Controller 17 | @RequestMapping("/computerEntity") 18 | public class ComputerController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/controller/SoftwareController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-11 15 | */ 16 | @Controller 17 | @RequestMapping("/softwareEntity") 18 | public class SoftwareController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/entity/ComputerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-11 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("computer") 22 | public class ComputerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("computerId") 27 | private String computerId; 28 | 29 | @TableField("computerName") 30 | private String computerName; 31 | 32 | @TableField("computerPrice") 33 | private Long computerPrice; 34 | 35 | @TableField("madeTime") 36 | private LocalDateTime madeTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/entity/SoftwareEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-11 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("software") 21 | public class SoftwareEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("softWareId") 26 | private String softWareId; 27 | 28 | @TableField("softWareName") 29 | private String softWareName; 30 | 31 | @TableField("cFKId") 32 | private String cFKId; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.ComputerEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-11 16 | */ 17 | @Mapper 18 | public interface ComputerMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.SoftwareEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-11 16 | */ 17 | @Mapper 18 | public interface SoftwareMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/service/IComputerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.service; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.ComputerEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-11 13 | */ 14 | public interface IComputerService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/service/ISoftwareService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.service; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.SoftwareEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-11 13 | */ 14 | public interface ISoftwareService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.ComputerEntity; 4 | import com.jachs.mybatis.multiple.d1.mapper.ComputerMapper; 5 | import com.jachs.mybatis.multiple.d1.service.IComputerService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-11 16 | */ 17 | @Service 18 | public class ComputerServiceImpl extends ServiceImpl implements IComputerService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d1/service/impl/SoftwareServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d1.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d1.entity.SoftwareEntity; 4 | import com.jachs.mybatis.multiple.d1.mapper.SoftwareMapper; 5 | import com.jachs.mybatis.multiple.d1.service.ISoftwareService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-11 16 | */ 17 | @Service 18 | public class SoftwareServiceImpl extends ServiceImpl implements ISoftwareService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/controller/StudentController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/studentEntity") 18 | public class StudentController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/controller/StudentcardController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/studentcardEntity") 18 | public class StudentcardController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/entity/StudentEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("student") 22 | public class StudentEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("studentId") 27 | private String studentId; 28 | 29 | @TableField("dateOfBirth") 30 | private LocalDateTime dateOfBirth; 31 | 32 | @TableField("studentAge") 33 | private Integer studentAge; 34 | 35 | @TableField("studentName") 36 | private String studentName; 37 | 38 | @TableField("sCarId") 39 | private String sCarId; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/entity/StudentcardEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-12 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("studentcard") 21 | public class StudentcardEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("cardId") 26 | private String cardId; 27 | 28 | @TableField("cardMonery") 29 | private Long cardMonery; 30 | 31 | @TableField("cardName") 32 | private String cardName; 33 | 34 | @TableField("cardType") 35 | private String cardType; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/mapper/StudentMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface StudentMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/mapper/StudentcardMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentcardEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface StudentcardMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/service/IStudentService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.service; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IStudentService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/service/IStudentcardService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.service; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentcardEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IStudentcardService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/service/impl/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentEntity; 4 | import com.jachs.mybatis.multiple.d2.mapper.StudentMapper; 5 | import com.jachs.mybatis.multiple.d2.service.IStudentService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class StudentServiceImpl extends ServiceImpl implements IStudentService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d2/service/impl/StudentcardServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d2.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d2.entity.StudentcardEntity; 4 | import com.jachs.mybatis.multiple.d2.mapper.StudentcardMapper; 5 | import com.jachs.mybatis.multiple.d2.service.IStudentcardService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class StudentcardServiceImpl extends ServiceImpl implements IStudentcardService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/controller/PlayerController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/playerEntity") 18 | public class PlayerController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/controller/VideogameController.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author zhanchaohan 14 | * @since 2022-07-12 15 | */ 16 | @Controller 17 | @RequestMapping("/videogameEntity") 18 | public class VideogameController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/entity/PlayerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("player") 22 | public class PlayerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "pID", type = IdType.AUTO) 27 | private Long pID; 28 | 29 | @TableField("level") 30 | private Integer level; 31 | 32 | @TableField("playerUserName") 33 | private String playerUserName; 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/entity/VideogameEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-12 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("videogame") 22 | public class VideogameEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "gameId", type = IdType.AUTO) 27 | private Long gameId; 28 | 29 | @TableField("gameName") 30 | private String gameName; 31 | 32 | @TableField("gamePrice") 33 | private Integer gamePrice; 34 | 35 | @TableField("pID") 36 | private Long pID; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/mapper/PlayerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.PlayerEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface PlayerMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/mapper/VideogameMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.mapper; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.VideogameEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Mapper 18 | public interface VideogameMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/service/IPlayerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.service; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.PlayerEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IPlayerService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/service/IVideogameService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.service; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.VideogameEntity; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-07-12 13 | */ 14 | public interface IVideogameService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/service/impl/PlayerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.PlayerEntity; 4 | import com.jachs.mybatis.multiple.d3.mapper.PlayerMapper; 5 | import com.jachs.mybatis.multiple.d3.service.IPlayerService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class PlayerServiceImpl extends ServiceImpl implements IPlayerService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/java/com/jachs/mybatis/multiple/d3/service/impl/VideogameServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.d3.service.impl; 2 | 3 | import com.jachs.mybatis.multiple.d3.entity.VideogameEntity; 4 | import com.jachs.mybatis.multiple.d3.mapper.VideogameMapper; 5 | import com.jachs.mybatis.multiple.d3.service.IVideogameService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-12 16 | */ 17 | @Service 18 | public class VideogameServiceImpl extends ServiceImpl implements IVideogameService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #mybatis-plus.mapper-locations=classpath:mapper/*.xml 2 | #mybatis.mapper-locations=classpath:mapper/*.xml 3 | 4 | #logging.level.com.example.demo.mapper=debug 5 | mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/d1.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.datasource.dbcp2.driver=com.mysql.cj.jdbc.Driver 3 | spring.datasource.dbcp2.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 4 | spring.datasource.dbcp2.user=root 5 | spring.datasource.dbcp2.password=123456 6 | spring.datasource.dbcp2.initialSize=10 7 | spring.datasource.dbcp2.maxTotal=300 8 | spring.datasource.dbcp2.maxIdle=20 9 | spring.datasource.dbcp2.minIdle=10 10 | spring.datasource.dbcp2.maxWaitMillis=10000 11 | spring.datasource.dbcp2.defaultAutoCommit=true 12 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/d2.properties: -------------------------------------------------------------------------------- 1 | ####################C3P0数据源配置############################# 2 | spring.datasource.c3p0.jdbcUrl =jdbc:mysql://localhost:3306/t1?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 3 | spring.datasource.c3p0.driverClass=com.mysql.cj.jdbc.Driver 4 | spring.datasource.c3p0.user=root 5 | spring.datasource.c3p0.password=123456 6 | ##初始化连接数 7 | spring.datasource.c3p0.initialPoolSize=5 8 | ##连接池中保留的最小连接数 9 | spring.datasource.c3p0.minPoolSize=3 10 | ##连接池中保留的最大连接数 11 | spring.datasource.c3p0.maxPoolSize=10 12 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/d3.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.druid.mysql.type=com.alibaba.druid.pool.DruidDataSource 2 | spring.datasource.druid.mysql.driverClassName=com.mysql.jdbc.Driver 3 | spring.datasource.druid.mysql.url=jdbc:mysql://localhost:3306/t2?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 4 | spring.datasource.druid.mysql.username=root 5 | spring.datasource.druid.mysql.password=123456 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d1/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d1/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d2/StudentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d2/StudentcardMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d3/PlayerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/main/resources/mapper/d3/VideogameMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /j-mybatis/multiple/j-multiple-base/src/test/java/com/jachs/mybatis/multiple/data/D1Test.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.multiple.data; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.context.annotation.ComponentScan; 8 | 9 | import com.jachs.mybatis.multiple.d1.mapper.ComputerMapper; 10 | import com.jachs.mybatis.multiple.d2.mapper.StudentcardMapper; 11 | import com.jachs.mybatis.multiple.d3.mapper.PlayerMapper; 12 | 13 | /** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest 19 | 20 | //@ComponentScan( 21 | // basePackages = "com.jachs.mybatis.multiple.*", 22 | // excludeFilters = { 23 | // @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.jachs.mybatis.multiple.d2\\..*"), 24 | // @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.jachs.mybatis.multiple.d3\\..*") 25 | // }) 26 | @ComponentScan("com.jachs.mybatis.multiple.*") 27 | //@MapperScan("com.jachs.mybatis.multiple.*") 28 | public class D1Test { 29 | @Autowired 30 | private ComputerMapper computerMapper; 31 | @Autowired 32 | private StudentcardMapper studentcardMapper; 33 | @Autowired 34 | private PlayerMapper playerMapper; 35 | 36 | 37 | @Test 38 | public void test1() { 39 | computerMapper.selectList(null).forEach(cp->{ 40 | System.out.println(cp.toString()); 41 | }); 42 | } 43 | 44 | @Test 45 | public void test2() { 46 | studentcardMapper.selectList(null).forEach(sm->{ 47 | System.out.println(sm.toString()); 48 | }); 49 | } 50 | @Test 51 | public void test3() { 52 | playerMapper.selectList(null).forEach(em->{ 53 | System.out.println(em.toString()); 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jachs 8 | j-mybatis-plus 9 | 1.0 10 | 11 | 12 | j-mybatis-annotation-plus-generator 13 | plus代码生成 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | com.baomidou 23 | mybatis-plus-boot-starter 24 | ${mybatis.plus.version} 25 | 26 | 27 | 28 | com.baomidou 29 | mybatis-plus-generator 30 | ${mybatis-plus-generator.version} 31 | 32 | 33 | 34 | org.apache.velocity 35 | velocity-engine-core 36 | 2.2 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/java/com/jachs/mybatis/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.web.servlet.ServletComponentScan; 7 | 8 | @SpringBootApplication 9 | @MapperScan("com.jachs.mybatis.mapper") 10 | @ServletComponentScan("com.jachs.mybatis.service") 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/META-INF/mybatis/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | computerId, computerName, computerPrice, madeTime 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/META-INF/mybatis/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | softWareId, softWareName, cFKId 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | logging.level.com.example.demo.mapper=debug 7 | mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 8 | #关闭驼峰命名 9 | mybatis-plus.configuration.map-underscore-to-camel-case=false 10 | 11 | mybatis-plus.mapper-locations=classpath:/META-INF/mybatis/*.xml 12 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/controller.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | <% if(restControllerStyle){ %> 7 | import org.springframework.web.bind.annotation.RestController; 8 | <% }else{ %> 9 | import org.springframework.stereotype.Controller; 10 | <% } %> 11 | <% if(isNotEmpty(superControllerClassPackage)){ %> 12 | import ${superControllerClassPackage}; 13 | <% } %> 14 | 15 | /** 16 | *

17 | * ${table.comment!} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | <% if(restControllerStyle){ %> 24 | @RestController 25 | <% }else{ %> 26 | @Controller 27 | <% } %> 28 | @RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>") 29 | <% if(kotlin){ %> 30 | class ${table.controllerName}<% if(isNotEmpty(superControllerClass)){ %> : ${superControllerClass}()<% } %> 31 | <% }else{ %> 32 | <% if(isNotEmpty(superControllerClass)){ %> 33 | public class ${table.controllerName} extends ${superControllerClass} { 34 | <% }else{ %> 35 | public class ${table.controllerName} { 36 | <% } %> 37 | 38 | } 39 | <% } %> 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/controller.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | <#if restControllerStyle> 7 | import org.springframework.web.bind.annotation.RestController; 8 | <#else> 9 | import org.springframework.stereotype.Controller; 10 | 11 | <#if superControllerClassPackage??> 12 | import ${superControllerClassPackage}; 13 | 14 | 15 | /** 16 | *

17 | * ${table.comment!} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | <#if restControllerStyle> 24 | @RestController 25 | <#else> 26 | @Controller 27 | 28 | @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}") 29 | <#if kotlin> 30 | class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}() 31 | <#else> 32 | <#if superControllerClass??> 33 | public class ${table.controllerName} extends ${superControllerClass} { 34 | <#else> 35 | public class ${table.controllerName} { 36 | 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/controller.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | #if(${restControllerStyle}) 7 | import org.springframework.web.bind.annotation.RestController; 8 | #else 9 | import org.springframework.stereotype.Controller; 10 | #end 11 | #if(${superControllerClassPackage}) 12 | import ${superControllerClassPackage}; 13 | #end 14 | 15 | /** 16 | *

17 | * $!{table.comment} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | #if(${restControllerStyle}) 24 | @RestController 25 | #else 26 | @Controller 27 | #end 28 | @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") 29 | #if(${kotlin}) 30 | class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end 31 | 32 | #else 33 | #if(${superControllerClass}) 34 | public class ${table.controllerName} extends ${superControllerClass} { 35 | #else 36 | public class ${table.controllerName} { 37 | #end 38 | 39 | } 40 | 41 | #end -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <% if(kotlin){ %> 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | <% }else{ %> 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | <% } %> 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <#if kotlin> 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | <#else> 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * $!{table.comment} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | #if(${kotlin}) 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | #else 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | #end 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.xml.btl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <% if(enableCache){ %> 6 | 7 | 8 | 9 | <% } %> 10 | <% if(baseResultMap){ %> 11 | 12 | 13 | <% for(field in table.fields){ %> 14 | <% /** 生成主键排在第一位 **/ %> 15 | <% if(field.keyFlag){ %> 16 | 17 | <% } %> 18 | <% } %> 19 | <% for(field in table.commonFields){ %> 20 | <% /** 生成公共字段 **/ %> 21 | 22 | <% } %> 23 | <% for(field in table.fields){ %> 24 | <% /** 生成普通字段 **/ %> 25 | <% if(!field.keyFlag){ %> 26 | 27 | <% } %> 28 | <% } %> 29 | 30 | <% } %> 31 | <% if(baseColumnList){ %> 32 | 33 | 34 | <% for(field in table.commonFields){ %> 35 | ${field.columnName}, 36 | <% } %> 37 | ${table.fieldNames} 38 | 39 | 40 | <% } %> 41 | 42 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if baseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if baseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.columnName}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/mapper.xml.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #if(${enableCache}) 6 | 7 | 8 | 9 | #end 10 | #if(${baseResultMap}) 11 | 12 | 13 | #foreach($field in ${table.fields}) 14 | #if(${field.keyFlag})##生成主键排在第一位 15 | 16 | #end 17 | #end 18 | #foreach($field in ${table.commonFields})##生成公共字段 19 | 20 | #end 21 | #foreach($field in ${table.fields}) 22 | #if(!${field.keyFlag})##生成普通字段 23 | 24 | #end 25 | #end 26 | 27 | 28 | #end 29 | #if(${baseColumnList}) 30 | 31 | 32 | #foreach($field in ${table.commonFields}) 33 | ${field.columnName}, 34 | #end 35 | ${table.fieldNames} 36 | 37 | 38 | #end 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/service.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <% if(kotlin){ %> 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | <% }else{ %> 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | <% } %> 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/service.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <#if kotlin> 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | <#else> 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/service.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * $!{table.comment} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | #if(${kotlin}) 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | #else 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | #end 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/serviceImpl.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * ${table.comment!} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | <% if(kotlin){ %> 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | <% }else{ %> 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | <% } %> 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/serviceImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * ${table.comment!} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | <#if kotlin> 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | <#else> 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus-generator/src/main/resources/templates/serviceImpl.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * $!{table.comment} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | #if(${kotlin}) 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | #else 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | #end 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jachs 8 | j-mybatis-plus 9 | 1.0 10 | 11 | 12 | j-mybatis-annotation-plus 13 | plus使用 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | com.baomidou 23 | mybatis-plus-boot-starter 24 | ${mybatis.plus.version} 25 | 26 | 27 | com.github.yulichang 28 | mybatis-plus-join 29 | ${mybatis.plus.join.version} 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.web.servlet.ServletComponentScan; 7 | 8 | @SpringBootApplication 9 | @MapperScan("com.jachs.mybatis.mapper") 10 | @ServletComponentScan("com.jachs.mybatis.service") 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 7 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 8 | 9 | /*** 10 | * 11 | * @author zhanchaohan 12 | * 13 | */ 14 | @Configuration 15 | public class MybatisPlusConfig { 16 | /*** 17 | * 配置分页 18 | * @return 19 | */ 20 | @Bean 21 | public MybatisPlusInterceptor mybatisPlusInterceptor(){ 22 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 23 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 24 | return interceptor; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/domain/Computer.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.util.Date; 11 | import com.baomidou.mybatisplus.annotation.TableId; 12 | import com.baomidou.mybatisplus.annotation.TableField; 13 | import java.io.Serializable; 14 | 15 | /** 16 | * 17 | * @author zhanchaohan 18 | */ 19 | @Data 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public class Computer extends Model { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "computerId") 27 | private String computerid; 28 | 29 | @TableField("computerName") 30 | private String computername; 31 | 32 | @TableField("computerPrice") 33 | private Long computerprice; 34 | 35 | @TableField("madeTime") 36 | private Date madetime; 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "Computer{" + 42 | "computerid=" + computerid + 43 | ", computername=" + computername + 44 | ", computerprice=" + computerprice + 45 | ", madetime=" + madetime + 46 | "}"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/domain/Software.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import com.baomidou.mybatisplus.annotation.TableId; 11 | import com.baomidou.mybatisplus.annotation.TableField; 12 | import java.io.Serializable; 13 | import java.util.Date; 14 | 15 | /** 16 | * 17 | * @author zhanchaohan 18 | */ 19 | @Data 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public class Software extends Model { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId(value = "softWareId", type = IdType.AUTO) 27 | private String softwareid; 28 | 29 | @TableField("softWareName") 30 | private String softwarename; 31 | 32 | @TableField("cFKId") 33 | private String cfkid; 34 | 35 | 36 | @Override 37 | public String toString() { 38 | return "Software{" + 39 | "softwareid=" + softwareid + 40 | ", softwarename=" + softwarename + 41 | ", cfkid=" + cfkid + 42 | "}"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/dto/SoftwareDto.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dto; 2 | 3 | /*** 4 | * 5 | * @author zhanchaohan 6 | * 7 | */ 8 | 9 | public class SoftwareDto { 10 | private String cfId; 11 | } 12 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.mapper; 2 | 3 | import com.jachs.mybatis.domain.Computer; 4 | 5 | import java.util.List; 6 | 7 | import org.apache.ibatis.annotations.Param; 8 | import org.apache.ibatis.annotations.Select; 9 | 10 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 11 | import com.github.yulichang.base.MPJBaseMapper; 12 | 13 | /** 14 | *

15 | * Mapper 接口 16 | *

17 | * 18 | * @author zhanchaohan 19 | * @since 2022-04-06 20 | */ 21 | public interface ComputerMapper extends MPJBaseMapper { 22 | 23 | List selectPageByXml(@Param("price") Long price); 24 | 25 | List selectPageByXml(@Param("price") Long price, Page page); 26 | 27 | @Select(value = "SELECT computerId,computerName,computerPrice,madeTime FROM computer\r\n" 28 | + " WHERE (computerPrice >= #{price}) ORDER BY computerPrice ASC") 29 | List selectPageByAnn(@Param("price") Long price); 30 | 31 | @Select(value = "SELECT computerId,computerName,computerPrice,madeTime FROM computer\r\n" 32 | + " WHERE (computerPrice >= #{price}) ORDER BY computerPrice ASC") 33 | List selectPageByAnn(@Param("price") Long price, Page page); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.mapper; 2 | 3 | import com.jachs.mybatis.domain.Software; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-04-06 13 | */ 14 | public interface SoftwareMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/service/ComputerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.service; 2 | 3 | import com.jachs.mybatis.domain.Computer; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-04-06 13 | */ 14 | public interface ComputerService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/service/SoftwareService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.service; 2 | 3 | import com.jachs.mybatis.domain.Software; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author zhanchaohan 12 | * @since 2022-04-06 13 | */ 14 | public interface SoftwareService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.service.impl; 2 | 3 | import com.jachs.mybatis.domain.Computer; 4 | import com.jachs.mybatis.mapper.ComputerMapper; 5 | import com.jachs.mybatis.service.ComputerService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-04-06 16 | */ 17 | @Service 18 | public class ComputerServiceImpl extends ServiceImpl implements ComputerService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/java/com/jachs/mybatis/service/impl/SoftwareServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.service.impl; 2 | 3 | import com.jachs.mybatis.domain.Software; 4 | import com.jachs.mybatis.mapper.SoftwareMapper; 5 | import com.jachs.mybatis.service.SoftwareService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-04-06 16 | */ 17 | @Service 18 | public class SoftwareServiceImpl extends ServiceImpl implements SoftwareService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/META-INF/mybatis/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | computerId, computerName, computerPrice, madeTime 16 | 17 | 18 | 22 | 23 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/META-INF/mybatis/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | softWareId, softWareName, cFKId 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | logging.level.com.example.demo.mapper=debug 7 | mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 8 | #关闭驼峰命名 9 | mybatis-plus.configuration.map-underscore-to-camel-case=false 10 | 11 | mybatis-plus.mapper-locations=classpath:/META-INF/mybatis/*.xml 12 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/controller.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | <% if(restControllerStyle){ %> 7 | import org.springframework.web.bind.annotation.RestController; 8 | <% }else{ %> 9 | import org.springframework.stereotype.Controller; 10 | <% } %> 11 | <% if(isNotEmpty(superControllerClassPackage)){ %> 12 | import ${superControllerClassPackage}; 13 | <% } %> 14 | 15 | /** 16 | *

17 | * ${table.comment!} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | <% if(restControllerStyle){ %> 24 | @RestController 25 | <% }else{ %> 26 | @Controller 27 | <% } %> 28 | @RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>") 29 | <% if(kotlin){ %> 30 | class ${table.controllerName}<% if(isNotEmpty(superControllerClass)){ %> : ${superControllerClass}()<% } %> 31 | <% }else{ %> 32 | <% if(isNotEmpty(superControllerClass)){ %> 33 | public class ${table.controllerName} extends ${superControllerClass} { 34 | <% }else{ %> 35 | public class ${table.controllerName} { 36 | <% } %> 37 | 38 | } 39 | <% } %> 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/controller.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | <#if restControllerStyle> 7 | import org.springframework.web.bind.annotation.RestController; 8 | <#else> 9 | import org.springframework.stereotype.Controller; 10 | 11 | <#if superControllerClassPackage??> 12 | import ${superControllerClassPackage}; 13 | 14 | 15 | /** 16 | *

17 | * ${table.comment!} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | <#if restControllerStyle> 24 | @RestController 25 | <#else> 26 | @Controller 27 | 28 | @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}") 29 | <#if kotlin> 30 | class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}() 31 | <#else> 32 | <#if superControllerClass??> 33 | public class ${table.controllerName} extends ${superControllerClass} { 34 | <#else> 35 | public class ${table.controllerName} { 36 | 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/controller.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | #if(${restControllerStyle}) 7 | import org.springframework.web.bind.annotation.RestController; 8 | #else 9 | import org.springframework.stereotype.Controller; 10 | #end 11 | #if(${superControllerClassPackage}) 12 | import ${superControllerClassPackage}; 13 | #end 14 | 15 | /** 16 | *

17 | * $!{table.comment} 前端控制器 18 | *

19 | * 20 | * @author ${author} 21 | * @since ${date} 22 | */ 23 | #if(${restControllerStyle}) 24 | @RestController 25 | #else 26 | @Controller 27 | #end 28 | @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") 29 | #if(${kotlin}) 30 | class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end 31 | 32 | #else 33 | #if(${superControllerClass}) 34 | public class ${table.controllerName} extends ${superControllerClass} { 35 | #else 36 | public class ${table.controllerName} { 37 | #end 38 | 39 | } 40 | 41 | #end -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <% if(kotlin){ %> 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | <% }else{ %> 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | <% } %> 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <#if kotlin> 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | <#else> 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superMapperClassPackage}; 5 | 6 | /** 7 | *

8 | * $!{table.comment} Mapper 接口 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | #if(${kotlin}) 15 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 16 | #else 17 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 18 | 19 | } 20 | #end 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.xml.btl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <% if(enableCache){ %> 6 | 7 | 8 | 9 | <% } %> 10 | <% if(baseResultMap){ %> 11 | 12 | 13 | <% for(field in table.fields){ %> 14 | <% /** 生成主键排在第一位 **/ %> 15 | <% if(field.keyFlag){ %> 16 | 17 | <% } %> 18 | <% } %> 19 | <% for(field in table.commonFields){ %> 20 | <% /** 生成公共字段 **/ %> 21 | 22 | <% } %> 23 | <% for(field in table.fields){ %> 24 | <% /** 生成普通字段 **/ %> 25 | <% if(!field.keyFlag){ %> 26 | 27 | <% } %> 28 | <% } %> 29 | 30 | <% } %> 31 | <% if(baseColumnList){ %> 32 | 33 | 34 | <% for(field in table.commonFields){ %> 35 | ${field.columnName}, 36 | <% } %> 37 | ${table.fieldNames} 38 | 39 | 40 | <% } %> 41 | 42 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if baseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if baseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.columnName}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/mapper.xml.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #if(${enableCache}) 6 | 7 | 8 | 9 | #end 10 | #if(${baseResultMap}) 11 | 12 | 13 | #foreach($field in ${table.fields}) 14 | #if(${field.keyFlag})##生成主键排在第一位 15 | 16 | #end 17 | #end 18 | #foreach($field in ${table.commonFields})##生成公共字段 19 | 20 | #end 21 | #foreach($field in ${table.fields}) 22 | #if(!${field.keyFlag})##生成普通字段 23 | 24 | #end 25 | #end 26 | 27 | 28 | #end 29 | #if(${baseColumnList}) 30 | 31 | 32 | #foreach($field in ${table.commonFields}) 33 | ${field.columnName}, 34 | #end 35 | ${table.fieldNames} 36 | 37 | 38 | #end 39 | 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/service.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <% if(kotlin){ %> 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | <% }else{ %> 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | <% } %> 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/service.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <#if kotlin> 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | <#else> 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/service.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${superServiceClassPackage}; 5 | 6 | /** 7 | *

8 | * $!{table.comment} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | #if(${kotlin}) 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | #else 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | #end 21 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/serviceImpl.java.btl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * ${table.comment!} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | <% if(kotlin){ %> 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | <% }else{ %> 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | <% } %> 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/serviceImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * ${table.comment!} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | <#if kotlin> 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | <#else> 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/main/resources/templates/serviceImpl.java.vm: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${package.Service}.${table.serviceName}; 6 | import ${superServiceImplClassPackage}; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * $!{table.comment} 服务实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | #if(${kotlin}) 19 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 20 | 21 | } 22 | #else 23 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 24 | 25 | } 26 | #end 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/test/java/com/jachs/mybatis/dao/generator/MapperDemo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao.generator; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.jachs.mybatis.Application; 10 | import com.jachs.mybatis.domain.Computer; 11 | import com.jachs.mybatis.service.ComputerService; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest(classes = Application.class) 19 | public class MapperDemo { 20 | @Autowired 21 | private ComputerService computerService; 22 | 23 | @Test 24 | public void test1() { 25 | List cmList=computerService.list(null); 26 | 27 | cmList.forEach(cp->{ 28 | System.out.println(cp.toString()); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation-plus/src/test/java/com/jachs/mybatis/dao/generator/add/ComputerAdd.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao.generator.add; 2 | 3 | import java.util.Date; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.jachs.mybatis.Application; 10 | import com.jachs.mybatis.domain.Computer; 11 | import com.jachs.mybatis.service.ComputerService; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest(classes = Application.class) 19 | public class ComputerAdd { 20 | @Autowired 21 | private ComputerService computerService; 22 | 23 | @Test 24 | public void ts1() { 25 | Computer cp=new Computer(); 26 | cp.setComputerid("cp_001"); 27 | cp.setComputername("测试主机"); 28 | cp.setComputerprice(198292L); 29 | cp.setMadetime(new Date()); 30 | 31 | computerService.save(cp); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jachs 8 | j-mybatis-plus 9 | 1.0 10 | 11 | 12 | j-mybatis-annotation 13 | 注解使用 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-maven-plugin 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/src/main/java/com/jachs/mybatis/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/src/main/java/com/jachs/mybatis/dao/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.*; 6 | 7 | import com.jachs.mybatis.entity.Computer; 8 | 9 | /*** 10 | * @Mapper:将mapper接口注册到容器中
11 | * @Select:查询
12 | * @Delete:删除
13 | * @Insert:插入 
14 | * @Update:更新
15 | * @Options(useGeneratedKeys = true,keyColumn = "id"):指定表的自增主键并自动绑定到实体类对象
16 | * @Result 修饰返回的结果集,关联实体类属性和数据库字段一一对应,如果实体类属性和数据库属性名保持一致,    就不需要这个属性来修饰。
17 | * @author zhanchaohan 18 | * 19 | */ 20 | @Mapper 21 | public interface ComputerMapper { 22 | @Insert("insert into Computer(computerId,computerName,computerPrice,madeTime) values(#{computerId},#{computerName},#{computerPrice},#{madeTime})") 23 | int addComputer(Computer computer); 24 | 25 | @Delete("delete from computer where computerId=#{computer_id}") 26 | int deleteComputer(String computerId); 27 | 28 | @Select("select * from computer") 29 | List findAllComputer(); 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/src/main/java/com/jachs/mybatis/entity/Soft_ware.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /*** 6 | * 7 | * @author zhanchaohan 8 | * 9 | */ 10 | public class Soft_ware implements Serializable { 11 | private String softWareId; 12 | private String softWareName; 13 | private String cFKId; 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | public Soft_ware() { 18 | super(); 19 | } 20 | 21 | public Soft_ware(String softWareId, String softWareName, String cFKId) { 22 | super(); 23 | this.softWareId = softWareId; 24 | this.softWareName = softWareName; 25 | this.cFKId = cFKId; 26 | } 27 | public String getSoftWareId() { 28 | return softWareId; 29 | } 30 | public void setSoftWareId(String softWareId) { 31 | this.softWareId = softWareId; 32 | } 33 | public String getSoftWareName() { 34 | return softWareName; 35 | } 36 | public void setSoftWareName(String softWareName) { 37 | this.softWareName = softWareName; 38 | } 39 | public String getcFKId() { 40 | return cFKId; 41 | } 42 | public void setcFKId(String cFKId) { 43 | this.cFKId = cFKId; 44 | } 45 | public static long getSerialversionuid() { 46 | return serialVersionUID; 47 | } 48 | @Override 49 | public String toString() { 50 | return "Soft_ware [softWareId=" + softWareId + ", softWareName=" + softWareName + ", cFKId=" + cFKId + "]"; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | logging.level.com.example.demo.mapper=debug 7 | mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 8 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-annotation/src/test/java/com/jachs/mybatis/dao/ComputerTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.github.pagehelper.PageHelper; 10 | import com.jachs.mybatis.Application; 11 | import com.jachs.mybatis.entity.Computer; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest(classes = Application.class) 19 | public class ComputerTest { 20 | @Autowired 21 | private ComputerMapper computerMapper; 22 | 23 | @Test 24 | public void test() { 25 | Computer cp=new Computer(); 26 | cp.setComputerId(24+""); 27 | cp.setComputerName("nams"); 28 | cp.setComputerPrice(15875L); 29 | computerMapper.addComputer(cp); 30 | } 31 | @Test 32 | public void test1() { 33 | System.out.println(computerMapper.deleteComputer("24")); 34 | } 35 | @Test 36 | public void test2() { 37 | ListcpList=computerMapper.findAllComputer(); 38 | for (Computer computer : cpList) { 39 | System.out.println(computer.toString()); 40 | } 41 | } 42 | //分页 43 | @Test 44 | public void test3() { 45 | int pageNum=2; 46 | int pageSize=2; 47 | PageHelper.startPage(pageNum,pageSize); 48 | 49 | ListcpList=computerMapper.findAllComputer(); 50 | for (Computer computer : cpList) { 51 | System.out.println(computer.toString()); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/ApplicationContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | /*** 9 | * 10 | * @author zhanchaohan 11 | * 12 | */ 13 | @Component 14 | public class ApplicationContextUtils implements ApplicationContextAware { 15 | 16 | private static ApplicationContext context; 17 | 18 | @Override 19 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 20 | this.context = applicationContext; 21 | } 22 | 23 | /** 24 | * 25 | * @param beanName 26 | * @return 27 | */ 28 | public static Object getBean(String beanName) { 29 | return context.getBean(beanName); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/entity/ComputerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-19 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("computer") 22 | public class ComputerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("computerId") 27 | private String computerId; 28 | 29 | @TableField("computerName") 30 | private String computerName; 31 | 32 | @TableField("computerPrice") 33 | private Long computerPrice; 34 | 35 | @TableField("madeTime") 36 | private LocalDateTime madeTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/entity/SoftwareEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-19 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("software") 21 | public class SoftwareEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("softWareId") 26 | private String softWareId; 27 | 28 | @TableField("softWareName") 29 | private String softWareName; 30 | 31 | @TableField("cFKId") 32 | private String cFKId; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/entity/dto/CpDto.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity.dto; 2 | 3 | import java.util.Date; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /*** 10 | * 11 | * @author zhanchaohan 12 | * 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class CpDto { 18 | private String computerId; 19 | private String computerName; 20 | private Long computerPrice; 21 | private Date madeTime; 22 | 23 | private String softWareName; 24 | } 25 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.mapper; 2 | 3 | import com.jachs.mybatis.cache.MybatisPlusRedisCache; 4 | import com.jachs.mybatis.cache.entity.ComputerEntity; 5 | import com.jachs.mybatis.cache.entity.dto.CpDto; 6 | 7 | import java.util.List; 8 | 9 | import org.apache.ibatis.annotations.CacheNamespace; 10 | import org.apache.ibatis.annotations.Mapper; 11 | import org.apache.ibatis.annotations.Param; 12 | import org.apache.ibatis.annotations.Property; 13 | 14 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 15 | 16 | /** 17 | *

18 | * Mapper 接口 19 | *

20 | * 21 | * @author zhanchaohan 22 | * @since 2022-07-19 23 | */ 24 | @Mapper 25 | @CacheNamespace(implementation= MybatisPlusRedisCache.class, 26 | eviction=MybatisPlusRedisCache.class,properties = { @Property(name = "timeout", value = "60000") }) 27 | public interface ComputerMapper extends BaseMapper { 28 | 29 | List queryCpDto(@Param("cpId") String cpId); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.mapper; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | 5 | import java.util.List; 6 | 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 11 | 12 | /** 13 | *

14 | * Mapper 接口 15 | *

16 | * 17 | * @author zhanchaohan 18 | * @since 2022-07-19 19 | */ 20 | @Mapper 21 | public interface SoftwareMapper extends BaseMapper { 22 | List findAllByXml(); 23 | 24 | SoftwareEntity findById(@Param("swId") String swId); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/service/IComputerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service; 2 | 3 | import com.jachs.mybatis.cache.entity.ComputerEntity; 4 | import com.jachs.mybatis.cache.entity.dto.CpDto; 5 | 6 | import java.util.List; 7 | 8 | import com.baomidou.mybatisplus.extension.service.IService; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-19 17 | */ 18 | public interface IComputerService extends IService { 19 | 20 | List queryCpDto(String cpId); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/service/ISoftwareService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | 5 | import java.util.List; 6 | 7 | import com.baomidou.mybatisplus.extension.service.IService; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-19 16 | */ 17 | public interface ISoftwareService extends IService { 18 | 19 | List findAllByXml(); 20 | 21 | SoftwareEntity findById(String swId); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service.impl; 2 | 3 | import com.jachs.mybatis.cache.entity.ComputerEntity; 4 | import com.jachs.mybatis.cache.entity.dto.CpDto; 5 | import com.jachs.mybatis.cache.mapper.ComputerMapper; 6 | import com.jachs.mybatis.cache.service.IComputerService; 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 8 | 9 | import java.util.List; 10 | 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | *

15 | * 服务实现类 16 | *

17 | * 18 | * @author zhanchaohan 19 | * @since 2022-07-19 20 | */ 21 | @Service 22 | public class ComputerServiceImpl extends ServiceImpl implements IComputerService { 23 | 24 | @Override 25 | public List queryCpDto(String cpId) { 26 | return baseMapper.queryCpDto(cpId); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/java/com/jachs/mybatis/cache/service/impl/SoftwareServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service.impl; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | import com.jachs.mybatis.cache.mapper.SoftwareMapper; 5 | import com.jachs.mybatis.cache.service.ISoftwareService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | 8 | import java.util.List; 9 | 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | *

14 | * 服务实现类 15 | *

16 | * 17 | * @author zhanchaohan 18 | * @since 2022-07-19 19 | */ 20 | @Service 21 | public class SoftwareServiceImpl extends ServiceImpl implements ISoftwareService { 22 | 23 | @Override 24 | public List findAllByXml() { 25 | return baseMapper.findAllByXml(); 26 | } 27 | 28 | @Override 29 | public SoftwareEntity findById(String swId) { 30 | return baseMapper.findById(swId); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | logging.level.com.example.demo.mapper=debug 7 | mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 8 | 9 | mybatis-plus.mapper-locations=classpath:/xml/*.xml 10 | mybatis-plus.configuration.cache-enabled=true 11 | 12 | spring.redis.database=0 13 | spring.redis.host=127.0.0.1 14 | spring.redis.password= 15 | spring.redis.port=6379 16 | 17 | spring.redis.lettuce.pool.max-active=20 18 | spring.redis.lettuce.pool.max-wait=5000 19 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/resources/xml/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/main/resources/xml/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/test/java/com/jachs/mybatis/cache/ComputerTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 10 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 11 | import com.jachs.mybatis.cache.entity.ComputerEntity; 12 | import com.jachs.mybatis.cache.entity.dto.CpDto; 13 | import com.jachs.mybatis.cache.service.IComputerService; 14 | 15 | /*** 16 | * Mapper上加的缓存整个mapper 增删改查都被缓存,手动改库后查询缓存生效 17 | * @author zhanchaohan 18 | * 19 | */ 20 | @SpringBootTest(classes = Application.class) 21 | public class ComputerTest { 22 | @Autowired 23 | private IComputerService iComputerService; 24 | 25 | private String cpId="PWRMGMKLOA"; 26 | 27 | @Test 28 | public void test1() { 29 | LambdaQueryWrappercWrapper=new LambdaQueryWrapper(); 30 | 31 | cWrapper.eq(ComputerEntity::getComputerId, cpId); 32 | System.out.println(iComputerService.getOne(cWrapper).toString()); 33 | } 34 | @Test 35 | public void test5() { 36 | ListcpList=iComputerService.queryCpDto(cpId); 37 | 38 | cpList.forEach(cpd->{ 39 | System.out.println(cpd.toString()); 40 | }); 41 | } 42 | @Test 43 | public void test2() { 44 | UpdateWrappercpWrapper=new UpdateWrapper(); 45 | cpWrapper.eq("computerId", cpId); 46 | 47 | ComputerEntity ce=new ComputerEntity(); 48 | ce.setComputerPrice(8888L); 49 | iComputerService.update(ce,cpWrapper); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-cache/src/test/java/com/jachs/mybatis/cache/RedisTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import java.time.Duration; 4 | import java.util.Set; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Qualifier; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.data.redis.core.RedisTemplate; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | @SpringBootTest(classes = Application.class) 19 | public class RedisTest { 20 | @Autowired 21 | @Qualifier("stringRedisTemplate") 22 | private RedisTemplate redisTemplate; 23 | 24 | @Test 25 | public void test1() { 26 | SetkeySet=redisTemplate.keys("*"); 27 | keySet.forEach(key->{ 28 | System.out.println(key); 29 | }); 30 | } 31 | 32 | @Test 33 | public void test2() { 34 | SetkeySet=redisTemplate.keys("*"); 35 | 36 | keySet.forEach(key->{ 37 | System.out.println(redisTemplate.expire(key, Duration.ofMillis(3000))); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jachs 8 | j-mybatis-plus 9 | 1.0 10 | 11 | 12 | j-mybatis-redis-cache 13 | mybatis-redis二级缓存 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | com.baomidou 23 | mybatis-plus-boot-starter 24 | ${mybatis.plus.version} 25 | 26 | 33 | 34 | org.mybatis.caches 35 | mybatis-redis 36 | 1.0.0-beta3-SNAPSHOT 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/entity/ComputerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-07-19 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("computer") 22 | public class ComputerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("computerId") 27 | private String computerId; 28 | 29 | @TableField("computerName") 30 | private String computerName; 31 | 32 | @TableField("computerPrice") 33 | private Long computerPrice; 34 | 35 | @TableField("madeTime") 36 | private LocalDateTime madeTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/entity/SoftwareEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-19 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("software") 21 | public class SoftwareEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("softWareId") 26 | private String softWareId; 27 | 28 | @TableField("softWareName") 29 | private String softWareName; 30 | 31 | @TableField("cFKId") 32 | private String cFKId; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/entity/dto/CpDto.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.entity.dto; 2 | 3 | import java.util.Date; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /*** 10 | * 11 | * @author zhanchaohan 12 | * 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class CpDto { 18 | private String computerId; 19 | private String computerName; 20 | private Long computerPrice; 21 | private Date madeTime; 22 | 23 | private String softWareName; 24 | } 25 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.mapper; 2 | 3 | import com.jachs.mybatis.cache.entity.ComputerEntity; 4 | import com.jachs.mybatis.cache.entity.dto.CpDto; 5 | 6 | import java.util.List; 7 | 8 | import org.apache.ibatis.annotations.CacheNamespace; 9 | import org.apache.ibatis.annotations.Mapper; 10 | import org.apache.ibatis.annotations.Param; 11 | import org.apache.ibatis.annotations.Property; 12 | 13 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 14 | 15 | /** 16 | *

17 | * Mapper 接口 18 | *

19 | * 20 | * @author zhanchaohan 21 | * @since 2022-07-19 22 | */ 23 | @Mapper 24 | @CacheNamespace(implementation = org.mybatis.caches.redis.RedisCache.class ,properties = { @Property(name = "timeout", value = "3") }) 25 | public interface ComputerMapper extends BaseMapper { 26 | 27 | List queryCpDto(@Param("cpId") String cpId); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.mapper; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | 5 | import java.util.List; 6 | 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 11 | 12 | /** 13 | *

14 | * Mapper 接口 15 | *

16 | * 17 | * @author zhanchaohan 18 | * @since 2022-07-19 19 | */ 20 | @Mapper 21 | public interface SoftwareMapper extends BaseMapper { 22 | List findAllByXml(); 23 | 24 | SoftwareEntity findById(@Param("swId") String swId); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/service/IComputerService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service; 2 | 3 | import com.jachs.mybatis.cache.entity.ComputerEntity; 4 | import com.jachs.mybatis.cache.entity.dto.CpDto; 5 | 6 | import java.util.List; 7 | 8 | import com.baomidou.mybatisplus.extension.service.IService; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-07-19 17 | */ 18 | public interface IComputerService extends IService { 19 | 20 | List queryCpDto(String cpId); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/service/ISoftwareService.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | 5 | import java.util.List; 6 | 7 | import com.baomidou.mybatisplus.extension.service.IService; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-07-19 16 | */ 17 | public interface ISoftwareService extends IService { 18 | 19 | List findAllByXml(); 20 | 21 | SoftwareEntity findById(String swId); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/service/impl/ComputerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service.impl; 2 | 3 | import com.jachs.mybatis.cache.entity.ComputerEntity; 4 | import com.jachs.mybatis.cache.entity.dto.CpDto; 5 | import com.jachs.mybatis.cache.mapper.ComputerMapper; 6 | import com.jachs.mybatis.cache.service.IComputerService; 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 8 | 9 | import java.util.List; 10 | 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | *

15 | * 服务实现类 16 | *

17 | * 18 | * @author zhanchaohan 19 | * @since 2022-07-19 20 | */ 21 | @Service 22 | public class ComputerServiceImpl extends ServiceImpl implements IComputerService { 23 | 24 | @Override 25 | public List queryCpDto(String cpId) { 26 | return baseMapper.queryCpDto(cpId); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/java/com/jachs/mybatis/cache/service/impl/SoftwareServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache.service.impl; 2 | 3 | import com.jachs.mybatis.cache.entity.SoftwareEntity; 4 | import com.jachs.mybatis.cache.mapper.SoftwareMapper; 5 | import com.jachs.mybatis.cache.service.ISoftwareService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | 8 | import java.util.List; 9 | 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | *

14 | * 服务实现类 15 | *

16 | * 17 | * @author zhanchaohan 18 | * @since 2022-07-19 19 | */ 20 | @Service 21 | public class SoftwareServiceImpl extends ServiceImpl implements ISoftwareService { 22 | 23 | @Override 24 | public List findAllByXml() { 25 | return baseMapper.findAllByXml(); 26 | } 27 | 28 | @Override 29 | public SoftwareEntity findById(String swId) { 30 | return baseMapper.findById(swId); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | logging.level.com.example.demo.mapper=debug 7 | mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 8 | 9 | mybatis-plus.mapper-locations=classpath:/xml/*.xml 10 | mybatis-plus.configuration.cache-enabled=true 11 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/resources/redis.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.redis.database=0 3 | spring.redis.host=127.0.0.1 4 | spring.redis.password= 5 | spring.redis.port=6379 6 | 7 | spring.redis.lettuce.pool.max-active=20 8 | spring.redis.lettuce.pool.max-wait=5000 9 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/resources/xml/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/main/resources/xml/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /j-mybatis/plus/j-mybatis-redis-cache/src/test/java/com/jachs/mybatis/cache/ComputerTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.cache; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 10 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 11 | import com.jachs.mybatis.cache.entity.ComputerEntity; 12 | import com.jachs.mybatis.cache.entity.dto.CpDto; 13 | import com.jachs.mybatis.cache.service.IComputerService; 14 | 15 | /*** 16 | * Mapper上加的缓存整个mapper 增删改查都被缓存,手动改库后查询缓存生效 17 | * @author zhanchaohan 18 | * 19 | */ 20 | @SpringBootTest(classes = Application.class) 21 | public class ComputerTest { 22 | @Autowired 23 | private IComputerService iComputerService; 24 | 25 | private String cpId="PWRMGMKLOA"; 26 | 27 | @Test 28 | public void test1() { 29 | LambdaQueryWrappercWrapper=new LambdaQueryWrapper(); 30 | 31 | cWrapper.eq(ComputerEntity::getComputerId, cpId); 32 | System.out.println(iComputerService.getOne(cWrapper).toString()); 33 | } 34 | @Test 35 | public void test5() { 36 | ListcpList=iComputerService.queryCpDto(cpId); 37 | 38 | cpList.forEach(cpd->{ 39 | System.out.println(cpd.toString()); 40 | }); 41 | } 42 | @Test 43 | public void test2() { 44 | UpdateWrappercpWrapper=new UpdateWrapper(); 45 | cpWrapper.eq("computerId", cpId); 46 | 47 | ComputerEntity ce=new ComputerEntity(); 48 | ce.setComputerPrice(8888L); 49 | iComputerService.update(ce,cpWrapper); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/README.md: -------------------------------------------------------------------------------- 1 | # mybatis-plus-join-demo 2 | 3 | #### 介绍 4 | 5 | mybatis-plus-join演示工程 6 | 7 | [使用请参考mybatis-plus-join](https://gitee.com/best_handsome/mybatis-plus-join) 8 | 9 | #### 软件架构 10 | 11 | * springboot 12 | * mybatis-plus 13 | * h2 14 | 15 | #### 项目结构 16 | 17 | * [join-demo 多表查询演示工程](https://gitee.com/best_handsome/mybatis-plus-join-demo/tree/master/join-demo) 18 | * [mapping-demo 一对一,一对多关系映射演示工程](https://gitee.com/best_handsome/mybatis-plus-join-demo/tree/master/mapping-demo) -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/README.md: -------------------------------------------------------------------------------- 1 | ### 演示表结构 2 | 3 | user表 4 | 5 | |column|type|说明| 6 | |---|---|---| 7 | |id|int|主键| 8 | |name|varchar|名称| 9 | |sex|tinyint|性别| 10 | |head_img|varchar|头像| 11 | 12 | user_address表 13 | 14 | |column|type|说明| 15 | |---|---|---| 16 | |id|int|主键| 17 | |user_id|int|用户id| 18 | |area_id|int|区域id| 19 | |tel|varchar|电话| 20 | |address|varchar|地址| 21 | 22 | area表 23 | 24 | |column|type|说明| 25 | |---|---|---| 26 | |id|int|主键| 27 | |province|varchar|省| 28 | |city|varchar|市| 29 | |area|varchar|区| 30 | |postcode|varchar|邮编| 31 | 32 | [数据库DDL](https://gitee.com/best_handsome/mybatis-plus-join-demo/blob/master/join-demo/src/main/resources/db/schema.sql) 33 | 34 | [数据库数据记录](https://gitee.com/best_handsome/mybatis-plus-join-demo/blob/master/join-demo/src/main/resources/db/data.sql) -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | j-mybatis 8 | 1.0 9 | ../../pom.xml 10 | 11 | join-demo 12 | jar 13 | 14 | 15 | 1.8 16 | 17 | 18 | 19 | 20 | com.baomidou 21 | mybatis-plus-boot-starter 22 | ${mybatis.plus.version} 23 | 24 | 25 | com.github.yulichang 26 | mybatis-plus-join 27 | ${mybatis.plus.join.version} 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/Application.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 4 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * mybatis-plus配置 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | 14 | /** 15 | * 分页插件 16 | */ 17 | @Bean 18 | public MybatisPlusInterceptor paginationInterceptor() { 19 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 20 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 21 | return interceptor; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/dto/UserDTO.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.dto; 2 | 3 | import com.github.yulichang.join.enums.Sex; 4 | import lombok.Data; 5 | import lombok.ToString; 6 | 7 | /** 8 | * userDTO 9 | */ 10 | @Data 11 | @ToString 12 | public class UserDTO { 13 | /** user */ 14 | private Integer id; 15 | /** user */ 16 | private String nameName; 17 | /** user */ 18 | private Sex sex; 19 | /** user */ 20 | private String headImg; 21 | /** user */ 22 | private String userHeadImg;//同 headImg 别名测试 23 | /** user_address */ 24 | private String tel; 25 | /** user_address */ 26 | private String address; 27 | /** user_address */ 28 | private String userAddress; 29 | /** area */ 30 | private String province; 31 | /** area */ 32 | private String city; 33 | /** area */ 34 | private String area; 35 | } 36 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/entity/AreaDO.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.ToString; 9 | import lombok.experimental.Accessors; 10 | 11 | @Data 12 | @ToString 13 | @Accessors(chain = true) 14 | @EqualsAndHashCode 15 | @TableName("area") 16 | public class AreaDO { 17 | 18 | @TableId 19 | private Integer id; 20 | 21 | private String province; 22 | 23 | private String city; 24 | 25 | private String area; 26 | 27 | private String postcode; 28 | 29 | @TableLogic 30 | private Boolean del; 31 | } 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/entity/UserAddressDO.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.ToString; 9 | import lombok.experimental.Accessors; 10 | 11 | @Data 12 | @ToString 13 | @Accessors(chain = true) 14 | @EqualsAndHashCode 15 | @TableName("user_address") 16 | public class UserAddressDO { 17 | 18 | @TableId 19 | private Integer id; 20 | 21 | private Integer userId; 22 | 23 | private Integer areaId; 24 | 25 | private String tel; 26 | 27 | private String address; 28 | 29 | @TableLogic 30 | private Boolean del; 31 | } 32 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/entity/UserDO.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.github.yulichang.join.enums.Sex; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | import lombok.ToString; 10 | import lombok.experimental.Accessors; 11 | 12 | @Data 13 | @ToString 14 | @Accessors(chain = true) 15 | @EqualsAndHashCode 16 | @TableName("`user`") 17 | public class UserDO { 18 | 19 | @TableId 20 | private Integer id; 21 | 22 | private String name; 23 | 24 | private Sex sex; 25 | 26 | private String headImg; 27 | 28 | @TableLogic 29 | private Boolean del; 30 | } 31 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/enums/Sex.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | import lombok.Getter; 5 | import lombok.ToString; 6 | 7 | @Getter 8 | @ToString 9 | public enum Sex { 10 | 11 | MAN(0, "男"), 12 | 13 | WOMAN(1, "女"); 14 | 15 | @EnumValue 16 | private final int code; 17 | private final String des; 18 | 19 | Sex(int code, String des) { 20 | this.code = code; 21 | this.des = des; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/mapper/AreaMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.mapper; 2 | 3 | import com.github.yulichang.join.entity.AreaDO; 4 | import com.github.yulichang.base.MPJBaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | @Mapper 8 | public interface AreaMapper extends MPJBaseMapper { 9 | } 10 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/mapper/UserAddressMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.mapper; 2 | 3 | import com.github.yulichang.join.entity.UserAddressDO; 4 | import com.github.yulichang.base.MPJBaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | @Mapper 8 | public interface UserAddressMapper extends MPJBaseMapper { 9 | } 10 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/java/com/github/yulichang/join/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.join.mapper; 2 | 3 | import com.github.yulichang.join.entity.UserDO; 4 | import com.github.yulichang.base.MPJBaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | @Mapper 8 | public interface UserMapper extends MPJBaseMapper { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | schema: classpath:db/schema.sql 5 | data: classpath:db/data.sql 6 | url: jdbc:mysql://localhost:3306/mybatis-plus?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 7 | username: root 8 | password: 123456 9 | mybatis-plus: 10 | typeEnumsPackage: com.github.yulichang.join.enums 11 | global-config: 12 | db-config: 13 | logic-delete-field: del 14 | logic-delete-value: true 15 | logic-not-delete-value: false 16 | banner: true 17 | configuration: 18 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/join-demo/src/main/resources/db/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS area; 2 | 3 | create table area 4 | ( 5 | id int auto_increment 6 | primary key, 7 | province varchar(255) null, 8 | city varchar(255) null, 9 | area varchar(255) null, 10 | postcode varchar(255) null, 11 | del bit 12 | ); 13 | 14 | DROP TABLE IF EXISTS `user`; 15 | 16 | create table `user` 17 | ( 18 | id int auto_increment 19 | primary key, 20 | name varchar(255) not null, 21 | sex tinyint not null, 22 | head_img varchar(255) not null, 23 | del bit 24 | ); 25 | 26 | DROP TABLE IF EXISTS user_address; 27 | 28 | create table user_address 29 | ( 30 | id int auto_increment 31 | primary key, 32 | user_id int null, 33 | area_id int null, 34 | tel varchar(255) null, 35 | address varchar(255) null, 36 | del bit 37 | ); -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/README.md: -------------------------------------------------------------------------------- 1 | ## 演示表结构 2 | 3 | user表 4 | 5 | |column|type|说明| 6 | |---|---|---| 7 | |id|int|主键| 8 | |pid|int|上级id| 9 | |name|varchar|名称| 10 | |sex|tinyint|性别| 11 | |head_img|varchar|头像| 12 | 13 | user_address表 14 | 15 | |column|type|说明| 16 | |---|---|---| 17 | |id|int|主键| 18 | |user_id|int|用户id| 19 | |tel|varchar|电话| 20 | |address|varchar|地址| 21 | 22 | [数据库DDL](https://gitee.com/best_handsome/mybatis-plus-join-demo/blob/master/mapping-demo/src/main/resources/db/schema.sql) 23 | 24 | [数据库数据记录](https://gitee.com/best_handsome/mybatis-plus-join-demo/blob/master/mapping-demo/src/main/resources/db/data.sql) -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | j-mybatis 8 | 1.0 9 | ../../pom.xml 10 | 11 | mapping-demo 12 | 13 | 14 | 1.8 15 | 16 | 17 | 18 | 19 | 20 | com.baomidou 21 | mybatis-plus-boot-starter 22 | ${mybatis.plus.version} 23 | 24 | 25 | com.github.yulichang 26 | mybatis-plus-join 27 | ${mybatis.plus.join.version} 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/Application.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan("com.github.yulichang.mapping.mapper") 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 4 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * mybatis-plus配置 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | 14 | /** 15 | * 分页插件 16 | */ 17 | @Bean 18 | public MybatisPlusInterceptor paginationInterceptor() { 19 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 20 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 21 | return interceptor; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/entity/UserAddressDO.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.annotation.TableLogic; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.Data; 7 | import lombok.ToString; 8 | import lombok.experimental.Accessors; 9 | 10 | @Data 11 | @ToString 12 | @Accessors(chain = true) 13 | @TableName("user_address") 14 | public class UserAddressDO { 15 | 16 | @TableId 17 | private Integer id; 18 | private Integer userId; 19 | private String tel; 20 | private String address; 21 | @TableLogic 22 | private Boolean del; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/enums/Sex.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | import lombok.Getter; 5 | import lombok.ToString; 6 | 7 | @Getter 8 | @ToString 9 | public enum Sex { 10 | 11 | MAN(0, "男"), 12 | 13 | WOMAN(1, "女"); 14 | 15 | @EnumValue 16 | private final int code; 17 | private final String des; 18 | 19 | Sex(int code, String des) { 20 | this.code = code; 21 | this.des = des; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/mapper/UserAddressMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.mapper; 2 | 3 | import com.github.yulichang.base.MPJBaseMapper; 4 | import com.github.yulichang.mapping.entity.UserAddressDO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | @Mapper 8 | public interface UserAddressMapper extends MPJBaseMapper { 9 | } 10 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.mapper; 2 | 3 | import com.github.yulichang.base.MPJBaseMapper; 4 | import com.github.yulichang.mapping.entity.UserDO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | @Mapper 8 | public interface UserMapper extends MPJBaseMapper { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.service; 2 | 3 | import com.github.yulichang.base.MPJBaseService; 4 | import com.github.yulichang.mapping.entity.UserDO; 5 | 6 | public interface UserService extends MPJBaseService { 7 | } 8 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/java/com/github/yulichang/mapping/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.yulichang.mapping.service; 2 | 3 | import com.github.yulichang.base.MPJBaseServiceImpl; 4 | import com.github.yulichang.mapping.entity.UserDO; 5 | import com.github.yulichang.mapping.mapper.UserMapper; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class UserServiceImpl extends MPJBaseServiceImpl implements UserService { 10 | } 11 | -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: org.h2.Driver 4 | schema: classpath:db/schema.sql 5 | data: classpath:db/data.sql 6 | url: jdbc:h2:mem:test 7 | username: root 8 | password: test 9 | mybatis-plus: 10 | typeEnumsPackage: com.github.yulichang.mapping.enums 11 | global-config: 12 | db-config: 13 | logic-delete-field: del 14 | logic-delete-value: true 15 | logic-not-delete-value: false 16 | banner: true 17 | configuration: 18 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl -------------------------------------------------------------------------------- /j-mybatis/plus/mybatis-plus-join-demo/mapping-demo/src/main/resources/db/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `user`; 2 | 3 | create table `user` 4 | ( 5 | `id` int auto_increment 6 | primary key, 7 | `parent_id` int not null, 8 | `name` varchar(255) not null, 9 | `sex` int not null, 10 | `head_img` varchar(255) not null, 11 | `del` bit not null 12 | ); 13 | 14 | DROP TABLE IF EXISTS user_address; 15 | 16 | create table user_address 17 | ( 18 | id int auto_increment 19 | primary key, 20 | user_id int null, 21 | tel varchar(255) null, 22 | address varchar(255) null, 23 | del bit not null 24 | ); -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.jachs 8 | j-mybatis 9 | 1.0 10 | 11 | 12 | j-mybatis-xml-file 13 | 配置Xml 14 | jar 15 | 16 | 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/Application.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /*** 8 | * 9 | * @author zhanchaohan 10 | * 11 | */ 12 | @MapperScan("com.jachs.mybatis.dao") 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Application.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/dao/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.apache.ibatis.annotations.Mapper; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | import com.jachs.mybatis.entity.Computer; 10 | 11 | /*** 12 | * 13 | * @author zhanchaohan 14 | * 15 | */ 16 | @Mapper 17 | public interface ComputerMapper { 18 | int deleteByPrimaryKey(String computerid); 19 | 20 | int insert(Computer record); 21 | 22 | int insertSelective(Computer record); 23 | 24 | Computer selectByPrimaryKey(String computerid); 25 | 26 | int updateByPrimaryKeySelective(Computer record); 27 | 28 | int updateByPrimaryKey(Computer record); 29 | //查询 30 | Long allCount(); 31 | List findAll(); 32 | Computer findByNameAndPrice(@Param("cname") String cpName,@Param("cprice") long price); 33 | Computer findByNameAndPriceAndMadeTime(Map map); 34 | List findIdLike(@Param("cid") String id); 35 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/dao/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import com.jachs.mybatis.dto.SoftWareDto; 9 | import com.jachs.mybatis.entity.Software; 10 | import com.jachs.mybatis.vo.SoftWareVo; 11 | 12 | /*** 13 | * 14 | * @author zhanchaohan 15 | * 16 | */ 17 | @Mapper 18 | public interface SoftwareMapper { 19 | int deleteByPrimaryKey(String softwareid); 20 | 21 | int insert(Software record); 22 | 23 | int insertSelective(Software record); 24 | 25 | Software selectByPrimaryKey(String softwareid); 26 | 27 | int updateByPrimaryKeySelective(Software record); 28 | 29 | int updateByPrimaryKey(Software record); 30 | //查询 31 | List findByCpId(@Param("cpId") String cpId); 32 | List findBycIdAndName(SoftWareVo swv); 33 | List findBycIdAndNameDto(SoftWareVo swv); 34 | //拼接循环语句 35 | List queryManyById(List idList); 36 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/dto/SoftWareDto.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.dto; 2 | 3 | /*** 4 | * 5 | * @author zhanchaohan 6 | * 7 | */ 8 | public class SoftWareDto { 9 | //computer表字段 10 | private String cpId; 11 | private String cpName; 12 | private Long cpMonery; 13 | //software表字段 14 | private String swId; 15 | private String swName; 16 | 17 | 18 | public SoftWareDto() { 19 | super(); 20 | } 21 | public SoftWareDto(String cpId, String cpName, Long cpMonery, String swId, String swName) { 22 | super(); 23 | this.cpId = cpId; 24 | this.cpName = cpName; 25 | this.cpMonery = cpMonery; 26 | this.swId = swId; 27 | this.swName = swName; 28 | } 29 | 30 | public String getCpId() { 31 | return cpId; 32 | } 33 | public void setCpId(String cpId) { 34 | this.cpId = cpId; 35 | } 36 | public String getCpName() { 37 | return cpName; 38 | } 39 | public void setCpName(String cpName) { 40 | this.cpName = cpName; 41 | } 42 | public Long getCpMonery() { 43 | return cpMonery; 44 | } 45 | public void setCpMonery(Long cpMonery) { 46 | this.cpMonery = cpMonery; 47 | } 48 | public String getSwId() { 49 | return swId; 50 | } 51 | public void setSwId(String swId) { 52 | this.swId = swId; 53 | } 54 | public String getSwName() { 55 | return swName; 56 | } 57 | public void setSwName(String swName) { 58 | this.swName = swName; 59 | } 60 | @Override 61 | public String toString() { 62 | return "SoftWareDto [cpId=" + cpId + ", cpMonery=" + cpMonery + ", swId=" + swId + ", swName=" + swName + "]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/entity/Computer.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | /*** 7 | * 8 | * @author zhanchaohan 9 | * 10 | */ 11 | public class Computer implements Serializable { 12 | private String computerid; 13 | 14 | private String computername; 15 | 16 | private Long computerprice; 17 | 18 | private Date madetime; 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public String getComputerid() { 23 | return computerid; 24 | } 25 | 26 | public void setComputerid(String computerid) { 27 | this.computerid = computerid == null ? null : computerid.trim(); 28 | } 29 | 30 | public String getComputername() { 31 | return computername; 32 | } 33 | 34 | public void setComputername(String computername) { 35 | this.computername = computername == null ? null : computername.trim(); 36 | } 37 | 38 | public Long getComputerprice() { 39 | return computerprice; 40 | } 41 | 42 | public void setComputerprice(Long computerprice) { 43 | this.computerprice = computerprice; 44 | } 45 | 46 | public Date getMadetime() { 47 | return madetime; 48 | } 49 | 50 | public void setMadetime(Date madetime) { 51 | this.madetime = madetime; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Computer [computerid=" + computerid + ", computername=" + computername + ", computerprice=" 57 | + computerprice + ", madetime=" + madetime + "]"; 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/entity/Software.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /*** 6 | * 7 | * @author zhanchaohan 8 | * 9 | */ 10 | public class Software implements Serializable { 11 | private String softwareid; 12 | 13 | private String softwarename; 14 | 15 | private String cfkid; 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | public String getSoftwareid() { 20 | return softwareid; 21 | } 22 | 23 | public void setSoftwareid(String softwareid) { 24 | this.softwareid = softwareid == null ? null : softwareid.trim(); 25 | } 26 | 27 | public String getSoftwarename() { 28 | return softwarename; 29 | } 30 | 31 | public void setSoftwarename(String softwarename) { 32 | this.softwarename = softwarename == null ? null : softwarename.trim(); 33 | } 34 | 35 | public String getCfkid() { 36 | return cfkid; 37 | } 38 | 39 | public void setCfkid(String cfkid) { 40 | this.cfkid = cfkid == null ? null : cfkid.trim(); 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Software [softwareid=" + softwareid + ", softwarename=" + softwarename + ", cfkid=" + cfkid + "]"; 46 | } 47 | 48 | 49 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/java/com/jachs/mybatis/vo/SoftWareVo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis.vo; 2 | 3 | /*** 4 | * 5 | * @author zhanchaohan 6 | * 7 | */ 8 | public class SoftWareVo { 9 | private String cpId;//Computer表字段 10 | private String swName;//Software表字段 11 | 12 | 13 | public SoftWareVo() { 14 | super(); 15 | } 16 | public SoftWareVo(String cpId, String swName) { 17 | super(); 18 | this.cpId = cpId; 19 | this.swName = swName; 20 | } 21 | public String getCpId() { 22 | return cpId; 23 | } 24 | public void setCpId(String cpId) { 25 | this.cpId = cpId; 26 | } 27 | public String getSwName() { 28 | return swName; 29 | } 30 | public void setSwName(String swName) { 31 | this.swName = swName; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/jpatest?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=123456 5 | 6 | #https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/site/markdown/index.md 7 | mybatis.typeAliasesPackage=com.jachs.mybatis.entity 8 | mybatis.mapperLocations=classpath:com/jachs/mybatis/xml/*.xml 9 | 10 | #打印SQL,logging.level.com,后面的路径指的是mybatis对应的方法接口所在的包。并不是mapper.xml所在的包 11 | #logging.level.com.jachs.mybatis.dao=debug 12 | mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl 13 | 14 | # 15 | pagehelper.helperDialect=mysql 16 | pagehelper.reasonable=true 17 | pagehelper.supportMethodsArguments=true 18 | pagehelper.params=count=countSql -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/resources/forEach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhanChaoHan/spring-boot-mybatis/040d811eb01afab2d8244e228b2b0a9491924d39/j-mybatis/xml/j-mybatis-xml-file/src/main/resources/forEach.png -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/main/resources/readme: -------------------------------------------------------------------------------- 1 | 官网地址:https://mybatis.org/mybatis-3/zh/index.html 2 | github:https://github.com/mybatis/mybatis-3 3 | boot:https://github.com/mybatis/spring-boot-starter -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/PagehelperDemo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.github.pagehelper.PageHelper; 10 | import com.jachs.mybatis.Application; 11 | import com.jachs.mybatis.dao.ComputerMapper; 12 | import com.jachs.mybatis.dao.SoftwareMapper; 13 | import com.jachs.mybatis.dto.SoftWareDto; 14 | import com.jachs.mybatis.entity.Computer; 15 | import com.jachs.mybatis.vo.SoftWareVo; 16 | 17 | /*** 18 | * 19 | * @author zhanchaohan 20 | * 21 | */ 22 | @SpringBootTest(classes = Application.class) 23 | public class PagehelperDemo { 24 | @Autowired 25 | private ComputerMapper computerMapper; 26 | @Autowired 27 | private SoftwareMapper softwareMapper; 28 | 29 | //简单查询分页 30 | @Test 31 | public void test1() { 32 | int pageNum=2; 33 | int pageSize=2; 34 | PageHelper.startPage(pageNum,pageSize); 35 | //注意:只有紧跟着PageHelper.startPage()的sql语句才被pagehelper起作用 36 | List cList=computerMapper.findAll(); 37 | 38 | cList.forEach(a->{ 39 | System.out.println(a.toString()); 40 | }); 41 | } 42 | @Test 43 | public void test2() { 44 | SoftWareVo swv=new SoftWareVo(); 45 | 46 | swv.setCpId("BGHBOBPKMO"); 47 | swv.setSwName("Q"); 48 | 49 | int pageNum=1; 50 | int pageSize=2; 51 | PageHelper.startPage(pageNum,pageSize); 52 | List swDTO=softwareMapper.findBycIdAndNameDto(swv); 53 | 54 | swDTO.forEach(dto->{ 55 | System.out.println(dto.toString()); 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/complex/ForEachTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao.complex; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import com.jachs.mybatis.Application; 11 | import com.jachs.mybatis.dao.SoftwareMapper; 12 | import com.jachs.mybatis.entity.Software; 13 | 14 | /*** 15 | * 16 | * @author zhanchaohan 17 | * 18 | */ 19 | @SpringBootTest(classes = Application.class) 20 | public class ForEachTest { 21 | @Autowired 22 | private SoftwareMapper software; 23 | 24 | @Test 25 | public void test1() { 26 | ListidList=new ArrayList(); 27 | idList.add("ACSVRVSMUF"); 28 | idList.add("ATAMTQKHOA"); 29 | idList.add("BLDDDUALYE"); 30 | ListswList=software.queryManyById(idList); 31 | 32 | swList.forEach(sw->{ 33 | System.out.println(sw.toString()); 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/complex/SoftwareQueryDemo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao.complex; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import com.jachs.mybatis.Application; 10 | import com.jachs.mybatis.dao.SoftwareMapper; 11 | import com.jachs.mybatis.dto.SoftWareDto; 12 | import com.jachs.mybatis.entity.Software; 13 | import com.jachs.mybatis.vo.SoftWareVo; 14 | 15 | /**** 16 | * @author zhanchaohan 17 | * 18 | */ 19 | @SpringBootTest(classes = Application.class) 20 | public class SoftwareQueryDemo { 21 | @Autowired 22 | private SoftwareMapper software; 23 | 24 | //连表查询 25 | @Test 26 | public void test1() { 27 | ListswList=software.findByCpId("NJKSLVUSBA"); 28 | 29 | swList.forEach(sw->{ 30 | System.out.println(sw.toString()); 31 | }); 32 | } 33 | //bean查询 34 | @Test 35 | public void test2() { 36 | SoftWareVo swv=new SoftWareVo("NJKSLVUSBA","信"); 37 | 38 | ListswList=software.findBycIdAndName(swv); 39 | 40 | swList.forEach(sw->{ 41 | System.out.println(sw.toString()); 42 | }); 43 | } 44 | //bean查询返回dto 45 | @Test 46 | public void test3() { 47 | SoftWareVo swv=new SoftWareVo("NJKSLVUSBA","信"); 48 | ListswList=software.findBycIdAndNameDto(swv); 49 | 50 | swList.forEach(sw->{ 51 | System.out.println(sw.toString()); 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/paser/util/MyBatisSql.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao.paser.util; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * @author zhanchaohan 10 | * 11 | */ 12 | public class MyBatisSql 13 | { 14 | /** * 运行期 sql */ 15 | private String sql; 16 | 17 | /** * 参数 数组 */ 18 | private Object[] parameters; 19 | 20 | public void setSql(String sql) { 21 | 22 | this.sql = sql; 23 | } 24 | 25 | public String getSql() { 26 | 27 | return sql; 28 | } 29 | 30 | public void setParameters(Object[] parameters) { 31 | 32 | this.parameters = parameters; 33 | } 34 | 35 | public Object[] getParameters() { 36 | 37 | return parameters; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | if(parameters == null || sql == null) 43 | { 44 | return ""; 45 | } 46 | List parametersArray = Arrays.asList(parameters); 47 | List list = new ArrayList(parametersArray); 48 | while(sql.indexOf("?") != -1 && list.size() > 0 && parameters.length > 0&&list.get(0)!=null) 49 | { 50 | sql = sql.replaceFirst("\\?", list.get(0).toString()); 51 | list.remove(0); 52 | } 53 | return sql.replaceAll("(\r?\n(\\s*\r?\n)+)", "\r\n"); 54 | } 55 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/simple/SoftwareAddDemo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao.simple; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Random; 6 | import java.util.Set; 7 | 8 | import org.apache.commons.lang3.RandomStringUtils; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import com.jachs.mybatis.Application; 14 | import com.jachs.mybatis.dao.ComputerMapper; 15 | import com.jachs.mybatis.dao.SoftwareMapper; 16 | import com.jachs.mybatis.entity.Computer; 17 | import com.jachs.mybatis.entity.Software; 18 | 19 | /*** 20 | * @author zhanchaohan 21 | * 22 | */ 23 | @SpringBootTest(classes = Application.class) 24 | public class SoftwareAddDemo { 25 | @Autowired 26 | private ComputerMapper computerMapper; 27 | @Autowired 28 | private SoftwareMapper softwareMapper; 29 | 30 | private SetcpID=new HashSet(); 31 | 32 | public void initPid() { 33 | ListcpList=computerMapper.findAll(); 34 | cpList.forEach(cp->{ 35 | cpID.add(cp.getComputerid()); 36 | }); 37 | } 38 | @Test 39 | public void test1() { 40 | initPid(); 41 | Random ran=new Random(); 42 | RandomStringUtils rsu=new RandomStringUtils(); 43 | 44 | cpID.forEach(cpiD->{ 45 | int count=ran.nextInt(10); 46 | 47 | for (int kk = 0; kk < count; kk++) { 48 | Software sw=new Software(); 49 | 50 | sw.setSoftwareid(rsu.random(10, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")); 51 | sw.setSoftwarename(rsu.random(20,"苹果ACER联想QQ腾讯阿里巴巴微信数据库C#Google")); 52 | sw.setCfkid(cpiD); 53 | 54 | softwareMapper.insert(sw); 55 | } 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-file/src/test/java/com/jachs/mybatisc/dao/simple/query/ComputerQueryDemo.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatisc.dao.simple.query; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | 11 | import com.jachs.mybatis.Application; 12 | import com.jachs.mybatis.dao.ComputerMapper; 13 | import com.jachs.mybatis.entity.Computer; 14 | 15 | /**** 16 | * @author zhanchaohan 17 | * 18 | */ 19 | @SpringBootTest(classes = Application.class) 20 | public class ComputerQueryDemo { 21 | @Autowired 22 | private ComputerMapper computerMapper; 23 | 24 | //id查询 25 | @Test 26 | public void test1() { 27 | Computer cp=computerMapper.selectByPrimaryKey("ABZTUKPYPB"); 28 | 29 | System.out.println(cp.toString()); 30 | } 31 | //多条件查询,@Param注解传参法 32 | @Test 33 | public void test2() { 34 | Computer cp=computerMapper.findByNameAndPrice("囩歺鰂遐婤鎟闡撱蘔啣歡渤聞列稚豻耆蕓廋寏",1530L); 35 | 36 | System.out.println(cp.toString()); 37 | } 38 | //多条件查询,Map传参法 39 | @Test 40 | public void test3() { 41 | Mapdata=new HashMap(); 42 | data.put("name", "半绢図凞碦荊縄棺鰫酁詯姉轭湙齉摲炒搴铙獛"); 43 | data.put("pri", 9267); 44 | 45 | Computer cp=computerMapper.findByNameAndPriceAndMadeTime(data); 46 | System.out.println(cp.toString()); 47 | } 48 | //like 查询 49 | @Test 50 | public void test5() { 51 | List cpList=computerMapper.findIdLike("A"); 52 | 53 | cpList.forEach(cp->{ 54 | System.out.println(cp.toString()); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.jachs 9 | j-mybatis 10 | 1.0 11 | 12 | 13 | j-mybatis-xml-generator 14 | 配置文件生成 15 | jar 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.mybatis.generator 24 | mybatis-generator-core 25 | 1.4.0 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/src/main/java/com/jachs/mybatis/MybatisGeneratorApp.java: -------------------------------------------------------------------------------- 1 | package com.jachs.mybatis; 2 | 3 | import org.mybatis.generator.api.ShellRunner; 4 | 5 | public class MybatisGeneratorApp { 6 | public static void main(String[] args) { 7 | args = new String[] { "-configfile", "src\\main\\resources\\generator.xml", "-overwrite" }; 8 | ShellRunner.main(args); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/src/main/java/com/jachs/springmybatis/dao/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.dao; 2 | 3 | import com.jachs.springmybatis.entity.Computer; 4 | 5 | public interface ComputerMapper { 6 | int deleteByPrimaryKey(String computerid); 7 | 8 | int insert(Computer record); 9 | 10 | int insertSelective(Computer record); 11 | 12 | Computer selectByPrimaryKey(String computerid); 13 | 14 | int updateByPrimaryKeySelective(Computer record); 15 | 16 | int updateByPrimaryKey(Computer record); 17 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/src/main/java/com/jachs/springmybatis/dao/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.dao; 2 | 3 | import com.jachs.springmybatis.entity.Software; 4 | 5 | public interface SoftwareMapper { 6 | int deleteByPrimaryKey(String softwareid); 7 | 8 | int insert(Software record); 9 | 10 | int insertSelective(Software record); 11 | 12 | Software selectByPrimaryKey(String softwareid); 13 | 14 | int updateByPrimaryKeySelective(Software record); 15 | 16 | int updateByPrimaryKey(Software record); 17 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/src/main/java/com/jachs/springmybatis/entity/Computer.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Computer implements Serializable { 7 | private String computerid; 8 | 9 | private String computername; 10 | 11 | private Long computerprice; 12 | 13 | private Date madetime; 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | public String getComputerid() { 18 | return computerid; 19 | } 20 | 21 | public void setComputerid(String computerid) { 22 | this.computerid = computerid == null ? null : computerid.trim(); 23 | } 24 | 25 | public String getComputername() { 26 | return computername; 27 | } 28 | 29 | public void setComputername(String computername) { 30 | this.computername = computername == null ? null : computername.trim(); 31 | } 32 | 33 | public Long getComputerprice() { 34 | return computerprice; 35 | } 36 | 37 | public void setComputerprice(Long computerprice) { 38 | this.computerprice = computerprice; 39 | } 40 | 41 | public Date getMadetime() { 42 | return madetime; 43 | } 44 | 45 | public void setMadetime(Date madetime) { 46 | this.madetime = madetime; 47 | } 48 | } -------------------------------------------------------------------------------- /j-mybatis/xml/j-mybatis-xml-generator/src/main/java/com/jachs/springmybatis/entity/Software.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Software implements Serializable { 6 | private String softwareid; 7 | 8 | private String softwarename; 9 | 10 | private String cfkid; 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | public String getSoftwareid() { 15 | return softwareid; 16 | } 17 | 18 | public void setSoftwareid(String softwareid) { 19 | this.softwareid = softwareid == null ? null : softwareid.trim(); 20 | } 21 | 22 | public String getSoftwarename() { 23 | return softwarename; 24 | } 25 | 26 | public void setSoftwarename(String softwarename) { 27 | this.softwarename = softwarename == null ? null : softwarename.trim(); 28 | } 29 | 30 | public String getCfkid() { 31 | return cfkid; 32 | } 33 | 34 | public void setCfkid(String cfkid) { 35 | this.cfkid = cfkid == null ? null : cfkid.trim(); 36 | } 37 | } -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | spring-mybatis 8 | 1.0 9 | 10 | 11 | spring-mybatis-plus 12 | spring-mybatis-plus 13 | plus配置 14 | 15 | 16 | 17 | 18 | 19 | 20 | com.baomidou 21 | mybatis-plus 22 | 3.5.2 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/java/com/jachs/springmybatis/entity/ComputerEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | import lombok.EqualsAndHashCode; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author zhanchaohan 17 | * @since 2022-08-17 18 | */ 19 | @Data 20 | @EqualsAndHashCode(callSuper = false) 21 | @TableName("computer") 22 | public class ComputerEntity implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | @TableId("computerId") 27 | private String computerId; 28 | 29 | @TableField("computerName") 30 | private String computerName; 31 | 32 | @TableField("computerPrice") 33 | private Long computerPrice; 34 | 35 | @TableField("madeTime") 36 | private LocalDateTime madeTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/java/com/jachs/springmybatis/entity/SoftwareEntity.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import java.io.Serializable; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | *

12 | * 13 | *

14 | * 15 | * @author zhanchaohan 16 | * @since 2022-08-17 17 | */ 18 | @Data 19 | @EqualsAndHashCode(callSuper = false) 20 | @TableName("software") 21 | public class SoftwareEntity implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @TableId("softWareId") 26 | private String softWareId; 27 | 28 | @TableField("softWareName") 29 | private String softWareName; 30 | 31 | @TableField("cFKId") 32 | private String cFKId; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/java/com/jachs/springmybatis/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.mapper; 2 | 3 | import com.jachs.springmybatis.entity.ComputerEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-08-17 16 | */ 17 | @Mapper 18 | public interface ComputerMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/java/com/jachs/springmybatis/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.mapper; 2 | 3 | import com.jachs.springmybatis.entity.SoftwareEntity; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author zhanchaohan 15 | * @since 2022-08-17 16 | */ 17 | @Mapper 18 | public interface SoftwareMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.url=jdbc:mysql://127.0.0.1:3306/jpatest?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC 2 | jdbc.username=root 3 | jdbc.password=123456 -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/resources/xml/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/main/resources/xml/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-plus/src/test/java/com/jachs/springmybatis/ComputerMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.Date; 5 | import java.util.Locale; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | import com.github.javafaker.Faker; 14 | import com.jachs.springmybatis.entity.ComputerEntity; 15 | import com.jachs.springmybatis.mapper.ComputerMapper; 16 | 17 | /** 18 | * 19 | * @author zhanchaohan 20 | * 21 | */ 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @ContextConfiguration(locations = {"classpath:/spring.xml"}) 24 | public class ComputerMapperTest { 25 | private static Faker FAKER = new Faker(Locale.CHINA); 26 | @Autowired 27 | private ComputerMapper computerMapper; 28 | 29 | @Test 30 | public void t1() { 31 | ComputerEntity cp=new ComputerEntity(); 32 | 33 | cp.setComputerId(FAKER.app().author()); 34 | cp.setComputerName(FAKER.company().name()); 35 | cp.setComputerPrice(FAKER.number().randomNumber()); 36 | cp.setMadeTime(LocalDateTime.now()); 37 | computerMapper.insert(cp); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.jachs 7 | spring-mybatis 8 | 1.0 9 | 10 | 11 | spring-mybatis-xml 12 | spring-mybatis-xml 13 | xml配置 14 | 15 | 16 | 17 | 18 | 19 | 20 | org.mybatis 21 | mybatis 22 | ${mybatis.version} 23 | 24 | 25 | org.mybatis 26 | mybatis-spring 27 | ${mybatis-spring.version} 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/main/java/com/jachs/springmybatis/dao/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.dao; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | 5 | import com.jachs.springmybatis.entity.Computer; 6 | 7 | @Mapper 8 | public interface ComputerMapper { 9 | int deleteByPrimaryKey(String computerid); 10 | 11 | int insert(Computer record); 12 | 13 | int insertSelective(Computer record); 14 | 15 | Computer selectByPrimaryKey(String computerid); 16 | 17 | int updateByPrimaryKeySelective(Computer record); 18 | 19 | int updateByPrimaryKey(Computer record); 20 | } -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/main/java/com/jachs/springmybatis/dao/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.dao; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | 5 | import com.jachs.springmybatis.entity.Software; 6 | 7 | @Mapper 8 | public interface SoftwareMapper { 9 | int deleteByPrimaryKey(String softwareid); 10 | 11 | int insert(Software record); 12 | 13 | int insertSelective(Software record); 14 | 15 | Software selectByPrimaryKey(String softwareid); 16 | 17 | int updateByPrimaryKeySelective(Software record); 18 | 19 | int updateByPrimaryKey(Software record); 20 | } -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/main/java/com/jachs/springmybatis/entity/Computer.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Computer implements Serializable { 7 | private String computerid; 8 | 9 | private String computername; 10 | 11 | private Long computerprice; 12 | 13 | private Date madetime; 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | public String getComputerid() { 18 | return computerid; 19 | } 20 | 21 | public void setComputerid(String computerid) { 22 | this.computerid = computerid == null ? null : computerid.trim(); 23 | } 24 | 25 | public String getComputername() { 26 | return computername; 27 | } 28 | 29 | public void setComputername(String computername) { 30 | this.computername = computername == null ? null : computername.trim(); 31 | } 32 | 33 | public Long getComputerprice() { 34 | return computerprice; 35 | } 36 | 37 | public void setComputerprice(Long computerprice) { 38 | this.computerprice = computerprice; 39 | } 40 | 41 | public Date getMadetime() { 42 | return madetime; 43 | } 44 | 45 | public void setMadetime(Date madetime) { 46 | this.madetime = madetime; 47 | } 48 | } -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/main/java/com/jachs/springmybatis/entity/Software.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Software implements Serializable { 6 | private String softwareid; 7 | 8 | private String softwarename; 9 | 10 | private String cfkid; 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | public String getSoftwareid() { 15 | return softwareid; 16 | } 17 | 18 | public void setSoftwareid(String softwareid) { 19 | this.softwareid = softwareid == null ? null : softwareid.trim(); 20 | } 21 | 22 | public String getSoftwarename() { 23 | return softwarename; 24 | } 25 | 26 | public void setSoftwarename(String softwarename) { 27 | this.softwarename = softwarename == null ? null : softwarename.trim(); 28 | } 29 | 30 | public String getCfkid() { 31 | return cfkid; 32 | } 33 | 34 | public void setCfkid(String cfkid) { 35 | this.cfkid = cfkid == null ? null : cfkid.trim(); 36 | } 37 | } -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.url=jdbc:mysql://127.0.0.1:3306/jpatest?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC 2 | jdbc.username=root 3 | jdbc.password=123456 -------------------------------------------------------------------------------- /spring-mybatis/spring-mybatis-xml/src/test/java/com/jachs/springmybatis/ComputerMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.jachs.springmybatis; 2 | 3 | import java.util.Date; 4 | import java.util.Locale; 5 | 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | import com.github.javafaker.Faker; 13 | import com.jachs.springmybatis.dao.ComputerMapper; 14 | import com.jachs.springmybatis.entity.Computer; 15 | 16 | /** 17 | * 18 | * @author zhanchaohan 19 | * 20 | */ 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @ContextConfiguration(locations = {"classpath:/spring.xml"}) 23 | public class ComputerMapperTest { 24 | private static Faker FAKER = new Faker(Locale.CHINA); 25 | @Autowired 26 | private ComputerMapper computerMapper; 27 | 28 | @Test 29 | public void t1() { 30 | Computer cp=new Computer(); 31 | 32 | cp.setComputerid(FAKER.app().author()); 33 | cp.setComputername(FAKER.company().name()); 34 | cp.setComputerprice(FAKER.number().randomNumber()); 35 | cp.setMadetime(new Date()); 36 | computerMapper.insert(cp); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xml/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.jachs 6 | xml 7 | 1.0 8 | jar 9 | 10 | xml 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | mysql 20 | mysql-connector-java 21 | 8.0.32 22 | 23 | 24 | 25 | org.mybatis 26 | mybatis 27 | 3.5.15 28 | 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | 1.18.32 34 | 35 | 36 | 37 | junit 38 | junit 39 | 4.13.1 40 | 41 | 42 | 43 | ch.qos.logback 44 | logback-classic 45 | 1.5.3 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/App.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.apache.ibatis.io.Resources; 7 | import org.apache.ibatis.session.SqlSession; 8 | import org.apache.ibatis.session.SqlSessionFactory; 9 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 10 | 11 | import com.jachs.xml.entity.Exam; 12 | 13 | /*** 14 | * 15 | * @author zhanchaohan 16 | * 17 | */ 18 | public class App{ 19 | 20 | public static void main( String[] args ) throws Exception{ 21 | Exam ex=new Exam(); 22 | ex.setExamId ( 2 ); 23 | ex.setExamName ( "peter" ); 24 | ex.setScore ( 12.12 ); 25 | 26 | SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder(); 27 | 28 | InputStream is=App.class.getResourceAsStream ( "configer/mybatis-config.xml" ); 29 | 30 | // SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(is); 31 | // SqlSession sqlSession = sqlSessionFactory.openSession(true); 32 | // int count = sqlSession.insert("insertExam", ex); 33 | // System.out.println("插入了几条记录:" + count); 34 | 35 | // 使用指定数据库 36 | SqlSessionFactory sqlSessionFactory1 = sqlSessionFactoryBuilder.build(is, "pro"); 37 | SqlSession sqlSession1 = sqlSessionFactory1.openSession(true); 38 | int count1 = sqlSession1.insert("insertExam", ex); 39 | System.out.println("插入了几条记录:" + count1); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/configer/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/entity/Computer.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml.entity; 2 | 3 | import java.util.Date; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /*** 10 | * 11 | * @author zhanchaohan 12 | * 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class Computer { 18 | private String computerId; 19 | private String computerName; 20 | private Long computerPrice; 21 | private Date madeTime; 22 | } 23 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/entity/Exam.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /*** 8 | * 9 | * @author zhanchaohan 10 | * 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class Exam { 16 | int examId; 17 | String examName; 18 | double score; 19 | } 20 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/entity/Software.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /**** 8 | * 9 | * @author zhanchaohan 10 | * 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class Software { 16 | private String softWareId; 17 | private String cId; 18 | private String softWareName; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/mapper/ComputerMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml.mapper; 2 | 3 | import com.jachs.xml.entity.Computer; 4 | 5 | public interface ComputerMapper { 6 | public int insertComputer(Computer cp); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/mapper/SoftwareMapper.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml.mapper; 2 | 3 | import org.apache.ibatis.annotations.Select; 4 | 5 | import com.jachs.xml.entity.Software; 6 | 7 | /*** 8 | * 9 | * @author zhanchaohan 10 | * 11 | */ 12 | public interface SoftwareMapper { 13 | @Select("SELECT * FROM software where softWareId=#{softWareId}") 14 | Software selectBlog(String softWareId); 15 | } 16 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/xml/ComputerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | insert into computer(computerId,computerName,computerPrice,madeTime) 9 | values(#{computerId},#{computerName},#{computerPrice},#{madeTime}) 10 | 11 | 12 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/xml/ExamMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | insert into exam(examId,examName,score) values(#{examId},#{examName},#{score}) 10 | 11 | 12 | 15 | 16 | 19 | -------------------------------------------------------------------------------- /xml/src/main/java/com/jachs/xml/xml/SoftwareMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /xml/src/main/java/readme: -------------------------------------------------------------------------------- 1 | https://mybatis.org/mybatis-3/zh_CN/configuration.html 2 | 3 | -------------------------------------------------------------------------------- /xml/src/test/java/com/jachs/xml/Annotation.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.apache.ibatis.session.SqlSessionFactory; 7 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | import com.jachs.xml.entity.Software; 12 | import com.jachs.xml.mapper.SoftwareMapper; 13 | 14 | /*** 15 | * 16 | * @author zhanchaohan 17 | * 18 | */ 19 | public class Annotation { 20 | SqlSession sqlSession; 21 | 22 | @Before 23 | public void init() { 24 | InputStream is=App.class.getResourceAsStream ( "configer/mybatis-config.xml" ); 25 | SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder(); 26 | SqlSessionFactory sqlSessionFactory1 = sqlSessionFactoryBuilder.build(is, "development"); 27 | sqlSession = sqlSessionFactory1.openSession(true); 28 | } 29 | 30 | @Test 31 | public void t1() { 32 | SoftwareMapper mapper=sqlSession.getMapper ( SoftwareMapper.class ); 33 | 34 | Software sw= mapper.selectBlog ( "QMT" ); 35 | 36 | System.out.println ( sw.toString () ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xml/src/test/java/com/jachs/xml/Mapper1.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml; 2 | 3 | import java.io.InputStream; 4 | import java.util.Date; 5 | 6 | import org.apache.ibatis.session.SqlSession; 7 | import org.apache.ibatis.session.SqlSessionFactory; 8 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import com.jachs.xml.entity.Computer; 13 | import com.jachs.xml.mapper.ComputerMapper; 14 | 15 | /*** 16 | * 17 | * @author zhanchaohan 18 | * 19 | */ 20 | public class Mapper1 { 21 | public static String namespace = "com.jachs.xml.xml.ExamMapper"; 22 | 23 | SqlSession sqlSession; 24 | 25 | @Before 26 | public void init() { 27 | InputStream is=App.class.getResourceAsStream ( "configer/mybatis-config.xml" ); 28 | SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder(); 29 | SqlSessionFactory sqlSessionFactory1 = sqlSessionFactoryBuilder.build(is, "development"); 30 | sqlSession = sqlSessionFactory1.openSession(true); 31 | } 32 | 33 | @Test 34 | public void t1() { 35 | ComputerMapper mapper=sqlSession.getMapper ( ComputerMapper.class ); 36 | 37 | Computer cp=new Computer(); 38 | 39 | cp.setComputerId ("mcjk"); 40 | cp.setComputerName ( "AKIC" ); 41 | cp.setComputerPrice ( 18266L ); 42 | cp.setMadeTime ( new Date()); 43 | 44 | int count= mapper.insertComputer ( cp ); 45 | 46 | System.out.println ( count ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /xml/src/test/java/com/jachs/xml/Select1.java: -------------------------------------------------------------------------------- 1 | package com.jachs.xml; 2 | 3 | import java.io.InputStream; 4 | import java.util.List; 5 | 6 | import org.apache.ibatis.session.SqlSession; 7 | import org.apache.ibatis.session.SqlSessionFactory; 8 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import com.jachs.xml.entity.Exam; 13 | 14 | 15 | /*** 16 | * 17 | * @author zhanchaohan 18 | * 19 | */ 20 | public class Select1 { 21 | public static String namespace = "com.jachs.xml.xml.ExamMapper"; 22 | 23 | SqlSession sqlSession; 24 | 25 | @Before 26 | public void init() { 27 | InputStream is=App.class.getResourceAsStream ( "configer/mybatis-config.xml" ); 28 | SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder(); 29 | SqlSessionFactory sqlSessionFactory1 = sqlSessionFactoryBuilder.build(is, "development"); 30 | sqlSession = sqlSessionFactory1.openSession(true); 31 | } 32 | 33 | @Test 34 | public void t1() { 35 | Exam exam=sqlSession.selectOne("exam.selectExam", 2 ); 36 | 37 | System.out.println ( exam.getExamId ()+"\t\t"+exam.getExamName ()+"\t\t"+exam.getScore () ); 38 | } 39 | 40 | @Test 41 | public void t2() { 42 | List emps = sqlSession.selectList("exam.findAll"); 43 | 44 | for ( Exam exam : emps ) { 45 | System.out.println ( exam.getExamId ()+"\t\t"+exam.getExamName ()+"\t\t"+exam.getScore () ); 46 | } 47 | } 48 | } 49 | --------------------------------------------------------------------------------