├── .gitignore ├── LICENSE ├── README.md ├── kingson-springboot-starter ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── springboot │ │ └── learn │ │ ├── config │ │ └── KingsonProperties.java │ │ ├── configuration │ │ └── KingsonAutoConfiguration.java │ │ └── service │ │ └── KingsonService.java │ └── resources │ ├── META-INF │ └── spring.factories │ └── kingson.properties ├── springboot-aop ├── .gitignore ├── READEME.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootaop │ │ │ ├── SpringbootAopApplication.java │ │ │ ├── aspects │ │ │ └── MyAspect.java │ │ │ ├── controller │ │ │ └── AOPController.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImp.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── springbootaop │ └── SpringbootAopApplicationTests.java ├── springboot-cache ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootcache │ │ │ ├── SpringbootCacheApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── utils │ │ │ └── MyCacheManager.java │ └── resources │ │ ├── application.yml │ │ ├── ehcache │ │ └── ehcache.xml │ │ └── mybatis │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootcache │ └── SpringbootCacheApplicationTests.java ├── springboot-druid-multsource ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootdruidmultsource │ │ │ ├── SpringbootDruidMultsourceApplication.java │ │ │ ├── config │ │ │ └── ds │ │ │ │ ├── MasterDataSourcesConfig.java │ │ │ │ └── SlaveDataSourcesConfig.java │ │ │ ├── domain │ │ │ ├── master │ │ │ │ └── SysUser.java │ │ │ └── slave │ │ │ │ └── User.java │ │ │ ├── mapper │ │ │ ├── master │ │ │ │ └── SysUserMapper.java │ │ │ └── slave │ │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── SysUserService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ ├── SysUserServiceImpl.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application-druid.yml │ │ ├── application.yml │ │ └── mybatis │ │ ├── master │ │ └── userMapper.xml │ │ └── slave │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootdruidmultsource │ └── SpringbootDruidMultsourceApplicationTests.java ├── springboot-druid ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootdruid │ │ │ ├── SpringbootDruidApplication.java │ │ │ ├── config │ │ │ └── DruidConfig.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mybatis │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootdruid │ └── SpringbootDruidApplicationTests.java ├── springboot-freemarker ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootfreemarker │ │ │ ├── ServletInitializer.java │ │ │ ├── SpringbootFreemarkerApplication.java │ │ │ ├── config │ │ │ └── FreeMarkerConfig.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── tags │ │ │ └── directive │ │ │ │ └── MyTagDirective.java │ │ │ └── utils │ │ │ └── FreeMarkerTemplateUtil.java │ └── resources │ │ ├── application.properties │ │ ├── ftl │ │ └── reg.ftl │ │ └── templates │ │ └── index.ftl │ └── test │ └── java │ └── com │ └── example │ └── springbootfreemarker │ └── SpringbootFreemarkerApplicationTests.java ├── springboot-i18n ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbooti18n │ │ │ ├── SpringbootI18nApplication.java │ │ │ ├── config │ │ │ └── I18nConfig.java │ │ │ ├── consts │ │ │ └── CommonConsts.java │ │ │ ├── controller │ │ │ └── HelloController.java │ │ │ └── utils │ │ │ └── MessagesUtil.java │ └── resources │ │ ├── application.yml │ │ ├── i18n │ │ ├── messages.properties │ │ ├── messages_en_US.properties │ │ └── messages_zh_CN.properties │ │ ├── static │ │ └── js │ │ │ ├── hello.js │ │ │ └── jquery.min.js │ │ └── templates │ │ └── hello.html │ └── test │ └── java │ └── com │ └── example │ └── springbooti18n │ └── SpringbootI18nApplicationTests.java ├── springboot-jpa ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootjpa │ │ │ ├── SpringbootJpaApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── repository │ │ │ ├── BaseRepository.java │ │ │ ├── UserRepository.java │ │ │ ├── factory │ │ │ │ └── BaseRepositoryFactoryBean.java │ │ │ └── impl │ │ │ │ ├── BaseRepositoryImpl.java │ │ │ │ └── BaseRepositoryImplBak.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── example │ └── springbootjpa │ └── SpringbootJpaApplicationTests.java ├── springboot-listener ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── springbootlistener │ │ ├── SpringbootListenerApplication.java │ │ ├── controller │ │ └── MyApplicationEventController.java │ │ ├── domain │ │ ├── LogPojo.java │ │ └── LogPojo2.java │ │ ├── event │ │ ├── MyApplicationEvent.java │ │ └── MyApplicationEvent2.java │ │ └── listener │ │ ├── MyApplicationContextInitializer.java │ │ ├── MyApplicationListener.java │ │ ├── MyApplicationListener2.java │ │ ├── MyApplicationListener3.java │ │ ├── MyApplicationRunner.java │ │ ├── MyApplicationRunner2.java │ │ ├── MyCommandRunner.java │ │ ├── MyCommandRunner2.java │ │ └── MySpringApplicationRunListener.java │ └── resources │ ├── META-INF │ └── spring.factories │ └── application.properties ├── springboot-log4j ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootlog4j │ │ │ ├── SpringbootLog4jApplication.java │ │ │ └── controller │ │ │ └── TestController.java │ └── resources │ │ ├── application.properties │ │ ├── log4j2.xml │ │ └── log4j2.yml │ └── test │ └── java │ └── com │ └── example │ └── springbootlog4j │ └── SpringbootLog4jApplicationTests.java ├── springboot-mybatis-mycat ├── .gitignore ├── README.md ├── doc │ └── springboot.sql ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootmybatismycat │ │ │ ├── SpringbootMybatisMycatApplication.java │ │ │ ├── controller │ │ │ ├── CompanyController.java │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ ├── Company.java │ │ │ └── User.java │ │ │ ├── mapper │ │ │ ├── CompanyMapper.java │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── CompanyService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ ├── CompanyServiceImpl.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mybatis │ │ ├── companyMapper.xml │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootmybatismycat │ └── SpringbootMybatisMycatApplicationTests.java ├── springboot-mybatis ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootmybatis │ │ │ ├── SpringbootMybatisApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mybatis │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootmybatis │ └── SpringbootMybatisApplicationTests.java ├── springboot-pagehelper ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootpagehelper │ │ │ ├── SpringbootPagehelperApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mybatis │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springbootpagehelper │ └── SpringbootPagehelperApplicationTests.java ├── springboot-rabbitmq ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootrabbitmq │ │ │ ├── SpringbootRabbitmqApplication.java │ │ │ ├── config │ │ │ ├── RabbitMqConfig.java │ │ │ ├── RabbitMqFanoutACKConfig.java │ │ │ └── RabbitMqTopicConfig.java │ │ │ ├── controller │ │ │ └── SendController.java │ │ │ ├── domain │ │ │ └── MessageObj.java │ │ │ ├── receive │ │ │ ├── MyAckReceiver.java │ │ │ ├── MyAckReceiver2.java │ │ │ ├── MyReceiver1.java │ │ │ ├── MyReceiver2.java │ │ │ ├── MyReceiver3.java │ │ │ ├── MyTopicReceiver1.java │ │ │ └── MyTopicReceiver2.java │ │ │ ├── service │ │ │ ├── AckSenderService.java │ │ │ ├── ConfirmService.java │ │ │ └── TransactionService.java │ │ │ └── utils │ │ │ └── RabbitMqConnFactoryUtil.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── springbootrabbitmq │ └── SpringbootRabbitmqApplicationTests.java ├── springboot-redis-cluster ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootrediscluster │ │ │ ├── SpringbootRedisClusterApplication.java │ │ │ └── config │ │ │ ├── RedisConfig.java │ │ │ └── client │ │ │ └── RedisClient.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── example │ └── springbootrediscluster │ └── SpringbootRedisClusterApplicationTests.java ├── springboot-redis ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootredis │ │ │ ├── SpringbootRedisApplication.java │ │ │ ├── config │ │ │ ├── JedisConfig.java │ │ │ ├── RedisConfig.java │ │ │ └── client │ │ │ │ └── RedisClient.java │ │ │ └── utils │ │ │ └── redis │ │ │ ├── CommonOperUtil.java │ │ │ ├── HashOperUtil.java │ │ │ ├── ListOperUtil.java │ │ │ ├── SetOperUtil.java │ │ │ ├── StringOperUtil.java │ │ │ └── ZSetOperUtil.java │ └── resources │ │ ├── application.yml │ │ └── config │ │ └── redis.properties │ └── test │ └── java │ └── com │ └── example │ └── springbootredis │ └── SpringbootRedisApplicationTests.java ├── springboot-rpc ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootrpc │ │ │ ├── SpringbootRpcApplication.java │ │ │ ├── annotation │ │ │ └── RpcService.java │ │ │ ├── channelhandel │ │ │ ├── RpcDecoder.java │ │ │ └── RpcEncoder.java │ │ │ ├── client │ │ │ ├── AsyncRpcCallback.java │ │ │ ├── ConnectManage.java │ │ │ ├── RpcClient.java │ │ │ ├── RpcClientHandler.java │ │ │ ├── RpcClientInitializer.java │ │ │ ├── RpcFuture.java │ │ │ └── proxy │ │ │ │ ├── IAsyncObjectProxy.java │ │ │ │ └── ObjectProxy.java │ │ │ ├── controller │ │ │ └── SpringbootRpcController.java │ │ │ ├── model │ │ │ ├── RpcRequest.java │ │ │ └── RpcResponse.java │ │ │ ├── registry │ │ │ ├── ServiceDiscovery.java │ │ │ └── ServiceRegistry.java │ │ │ ├── runner │ │ │ ├── BaseZookeeper.java │ │ │ ├── MyAppRunner.java │ │ │ ├── MyRunner.java │ │ │ └── MyRunner2.java │ │ │ ├── server │ │ │ ├── RpcServer.java │ │ │ ├── RpcServerHandler.java │ │ │ └── RpcServerInitializer.java │ │ │ └── utils │ │ │ ├── JsonUtil.java │ │ │ └── SerializationUtil.java │ └── resources │ │ └── rpc.properties │ └── test │ ├── java │ └── com │ │ └── example │ │ └── springbootrpc │ │ ├── SpringbootRpcApplicationTests.java │ │ ├── client │ │ └── Person.java │ │ └── server │ │ └── HelloServiceImpl.java │ └── resources │ └── rpc.properties ├── springboot-scheduled ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootscheduled │ │ │ ├── SpringbootScheduledApplication.java │ │ │ ├── config │ │ │ ├── AsyncScheduledConfig.java │ │ │ └── QuartzConfig.java │ │ │ ├── quartz │ │ │ └── TestQuartz.java │ │ │ └── timer │ │ │ ├── AsyncScheduledTest.java │ │ │ ├── ScheduledTest.java │ │ │ └── TimerTest.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── springbootscheduled │ └── SpringbootScheduledTestApplicationTests.java ├── springboot-shiro ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── doc │ └── shiro.sql │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootshiro │ │ │ ├── ServletInitializer.java │ │ │ ├── SpringbootShiroApplication.java │ │ │ ├── config │ │ │ ├── ErrorPagesConfig.java │ │ │ ├── FreeMarkerConfig.java │ │ │ ├── ShiroConfig.java │ │ │ └── WebMvcConfig.java │ │ │ ├── constants │ │ │ └── CommonConstants.java │ │ │ ├── controller │ │ │ ├── ErrorPagesController.java │ │ │ ├── ExceptionHandleController.java │ │ │ ├── IndexController.java │ │ │ ├── LoginController.java │ │ │ ├── RenderController.java │ │ │ ├── ResourcesController.java │ │ │ ├── RoleController.java │ │ │ ├── TestController.java │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ ├── SysResources.java │ │ │ ├── SysRole.java │ │ │ ├── SysRoleResources.java │ │ │ ├── SysUser.java │ │ │ ├── SysUserRole.java │ │ │ └── vo │ │ │ │ ├── BaseConditionVO.java │ │ │ │ ├── PageResult.java │ │ │ │ ├── ResourceConditionVO.java │ │ │ │ ├── Resources.java │ │ │ │ ├── ResponseVO.java │ │ │ │ ├── Role.java │ │ │ │ ├── RoleConditionVO.java │ │ │ │ ├── RoleResources.java │ │ │ │ ├── User.java │ │ │ │ ├── UserConditionVO.java │ │ │ │ └── UserRole.java │ │ │ ├── enums │ │ │ ├── ResourceTypeEnum.java │ │ │ ├── ResponseStatusEnum.java │ │ │ ├── UserGenderEnum.java │ │ │ ├── UserStatusEnum.java │ │ │ └── UserTypeEnum.java │ │ │ ├── holder │ │ │ ├── RequestHolder.java │ │ │ └── SpringContextHolder.java │ │ │ ├── interceptor │ │ │ └── RememberAuthenticationInterceptor.java │ │ │ ├── mapper │ │ │ ├── SysResourceMapper.java │ │ │ ├── SysRoleMapper.java │ │ │ ├── SysRoleResourcesMapper.java │ │ │ ├── SysUserMapper.java │ │ │ └── SysUserRoleMapper.java │ │ │ ├── plugin │ │ │ └── BaseMapper.java │ │ │ ├── service │ │ │ ├── AbstractService.java │ │ │ ├── SysResourcesService.java │ │ │ ├── SysRoleResourcesService.java │ │ │ ├── SysRoleService.java │ │ │ ├── SysUserRoleService.java │ │ │ ├── SysUserService.java │ │ │ └── impl │ │ │ │ ├── SysResourcesServiceImpl.java │ │ │ │ ├── SysRoleResourcesServiceImpl.java │ │ │ │ ├── SysRoleServiceImpl.java │ │ │ │ ├── SysUserRoleServiceImpl.java │ │ │ │ └── SysUserServiceImpl.java │ │ │ ├── shiro │ │ │ ├── credentials │ │ │ │ ├── CredentialsMatcher.java │ │ │ │ └── RetryLimitCredentialsMatcher.java │ │ │ └── realm │ │ │ │ └── UserRealm.java │ │ │ ├── tags │ │ │ └── CustomTagDirective.java │ │ │ └── utils │ │ │ ├── AesUtil.java │ │ │ ├── IpUtil.java │ │ │ ├── Md5Util.java │ │ │ ├── PasswordUtil.java │ │ │ └── ResultUtil.java │ └── resources │ │ ├── application.yml │ │ ├── ehcache │ │ └── ehcache-shiro.xml │ │ ├── logback.xml │ │ ├── mybatis │ │ ├── SysResourceMapper.xml │ │ ├── SysRoleMapper.xml │ │ ├── SysUserMapper.xml │ │ └── SysUserRoleMapper.xml │ │ ├── static │ │ └── assets │ │ │ ├── css │ │ │ ├── jquery-confirm.min.css │ │ │ └── shiro.core.css │ │ │ ├── images │ │ │ ├── back_disabled.png │ │ │ ├── back_enabled.png │ │ │ ├── back_enabled_hover.png │ │ │ ├── chooseImg_N.png │ │ │ ├── chooseImg_S.png │ │ │ ├── favicon.ico │ │ │ ├── favicon.png │ │ │ ├── forward_disabled.png │ │ │ ├── forward_enabled.png │ │ │ ├── forward_enabled_hover.png │ │ │ ├── loading.gif │ │ │ ├── picture.jpg │ │ │ ├── transparent.png │ │ │ ├── upload.png │ │ │ └── user.png │ │ │ └── js │ │ │ ├── jquery-form.js │ │ │ ├── shiro.core.js │ │ │ ├── shiro.table.js │ │ │ ├── shiro.tool.js │ │ │ ├── validator.js │ │ │ └── wangEditor.min.js │ │ └── templates │ │ ├── error │ │ ├── 401.ftl │ │ ├── 403.ftl │ │ ├── 404.ftl │ │ └── 500.ftl │ │ ├── index.ftl │ │ ├── layout │ │ ├── footer.ftl │ │ ├── header.ftl │ │ ├── setting.ftl │ │ └── sidebar.ftl │ │ ├── login.ftl │ │ ├── resources │ │ └── list.ftl │ │ ├── role │ │ └── list.ftl │ │ └── user │ │ └── list.ftl │ └── test │ └── java │ └── com │ └── example │ └── springbootshiro │ └── SpringbootShiroApplicationTests.java ├── springboot-start ├── .gitignore ├── README.md ├── doc │ └── 新建springboot项目过程.doc ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootstart │ │ │ ├── SpringbootStartApplication.java │ │ │ └── controller │ │ │ └── StartController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── springbootstart │ └── SpringbootStartApplicationTests.java ├── springboot-storage ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootqiniu │ │ │ ├── SpringbootStorageApplication.java │ │ │ └── storage │ │ │ ├── AliOssStorage.java │ │ │ └── QiNiuStorage.java │ └── resources │ │ ├── application.yml │ │ └── static │ │ └── images │ │ └── user.png │ └── test │ └── java │ └── com │ └── example │ └── springbootqiniu │ └── SpringbootStorageApplicationTests.java ├── springboot-swagger ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootswagger │ │ │ ├── ServletInitializer.java │ │ │ ├── SpringbootSwaggerApplication.java │ │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ └── SwaggerController.java │ │ │ └── domain │ │ │ └── User.java │ └── resources │ │ ├── application.properties │ │ └── banner.txt │ └── test │ └── java │ └── com │ └── example │ └── springbootswagger │ └── SpringbootSwaggerApplicationTests.java ├── springboot-thymeleaf ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootthymeleaf │ │ │ ├── ServletInitializer.java │ │ │ ├── SpringbootThymeleafApplication.java │ │ │ ├── config │ │ │ └── WebMvcConfig.java │ │ │ └── controller │ │ │ └── IndexController.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ └── css │ │ │ └── style.css │ │ └── templates │ │ ├── hello.html │ │ └── index.html │ └── test │ └── java │ └── com │ └── example │ └── springbootthymeleaf │ └── SpringbootThymeleafApplicationTests.java ├── springboot-transactional ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springboottransactional │ │ │ ├── SpringbootTransactionalApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mybatis │ │ └── userMapper.xml │ └── test │ └── java │ └── com │ └── example │ └── springboottransactional │ └── SpringbootTransactionalApplicationTests.java ├── springboot-webservice ├── .gitignore ├── README.md ├── XSD详解.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springbootwebservice │ │ │ ├── SpringbootWebserviceApplication.java │ │ │ ├── config │ │ │ ├── WSConfig.java │ │ │ ├── WebServiceConfig.java │ │ │ └── client │ │ │ │ └── WsClient.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── domain │ │ │ ├── Country.java │ │ │ ├── Currency.java │ │ │ ├── GetCountryRequest.java │ │ │ ├── GetCountryResponse.java │ │ │ ├── ObjectFactory.java │ │ │ └── countries.xsd │ │ │ ├── endpoint │ │ │ └── CountryEndpoint.java │ │ │ └── resp │ │ │ └── CountryRepository.java │ └── resources │ │ ├── application.properties │ │ ├── countries.wsdl │ │ └── countries.xsd │ └── test │ └── java │ └── com │ └── example │ └── springbootwebservice │ └── SpringbootWebserviceApplicationTests.java └── springboot-websocket ├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ └── springbootwebsocket │ │ ├── ServletInitializer.java │ │ ├── SpringbootWebsocketApplication.java │ │ ├── config │ │ └── WebSocketConfig.java │ │ ├── controller │ │ └── WebSocketController.java │ │ ├── domain │ │ └── Message.java │ │ ├── server │ │ ├── AbstractWsController.java │ │ ├── AudioController.java │ │ ├── BaseController.java │ │ ├── BaseMediaController.java │ │ ├── TextController.java │ │ ├── VideoController.java │ │ └── WebSocketServer.java │ │ └── utils │ │ ├── IdGenerator.java │ │ └── StringUtil.java └── resources │ ├── application.properties │ ├── static │ ├── css │ │ └── chat.css │ ├── js │ │ ├── WSClient.js │ │ ├── app.js │ │ ├── chat.js │ │ ├── jquery-1.9.1.js │ │ ├── jquery.nicescroll.min.js │ │ └── media.js │ └── pic │ │ └── websocket │ │ ├── Toolbar.png │ │ ├── btn_close.png │ │ ├── btn_close_down.png │ │ ├── btn_close_hover.png │ │ ├── canvaspost.png │ │ ├── headpic.png │ │ ├── mod_chat.png │ │ ├── mod_file.png │ │ ├── mod_video.png │ │ ├── mod_voice.png │ │ ├── photo_loading.jpg │ │ ├── sprite_main.png │ │ └── videopost.png │ └── templates │ ├── chat.html │ ├── chat2.html │ ├── index.html │ ├── index3.html │ └── ws │ ├── cameraTest.html │ ├── main.html │ ├── microphoneTest1.html │ └── microphoneTest2.html └── test └── java └── com └── example └── springbootwebsocket └── SpringbootWebsocketApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /kingson-springboot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.springboot.learn 8 | kingson-spring-boot-starter 9 | 1.0-SNAPSHOT 10 | spring boot starter demo 11 | 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-autoconfigure 16 | 2.4.1 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /kingson-springboot-starter/src/main/java/com/springboot/learn/config/KingsonProperties.java: -------------------------------------------------------------------------------- 1 | package com.springboot.learn.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.PropertySource; 6 | 7 | /** 8 | * @author 9 | * @Description: 文件描述 10 | * @date 11 | **/ 12 | @Configuration 13 | @ConfigurationProperties(prefix = "kingson") 14 | @PropertySource(value = "classpath:/kingson.properties") 15 | public class KingsonProperties { 16 | 17 | private String username; 18 | 19 | private String password; 20 | 21 | private boolean enabled; 22 | 23 | public String getUsername() { 24 | return username; 25 | } 26 | 27 | public void setUsername(String username) { 28 | this.username = username; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password; 37 | } 38 | 39 | public boolean isEnabled() { 40 | return enabled; 41 | } 42 | 43 | public void setEnabled(boolean enabled) { 44 | this.enabled = enabled; 45 | } 46 | } -------------------------------------------------------------------------------- /kingson-springboot-starter/src/main/java/com/springboot/learn/configuration/KingsonAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.springboot.learn.configuration; 2 | 3 | import com.springboot.learn.config.KingsonProperties; 4 | import com.springboot.learn.service.KingsonService; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 8 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | /** 13 | * @author 14 | * @Description: 文件描述 15 | * @date 16 | **/ 17 | @Configuration 18 | @ConditionalOnClass(KingsonService.class) 19 | @ConditionalOnProperty(prefix = "kingson", value = "enable", matchIfMissing = true) 20 | @EnableConfigurationProperties(KingsonProperties.class) 21 | public class KingsonAutoConfiguration { 22 | 23 | @Bean 24 | @ConditionalOnMissingBean 25 | public KingsonService kingsonGet() { 26 | return new KingsonService(); 27 | } 28 | } -------------------------------------------------------------------------------- /kingson-springboot-starter/src/main/java/com/springboot/learn/service/KingsonService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.learn.service; 2 | 3 | import com.springboot.learn.config.KingsonProperties; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * @author 9 | * @Description: 文件描述 10 | * @date 11 | **/ 12 | @Service 13 | public class KingsonService { 14 | 15 | @Autowired 16 | private KingsonProperties kingsonProperties; 17 | 18 | public String usernameGet() { 19 | return kingsonProperties.getUsername(); 20 | } 21 | 22 | public String passwordGet() { 23 | return kingsonProperties.getPassword(); 24 | } 25 | 26 | public boolean enabledGet() { 27 | return kingsonProperties.isEnabled(); 28 | } 29 | 30 | public String userGet() { 31 | if (kingsonProperties.isEnabled()) { 32 | return kingsonProperties.getUsername() + " - " + kingsonProperties.getPassword(); 33 | } 34 | 35 | return kingsonProperties.getUsername(); 36 | } 37 | } -------------------------------------------------------------------------------- /kingson-springboot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.springboot.learn.configuration.KingsonAutoConfiguration -------------------------------------------------------------------------------- /kingson-springboot-starter/src/main/resources/kingson.properties: -------------------------------------------------------------------------------- 1 | kingson.username=kingson 2 | kingson.password=111111 3 | kingson.enabled=true -------------------------------------------------------------------------------- /springboot-aop/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-aop/src/main/java/com/example/springbootaop/SpringbootAopApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootaop; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootAopApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootAopApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-aop/src/main/java/com/example/springbootaop/controller/AOPController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootaop.controller; 2 | 3 | import com.example.springbootaop.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/4/10 13 | * @time: 21:46 14 | * @modifier: 15 | * @since: 16 | */ 17 | @RestController 18 | public class AOPController { 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @RequestMapping(value = "/addUser") 24 | public void addUser() { 25 | userService.addUser(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-aop/src/main/java/com/example/springbootaop/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootaop.service; 2 | 3 | public interface UserService { 4 | 5 | int addUser(); 6 | 7 | void updateUser(); 8 | 9 | void deleteUser(); 10 | 11 | void findUser(); 12 | } -------------------------------------------------------------------------------- /springboot-aop/src/main/java/com/example/springbootaop/service/impl/UserServiceImp.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootaop.service.impl; 2 | 3 | import com.example.springbootaop.service.UserService; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public class UserServiceImp implements UserService { 8 | @Override 9 | public int addUser() { 10 | System.out.println("add user ......"); 11 | return 6666; 12 | } 13 | 14 | @Override 15 | public void updateUser() { 16 | System.out.println("update user ......"); 17 | } 18 | 19 | @Override 20 | public void deleteUser() { 21 | System.out.println("delete user ......"); 22 | } 23 | 24 | @Override 25 | public void findUser() { 26 | System.out.println("find user ......"); 27 | } 28 | } -------------------------------------------------------------------------------- /springboot-aop/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | -------------------------------------------------------------------------------- /springboot-aop/src/test/java/com/example/springbootaop/SpringbootAopApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootaop; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootAopApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-cache/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-cache/src/main/java/com/example/springbootcache/SpringbootCacheApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache; 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.cache.annotation.EnableCaching; 7 | 8 | @SpringBootApplication 9 | @MapperScan(basePackages = {"com.example.springbootcache.mapper"}) 10 | //启用cache缓存 11 | @EnableCaching 12 | public class SpringbootCacheApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringbootCacheApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-cache/src/main/java/com/example/springbootcache/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache.domain; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/1/31 10 | * @time: 21:42 11 | * @modifier: 12 | * @since: 13 | */ 14 | //@Data 15 | public class User { 16 | 17 | private Integer userId; 18 | 19 | private String userName; 20 | 21 | public Integer getUserId() { 22 | return userId; 23 | } 24 | 25 | public void setUserId(Integer userId) { 26 | this.userId = userId; 27 | } 28 | 29 | public String getUserName() { 30 | return userName; 31 | } 32 | 33 | public void setUserName(String userName) { 34 | this.userName = userName; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-cache/src/main/java/com/example/springbootcache/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache.mapper; 2 | 3 | import com.example.springbootcache.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserMapper { 17 | 18 | List selectUserList(); 19 | 20 | User selectUserById(final Integer id); 21 | 22 | void delete(final Integer id); 23 | 24 | void update(final User user); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-cache/src/main/java/com/example/springbootcache/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache.service; 2 | 3 | import com.example.springbootcache.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | 20 | User selectUserById(final Integer id); 21 | 22 | void delete(final Integer id); 23 | 24 | void update(final User user); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-cache/src/main/java/com/example/springbootcache/utils/MyCacheManager.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache.utils; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/2/21 8 | * @time: 14:24 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class MyCacheManager { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /springboot-cache/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #设置应用端口 2 | server: 3 | port: 8080 4 | 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | cache: 12 | #ehcache配置文件路径 13 | ehcache: 14 | config: classpath:/ehcache/ehcache.xml 15 | #指定缓存类型,可加可不加 16 | # type: ehcache 17 | 18 | # MyBatis 19 | mybatis: 20 | type-aliases-package: com.example.springbootcache.domain 21 | mapper-locations: classpath:/mybatis/*.xml 22 | #sql打印配置 23 | configuration: 24 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 25 | -------------------------------------------------------------------------------- /springboot-cache/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 19 | 20 | 21 | update user set user_name = #{userName} where user_id = #{userId} 22 | 23 | 24 | 25 | delete from user where user_id = #{id} 26 | 27 | 28 | -------------------------------------------------------------------------------- /springboot-cache/src/test/java/com/example/springbootcache/SpringbootCacheApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootcache; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class SpringbootCacheApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | @Before 19 | public void before() { 20 | System.out.println("before test"); 21 | } 22 | 23 | @After 24 | public void after() { 25 | System.out.println("after test"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-druid-multsource/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/SpringbootDruidMultsourceApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootDruidMultsourceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootDruidMultsourceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/domain/master/SysUser.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.domain.master; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/1/31 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class SysUser { 13 | 14 | private Integer userId; 15 | 16 | private String userName; 17 | 18 | public Integer getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(Integer userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/domain/slave/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.domain.slave; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/1/31 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class User { 13 | 14 | private Integer userId; 15 | 16 | private String userName; 17 | 18 | public Integer getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(Integer userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/mapper/master/SysUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.mapper.master; 2 | 3 | import com.example.springbootdruidmultsource.domain.master.SysUser; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 21:43 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Mapper 18 | public interface SysUserMapper { 19 | 20 | List selectUserList(); 21 | 22 | void update(SysUser sysUser); 23 | } 24 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/mapper/slave/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.mapper.slave; 2 | 3 | import com.example.springbootdruidmultsource.domain.slave.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 21:43 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Mapper 18 | public interface UserMapper { 19 | 20 | List selectUserList(); 21 | 22 | void update(User user); 23 | } 24 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.service; 2 | 3 | import com.example.springbootdruidmultsource.domain.master.SysUser; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface SysUserService { 17 | 18 | List listUser(); 19 | 20 | void update(SysUser sysUser); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.service; 2 | 3 | import com.example.springbootdruidmultsource.domain.slave.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | 20 | void update(User user); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/service/impl/SysUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.service.impl; 2 | 3 | import com.example.springbootdruidmultsource.domain.master.SysUser; 4 | import com.example.springbootdruidmultsource.mapper.master.SysUserMapper; 5 | import com.example.springbootdruidmultsource.service.SysUserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * descripiton: 14 | * 15 | * @author: kinson(2219945910 @ qq.com) 16 | * @date: 2019/1/31 17 | * @time: 21:56 18 | * @modifier: 19 | * @since: 20 | */ 21 | @Service 22 | public class SysUserServiceImpl implements SysUserService { 23 | 24 | @Autowired 25 | private SysUserMapper sysUserMapper; 26 | 27 | @Override 28 | public List listUser() { 29 | return sysUserMapper.selectUserList(); 30 | } 31 | 32 | @Override 33 | @Transactional 34 | public void update(SysUser sysUser) { 35 | sysUserMapper.update(sysUser); 36 | // int i = 10 / 0; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/java/com/example/springbootdruidmultsource/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruidmultsource.service.impl; 2 | 3 | import com.example.springbootdruidmultsource.domain.slave.User; 4 | import com.example.springbootdruidmultsource.mapper.slave.UserMapper; 5 | import com.example.springbootdruidmultsource.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * descripiton: 14 | * 15 | * @author: kinson(2219945910 @ qq.com) 16 | * @date: 2019/1/31 17 | * @time: 21:56 18 | * @modifier: 19 | * @since: 20 | */ 21 | @Service 22 | public class UserServiceImpl implements UserService { 23 | 24 | @Autowired 25 | private UserMapper userMapper; 26 | 27 | @Override 28 | public List listUser() { 29 | return userMapper.selectUserList(); 30 | } 31 | 32 | @Override 33 | @Transactional(value = "slaveTransactionManager") 34 | public void update(User user) { 35 | userMapper.update(user); 36 | int i = 10 / 0; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/resources/mybatis/master/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | UPDATE user set user_name = #{userName} where user_id = #{userId} 19 | 20 | 21 | -------------------------------------------------------------------------------- /springboot-druid-multsource/src/main/resources/mybatis/slave/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | UPDATE user set user_name = #{userName} where user_id = #{userId} 19 | 20 | 21 | -------------------------------------------------------------------------------- /springboot-druid/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/SpringbootDruidApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid; 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(basePackages = {"com.example.springbootdruid.mapper"}) 9 | public class SpringbootDruidApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootDruidApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid.controller; 2 | 3 | import com.example.springbootdruid.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * descripiton: 11 | * 12 | * @author: kinson(2219945910 @ qq.com) 13 | * @date: 2019/1/31 14 | * @time: 21:58 15 | * @modifier: 16 | * @since: 17 | */ 18 | @RestController 19 | public class UserController { 20 | 21 | @Autowired 22 | private UserService userService; 23 | 24 | @RequestMapping(value = "listUser") 25 | public Object listUser() { 26 | return userService.listUser(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid.domain; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/1/31 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class User { 13 | 14 | private Integer userId; 15 | 16 | private String userName; 17 | 18 | public Integer getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(Integer userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid.mapper; 2 | 3 | import com.example.springbootdruid.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserMapper { 17 | 18 | List selectUserList(); 19 | } 20 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid.service; 2 | 3 | import com.example.springbootdruid.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | } 20 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/example/springbootdruid/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid.service.impl; 2 | 3 | import com.example.springbootdruid.domain.User; 4 | import com.example.springbootdruid.mapper.UserMapper; 5 | import com.example.springbootdruid.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * descripiton: 13 | * 14 | * @author: kinson(2219945910 @ qq.com) 15 | * @date: 2019/1/31 16 | * @time: 21:56 17 | * @modifier: 18 | * @since: 19 | */ 20 | @Service 21 | public class UserServiceImpl implements UserService { 22 | 23 | @Autowired 24 | private UserMapper userMapper; 25 | 26 | @Override 27 | public List listUser() { 28 | return userMapper.selectUserList(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-druid/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /springboot-druid/src/test/java/com/example/springbootdruid/SpringbootDruidApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootdruid; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootDruidApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-freemarker/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/java/com/example/springbootfreemarker/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootfreemarker; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootFreemarkerApplication.class); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/java/com/example/springbootfreemarker/SpringbootFreemarkerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootfreemarker; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootFreemarkerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootFreemarkerApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/java/com/example/springbootfreemarker/config/FreeMarkerConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootfreemarker.config; 2 | 3 | import com.example.springbootfreemarker.tags.directive.MyTagDirective; 4 | import freemarker.template.TemplateModelException; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | /** 11 | * descripiton: 12 | * 13 | * @author: kinson(2219945910 @ qq.com) 14 | * @date: 2019/2/16 15 | * @time: 21:07 16 | * @modifier: 17 | * @since: 18 | */ 19 | @Configuration 20 | public class FreeMarkerConfig { 21 | 22 | @Autowired 23 | private freemarker.template.Configuration configuration; 24 | 25 | @Autowired 26 | private MyTagDirective myTagDirective; 27 | 28 | @PostConstruct //启动时加载 29 | public void setSharedVariable() throws TemplateModelException { 30 | System.out.println("=================初始化自定义tag配置================="); 31 | configuration.setSharedVariable("myTag", myTagDirective); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/java/com/example/springbootfreemarker/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootfreemarker.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.ui.ModelMap; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 18:00 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Controller 18 | public class IndexController { 19 | 20 | @GetMapping(name = "hello") 21 | public String hello(Model model, ModelMap modelMap) { 22 | modelMap.addAttribute("name", "freemarker2"); 23 | // model.addAttribute("name", "freemarker"); 24 | return "index"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-freemarker/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-freemarker/src/main/resources/ftl/reg.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 恭喜您成功注册!您的用户名为:${username} 7 | 8 | -------------------------------------------------------------------------------- /springboot-freemarker/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | hello, ${name}, let's go! 7 | <@myTag tagId = 1 tagName = "mytag"> 8 | <#if myTag??> 9 |

${myTag.tagId},${myTag.tagName}

10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springboot-i18n/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/com/example/springbooti18n/SpringbootI18nApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbooti18n; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootI18nApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootI18nApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/com/example/springbooti18n/consts/CommonConsts.java: -------------------------------------------------------------------------------- 1 | package com.example.springbooti18n.consts; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/2/18 8 | * @time: 17:16 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class CommonConsts { 13 | 14 | public static final String LANG_ZH = "zh"; 15 | public static final String LANG_EN = "en"; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server: 3 | port: 8080 4 | 5 | #i18n 6 | spring: 7 | messages: 8 | encoding: UTF-8 9 | basename: i18n/messages 10 | #设置缓存时长 11 | cache-duration: 3600 12 | thymeleaf: 13 | cache: false 14 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/i18n/messages.properties: -------------------------------------------------------------------------------- 1 | #key/value 当找不到其他语言的配置的时候使用默认的 2 | welcome=欢迎使用i18n(默认) 3 | hello=hello, {0}!(默认) 4 | lang=默认 -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/i18n/messages_en_US.properties: -------------------------------------------------------------------------------- 1 | #key/value 2 | welcome=welcome to use i18n(English) 3 | hello=hello, {0}!(English) 4 | lang=English -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/i18n/messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | #key/value 2 | welcome=欢迎使用i18n(中文) 3 | hello=hello, {0}!(中文) 4 | lang=中文 -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/static/js/hello.js: -------------------------------------------------------------------------------- 1 | $(function () { 2 | $("#locales").change(function () { 3 | var lang = $("#locales").val(); 4 | if (lang != "") { 5 | window.location.replace("/i18n?lang=" + lang); 6 | } 7 | }); 8 | }); -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | hello 6 | 7 | 8 | 9 | 10 |

11 |


12 | 13 | 14 | 19 | 20 |

21 | 点击切换语言: 22 | 简体中文    23 | English(US)
24 | 25 | -------------------------------------------------------------------------------- /springboot-i18n/src/test/java/com/example/springbooti18n/SpringbootI18nApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbooti18n; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootI18nApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-jpa/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/SpringbootJpaApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | //spring在加载的时候找到我们自定义的BaseRepository的工厂 8 | //@EnableJpaRepositories(basePackages = {"com.example.springbootjpa"}, 9 | // repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class) //指定自己的工厂类 10 | public class SpringbootJpaApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringbootJpaApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa.controller; 2 | 3 | import com.example.springbootjpa.domain.User; 4 | import com.example.springbootjpa.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * descripiton: 14 | * 15 | * @author: kinson(2219945910 @ qq.com) 16 | * @date: 2019/2/17 17 | * @time: 14:03 18 | * @modifier: 19 | * @since: 20 | */ 21 | @Controller 22 | public class UserController { 23 | 24 | @Autowired 25 | private UserService userService; 26 | 27 | @GetMapping(value = "listUser") 28 | @ResponseBody 29 | public List listUser() { 30 | User byUserId = userService.findByUserId(1); 31 | User fjw = userService.findUser("hzq"); 32 | return userService.listUser(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa.domain; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | /** 11 | * descripiton: 12 | * 13 | * @author: kinson(2219945910 @ qq.com) 14 | * @date: 2019/2/17 15 | * @time: 14:02 16 | * @modifier: 17 | * @since: 18 | */ 19 | @Entity 20 | @Data 21 | @Table(name = "user") 22 | public class User { 23 | 24 | @Id 25 | @Column(name = "user_id") 26 | private Integer userId; 27 | 28 | @Column(name = "user_name") 29 | private String username; 30 | 31 | @Override 32 | public String toString() { 33 | return String.format( 34 | "User[userId=%d, username='%s']", 35 | userId, username); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/repository/BaseRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.repository.NoRepositoryBean; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | /** 10 | * descripiton: 通用 11 | * 12 | * @author: kinson(2219945910 @ qq.com) 13 | * @date: 2019/2/18 14 | * @time: 22:56 15 | * @modifier: 16 | * @since: 17 | */ 18 | 19 | //在BaseRepository上添加@NoRepositoryBean标注,这样Spring Data Jpa在启动时就不会去实例化BaseRepository这个接口 20 | //@NoRepositoryBean 21 | public interface BaseRepository { 22 | 23 | T findOneBySql(String sql, Class tClass); 24 | 25 | List findAllBySql(String sql, Class clazz); 26 | 27 | List listBySQL(final String sql); 28 | 29 | //基于原生态的sql进行查询 30 | List findUserBySql(final String sql); 31 | 32 | //基于Hibernate的HQL进行查询 33 | List findUserByHql(final String sql); 34 | 35 | //基于Specification的方式进行查询,使用的是CriteriaQuery进行查询 36 | List findUserBySpecification(); 37 | } 38 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa.repository; 2 | 3 | import com.example.springbootjpa.domain.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * descripiton: 12 | * 13 | * @author: kinson(2219945910 @ qq.com) 14 | * @date: 2019/2/17 15 | * @time: 14:06 16 | * @modifier: 17 | * @since: 18 | */ 19 | public interface UserRepository extends JpaRepository { 20 | 21 | /** 22 | * Spring Data JPA 在后台为持久层接口创建代理对象时,会解析方法名字,并实现相应的功能。除了通过方法名字以外,它还可以通过如下两种方式指定查询语句: 23 | * Spring Data JPA 可以访问 JPA 命名查询语句。开发者只需要在定义命名查询语句时,为其指定一个符合给定格式的名字,Spring Data JPA 便会在创建代理对象时,使用该命名查询语句来实现其功能。 24 | * 开发者还可以直接在声明的方法上面使用 25 | * 26 | * @return 27 | */ 28 | 29 | List findAllBy(); 30 | 31 | User findByUserId(Integer userId); 32 | 33 | //@Query 注解,并提供一个查询语句作为参数,Spring Data JPA 在创建代理对象时,便以提供的查询语句来实现其功能。 34 | @Query("from User where user_name = :username") 35 | User findUser(@Param("username") String name); 36 | } 37 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/com/example/springbootjpa/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootjpa.service; 2 | 3 | import com.example.springbootjpa.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/2/17 12 | * @time: 14:13 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | 20 | User findByUserId(Integer userId); 21 | 22 | User findUser(String name); 23 | 24 | List findUsersBySql(final String sql, final Class clazz); 25 | 26 | Object findUserBySql(final String sql, final Class clazz); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | datasource: 5 | driverClassName: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/springboot?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false 7 | username: root 8 | password: root 9 | 10 | #jpa配置 11 | jpa: 12 | database: mysql 13 | show-sql: true 14 | hibernate: 15 | ddl-auto: update 16 | properties: 17 | hibernate.format_sql: true 18 | hibernate.naming.physical-strategy: org.hibernate.config.model.naming.PhysicalNamingStrategyStandardImpl 19 | hibernate.cache.use_second_level_cache: false 20 | hibernate.search.default.directory_provider: filesystem 21 | hibernate.search.default.indexBase: ${user.dir}/indexes -------------------------------------------------------------------------------- /springboot-listener/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-listener/README.md: -------------------------------------------------------------------------------- 1 | # 在Spring框架中提供了两种事件监听的方式: 2 | 3 | 1. 编程式:通过实现ApplicationListener接口来监听指定类型的事件 4 | 5 | * 发布:应用上下文AbstractApplicationContext实际还是通过继承ApplicationEventPublisher接口,实现了其中的事件发布的方法,使得Spring应用上下文有了发布事件的功能,在AbstractApplicationContext内部通过SimpleApplicationEventMulticaster事件发布类,将具体事件ApplicationEvent发布出去。 6 | * 监听:SimpleApplicationEventMulticaster.java中尝试将当前事件逐个广播到指定类型的监听器中(listeners已经根据当前事件类型过滤了) 7 | 2. 注解式:通过在方法上加@EventListener注解的方式监听指定参数类型的事件,写该类需要托管到Spring容器中 8 | * @EventListener注解主要通过EventListenerMethodProcessor扫描出所有带有@EventListener注解的方法,然后动态构造事件监听器,并将监听器托管到Spring应用上文中。 9 | 3. 通过application.properties中配置context.listener.classes属性指定监听器 10 | * 类DelegatingApplicationListener,该类的作用是从application.properties中读取配置context.listener.classes,并将事件广播给这些配置的监听器。 11 | 12 | 13 | # Reference 14 | https://www.cnblogs.com/duanxz/p/11243271.html -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/domain/LogPojo.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author 8 | * @date 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | public class LogPojo { 13 | 14 | private String logName; 15 | 16 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/domain/LogPojo2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.domain; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author 8 | * @date 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | public class LogPojo2 { 13 | 14 | private String logName; 15 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/event/MyApplicationEvent.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.event; 2 | 3 | import com.example.springbootlistener.domain.LogPojo; 4 | import lombok.Getter; 5 | import org.springframework.context.ApplicationEvent; 6 | 7 | /** 8 | * @author 9 | * @date 10 | */ 11 | @Getter 12 | public class MyApplicationEvent extends ApplicationEvent { 13 | 14 | private LogPojo logPojo; 15 | 16 | public MyApplicationEvent(Object source) { 17 | super(source); 18 | } 19 | 20 | public MyApplicationEvent(Object source, LogPojo logPojo) { 21 | super(source); 22 | this.logPojo = logPojo; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/event/MyApplicationEvent2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.event; 2 | 3 | import com.example.springbootlistener.domain.LogPojo2; 4 | import lombok.Getter; 5 | import org.springframework.context.ApplicationEvent; 6 | 7 | /** 8 | * @author 9 | * @date 10 | */ 11 | @Getter 12 | public class MyApplicationEvent2 extends ApplicationEvent { 13 | 14 | private LogPojo2 logPojo; 15 | 16 | public MyApplicationEvent2(Object source) { 17 | super(source); 18 | } 19 | 20 | public MyApplicationEvent2(Object source, LogPojo2 logPojo) { 21 | super(source); 22 | this.logPojo = logPojo; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationContextInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.ApplicationContextInitializer; 5 | import org.springframework.context.ConfigurableApplicationContext; 6 | 7 | /** 8 | * ApplicationContextInitializer IOC容器初始化时被调用 9 | * @author 10 | * @date 11 | */ 12 | @Slf4j 13 | public class MyApplicationContextInitializer implements ApplicationContextInitializer { 14 | @Override 15 | public void initialize(ConfigurableApplicationContext applicationContext) { 16 | log.info("MyApplicationContextInitializer initialize ..." + applicationContext.toString()); 17 | } 18 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationListener.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import com.example.springbootlistener.event.MyApplicationEvent; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.context.ApplicationListener; 6 | import org.springframework.scheduling.annotation.Async; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author 11 | * @date 12 | */ 13 | @Slf4j 14 | @Component 15 | public class MyApplicationListener implements ApplicationListener { 16 | 17 | @Async 18 | @Override 19 | public void onApplicationEvent(MyApplicationEvent myApplicationEvent) { 20 | log.info("MyApplicationListener:" + myApplicationEvent.getLogPojo().getLogName()); 21 | } 22 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationListener2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import com.example.springbootlistener.event.MyApplicationEvent; 4 | import com.example.springbootlistener.event.MyApplicationEvent2; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.context.event.EventListener; 8 | import org.springframework.scheduling.annotation.Async; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author 13 | * @date 14 | */ 15 | @Slf4j 16 | @Component 17 | public class MyApplicationListener2 { 18 | 19 | /** 20 | * @EventListener注解 21 | * 主要通过EventListenerMethodProcessor扫描出所有带有@EventListener注解的方法,然后动态构造事件监听器,并将监听器托管到Spring应用上文中。 22 | * @param myApplicationEvent 23 | */ 24 | @Async 25 | @EventListener 26 | public void onApplicationEvent(MyApplicationEvent2 myApplicationEvent) { 27 | log.info("MyApplicationListener2:" + myApplicationEvent.getLogPojo().getLogName()); 28 | } 29 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationListener3.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import com.example.springbootlistener.event.MyApplicationEvent; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.context.ApplicationListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author 10 | * @date 11 | */ 12 | @Slf4j 13 | //@Component 14 | public class MyApplicationListener3 implements ApplicationListener { 15 | 16 | /** 17 | * @param myApplicationEvent 18 | */ 19 | @Override 20 | public void onApplicationEvent(MyApplicationEvent myApplicationEvent) { 21 | log.info("MyApplicationListener3 :" + myApplicationEvent.getLogPojo().getLogName()); 22 | } 23 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.ApplicationArguments; 5 | import org.springframework.boot.ApplicationRunner; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * ApplicationRunner 容器完成后被调用 11 | * @author 12 | * @date 13 | */ 14 | @Slf4j 15 | @Component 16 | @Order(4) 17 | public class MyApplicationRunner implements ApplicationRunner { 18 | 19 | @Override 20 | public void run(ApplicationArguments args) throws Exception { 21 | log.info("MyApplicationRunner run ..." + args.toString()); 22 | } 23 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyApplicationRunner2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.ApplicationArguments; 5 | import org.springframework.boot.ApplicationRunner; 6 | import org.springframework.core.annotation.Order; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author 11 | * @date 12 | */ 13 | @Slf4j 14 | @Component 15 | @Order(3) 16 | public class MyApplicationRunner2 implements ApplicationRunner { 17 | 18 | @Override 19 | public void run(ApplicationArguments args) throws Exception { 20 | log.info("MyApplicationRunner2 run ..." + args.toString()); 21 | } 22 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyCommandRunner.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * CommandLineRunner ApplicationRunner之后(未设置order)被调用,设置order按order顺序调用 10 | * @author 11 | * @date 12 | */ 13 | @Slf4j 14 | @Component 15 | @Order(2) 16 | public class MyCommandRunner implements CommandLineRunner { 17 | 18 | @Override 19 | public void run(String... args) throws Exception { 20 | log.info("MyCommandRunner run ..." + args.toString()); 21 | } 22 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/java/com/example/springbootlistener/listener/MyCommandRunner2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlistener.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author 10 | * @date 11 | */ 12 | @Slf4j 13 | @Component 14 | @Order(1) 15 | public class MyCommandRunner2 implements CommandLineRunner { 16 | 17 | @Override 18 | public void run(String... args) throws Exception { 19 | log.info("MyCommandRunner2 run ..." + args.toString()); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-listener/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.SpringApplicationRunListener=\ 2 | com.example.springbootlistener.listener.MySpringApplicationRunListener 3 | 4 | org.springframework.context.ApplicationContextInitializer=\ 5 | com.example.springbootlistener.listener.MyApplicationContextInitializer 6 | -------------------------------------------------------------------------------- /springboot-listener/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-listener/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-log4j/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml -------------------------------------------------------------------------------- /springboot-log4j/src/main/java/com/example/springbootlog4j/SpringbootLog4jApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlog4j; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootLog4jApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootLog4jApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-log4j/src/main/java/com/example/springbootlog4j/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlog4j.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910@qq.com) 12 | * @date: 2019/9/15 13 | * @time: 12:29 14 | * @modifier: 15 | * @since: 16 | */ 17 | @RestController 18 | public class TestController { 19 | 20 | private static final Logger logger = LoggerFactory.getLogger(TestController.class); 21 | 22 | @GetMapping(value = "log") 23 | public void test() { 24 | logger.info("123131313"); 25 | logger.debug("123131313"); 26 | logger.warn("123131313"); 27 | logger.error("123131313"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-log4j/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 指定log4j配置文件的位置 2 | logging.config=classpath:log4j2.xml 3 | -------------------------------------------------------------------------------- /springboot-log4j/src/main/resources/log4j2.yml: -------------------------------------------------------------------------------- 1 | #Configuration: 2 | # status: warn 3 | # monitorInterval: 30 4 | # Appenders: 5 | # Console: #输出到控制台 6 | # name: CONSOLE #Appender命名 7 | # target: SYSTEM_OUT 8 | # PatternLayout: 9 | # pattern: "%d{yyyy-MM-dd HH:mm:ss}:%4p %t (%F:%L) - %m%n" 10 | # RollingFile: # 输出到文件,超过256MB归档 11 | # - name: ROLLING_FILE 12 | # ignoreExceptions: false 13 | # fileName: logs/test.log # 这个是日志文件路径名称 14 | # filePattern: "/logs/$${date:yyyy-MM}/test -%d{yyyy-MM-dd}-%i.log.gz" 15 | # PatternLayout: 16 | # pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n" 17 | # Policies: 18 | # SizeBasedTriggeringPolicy: 19 | # size: "2 MB" 20 | # DefaultRolloverStrategy: 21 | # max: 1000 22 | # Loggers: 23 | # Root: 24 | # level: debug 25 | # AppenderRef: 26 | # - ref: CONSOLE 27 | # Logger: #单独设置某些包的输出级别 28 | # - name: com.qisheng.mgjcrm #这个名称一定要是你项目中所存在的包名 29 | # additivity: false #去除重复的log 30 | # level: trace 31 | # AppenderRef: 32 | # - ref: CONSOLE #复数加上- 33 | # - ref: ROLLING_FILE #复数加上 -------------------------------------------------------------------------------- /springboot-log4j/src/test/java/com/example/springbootlog4j/SpringbootLog4jApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootlog4j; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootLog4jApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/README.md: -------------------------------------------------------------------------------- 1 | # springboot + mybatis + mycat整合 2 | [springboot + mybatis + mycat整合](https://github.com/fujiangwei/springboot-learn/tree/master/springboot-mybatis-mycat) 3 | 4 | # 相关文章 5 | [windows安装Mycat并测试](https://www.cnblogs.com/kingsonfu/p/10626481.html) 6 | [Mycat 简介](https://www.cnblogs.com/kingsonfu/p/10627802.html) 7 | [Mycat 配置文件schema.xml](https://www.cnblogs.com/kingsonfu/p/10626544.html) 8 | [Mycat 配置文件server.xml](https://www.cnblogs.com/kingsonfu/p/10627285.html) 9 | [Mycat 配置文件rule.xml](https://www.cnblogs.com/kingsonfu/p/10627423.html) 10 | 11 | # 问题 12 | 13 | > 在新增用户时报错:partition table, insert must provide ColumnList错误 14 | 15 | 将insert into tb_user VALUES (#{userId}, #{userName},#{companyId}); 16 | 改为 17 | insert into tb_user(id, name, company_id) VALUES (#{userId}, #{userName},#{companyId}); 18 | 即加上所有的列字段 -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/SpringbootMybatisMycatApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat; 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(basePackages = {"com.example.springbootmybatismycat.mapper"}) 9 | public class SpringbootMybatisMycatApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootMybatisMycatApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/controller/CompanyController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.controller; 2 | 3 | import com.example.springbootmybatismycat.domain.Company; 4 | import com.example.springbootmybatismycat.service.CompanyService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * descripiton: 13 | * 14 | * @author: kinson(2219945910 @ qq.com) 15 | * @date: 2019/1/31 16 | * @time: 21:58 17 | * @modifier: 18 | * @since: 19 | */ 20 | @RestController 21 | public class CompanyController { 22 | 23 | @Autowired 24 | private CompanyService companyService; 25 | 26 | @GetMapping(value = "listCompany") 27 | public List listCompany() { 28 | return companyService.listCompany(); 29 | } 30 | 31 | @GetMapping(value = "addCompany") 32 | public String addCompany(Company company) { 33 | companyService.addCompany(company); 34 | 35 | return "ok"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.controller; 2 | 3 | import com.example.springbootmybatismycat.domain.User; 4 | import com.example.springbootmybatismycat.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * descripiton: 13 | * 14 | * @author: kinson(2219945910 @ qq.com) 15 | * @date: 2019/1/31 16 | * @time: 21:58 17 | * @modifier: 18 | * @since: 19 | */ 20 | @RestController 21 | public class UserController { 22 | 23 | @Autowired 24 | private UserService userService; 25 | 26 | @GetMapping(value = "listUser") 27 | public List listUser() { 28 | return userService.listUser(); 29 | } 30 | 31 | @GetMapping(value = "addUser") 32 | public String addUser(User user) { 33 | userService.addUser(user); 34 | 35 | return "ok"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/domain/Company.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/1/31 10 | * @time: 21:42 11 | * @modifier: 12 | * @since: 13 | */ 14 | public class Company implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | private Integer id; 19 | 20 | private String name; 21 | 22 | public Integer getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Integer id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/1/31 10 | * @time: 21:42 11 | * @modifier: 12 | * @since: 13 | */ 14 | public class User implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | private Integer userId; 19 | 20 | private String userName; 21 | 22 | private Integer companyId; 23 | 24 | public Integer getUserId() { 25 | return userId; 26 | } 27 | 28 | public void setUserId(Integer userId) { 29 | this.userId = userId; 30 | } 31 | 32 | public String getUserName() { 33 | return userName; 34 | } 35 | 36 | public void setUserName(String userName) { 37 | this.userName = userName; 38 | } 39 | 40 | public Integer getCompanyId() { 41 | return companyId; 42 | } 43 | 44 | public void setCompanyId(Integer companyId) { 45 | this.companyId = companyId; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/mapper/CompanyMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.mapper; 2 | 3 | import com.example.springbootmybatismycat.domain.Company; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface CompanyMapper { 17 | 18 | List selectCompanyList(); 19 | 20 | void addCompany(final Company company); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.mapper; 2 | 3 | import com.example.springbootmybatismycat.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserMapper { 17 | 18 | List selectUserList(); 19 | 20 | void addUser(final User user); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/service/CompanyService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.service; 2 | 3 | import com.example.springbootmybatismycat.domain.Company; 4 | import com.example.springbootmybatismycat.domain.User; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 21:55 14 | * @modifier: 15 | * @since: 16 | */ 17 | public interface CompanyService { 18 | 19 | List listCompany(); 20 | 21 | void addCompany(final Company company); 22 | } 23 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.service; 2 | 3 | import com.example.springbootmybatismycat.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | 20 | void addUser(final User user); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/java/com/example/springbootmybatismycat/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat.service.impl; 2 | 3 | import com.example.springbootmybatismycat.domain.User; 4 | import com.example.springbootmybatismycat.mapper.UserMapper; 5 | import com.example.springbootmybatismycat.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * descripiton: 13 | * 14 | * @author: kinson(2219945910 @ qq.com) 15 | * @date: 2019/1/31 16 | * @time: 21:56 17 | * @modifier: 18 | * @since: 19 | */ 20 | @Service 21 | public class UserServiceImpl implements UserService { 22 | 23 | @Autowired 24 | private UserMapper userMapper; 25 | 26 | @Override 27 | public List listUser() { 28 | return userMapper.selectUserList(); 29 | } 30 | 31 | @Override 32 | public void addUser(User user) { 33 | userMapper.addUser(user); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #设置应用端口 2 | server: 3 | port: 8080 4 | 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | # Mycat连接 9 | url: jdbc:mysql://localhost:8066/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 10 | username: root 11 | password: 123456 12 | 13 | # MyBatis 14 | mybatis: 15 | type-aliases-package: com.example.springbootmybatismycat.domain 16 | mapper-locations: classpath:/mybatis/*.xml 17 | #sql打印配置 18 | configuration: 19 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 20 | 21 | 22 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/resources/mybatis/companyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | insert into tb_company VALUES (#{id}, #{name}); 18 | 19 | 20 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | insert into tb_user(id, name, company_id) VALUES (#{userId}, #{userName},#{companyId}); 19 | 20 | 21 | -------------------------------------------------------------------------------- /springboot-mybatis-mycat/src/test/java/com/example/springbootmybatismycat/SpringbootMybatisMycatApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatismycat; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootMybatisMycatApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mybatis/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/SpringbootMybatisApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis; 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(basePackages = {"com.example.springbootmybatis.mapper"}) 9 | public class SpringbootMybatisApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootMybatisApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis.controller; 2 | 3 | import com.example.springbootmybatis.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 21:58 14 | * @modifier: 15 | * @since: 16 | */ 17 | @RestController 18 | public class UserController { 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @RequestMapping(value = "listUser") 24 | public Object listUser() { 25 | return userService.listUser(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis.domain; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/1/31 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class User { 13 | 14 | private Integer userId; 15 | 16 | private String userName; 17 | 18 | public Integer getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(Integer userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis.mapper; 2 | 3 | import com.example.springbootmybatis.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserMapper { 17 | 18 | List selectUserList(); 19 | } 20 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis.service; 2 | 3 | import com.example.springbootmybatis.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | } 20 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/java/com/example/springbootmybatis/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis.service.impl; 2 | 3 | import com.example.springbootmybatis.domain.User; 4 | import com.example.springbootmybatis.mapper.UserMapper; 5 | import com.example.springbootmybatis.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * descripiton: 13 | * 14 | * @author: kinson(2219945910 @ qq.com) 15 | * @date: 2019/1/31 16 | * @time: 21:56 17 | * @modifier: 18 | * @since: 19 | */ 20 | @Service 21 | public class UserServiceImpl implements UserService { 22 | 23 | @Autowired 24 | private UserMapper userMapper; 25 | 26 | @Override 27 | public List listUser() { 28 | return userMapper.selectUserList(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #设置应用端口 2 | server: 3 | port: 8081 4 | 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 9 | username: xxx 10 | password: xxx 11 | 12 | # MyBatis 13 | mybatis: 14 | type-aliases-package: com.example.springbootmybatis.domain 15 | mapper-locations: classpath:/mybatis/*.xml 16 | 17 | -------------------------------------------------------------------------------- /springboot-mybatis/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /springboot-mybatis/src/test/java/com/example/springbootmybatis/SpringbootMybatisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootmybatis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootMybatisApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-pagehelper/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/main/java/com/example/springbootpagehelper/SpringbootPagehelperApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootpagehelper; 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(basePackages = {"com.example.springbootpagehelper.mapper"}) 9 | public class SpringbootPagehelperApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootPagehelperApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/main/java/com/example/springbootpagehelper/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootpagehelper.domain; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/1/31 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class User { 13 | 14 | private Integer userId; 15 | 16 | private String userName; 17 | 18 | public Integer getUserId() { 19 | return userId; 20 | } 21 | 22 | public void setUserId(Integer userId) { 23 | this.userId = userId; 24 | } 25 | 26 | public String getUserName() { 27 | return userName; 28 | } 29 | 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/main/java/com/example/springbootpagehelper/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootpagehelper.mapper; 2 | 3 | import com.example.springbootpagehelper.domain.User; 4 | import com.github.pagehelper.Page; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/1/31 13 | * @time: 21:43 14 | * @modifier: 15 | * @since: 16 | */ 17 | public interface UserMapper { 18 | 19 | List selectUserList(); 20 | 21 | Page selectUserPage(); 22 | } 23 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/main/java/com/example/springbootpagehelper/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootpagehelper.service; 2 | 3 | import com.example.springbootpagehelper.domain.User; 4 | import com.github.pagehelper.Page; 5 | import com.github.pagehelper.PageInfo; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * descripiton: 11 | * 12 | * @author: kinson(2219945910 @ qq.com) 13 | * @date: 2019/1/31 14 | * @time: 21:55 15 | * @modifier: 16 | * @since: 17 | */ 18 | public interface UserService { 19 | 20 | List listUser(); 21 | 22 | PageInfo pageInfoUser(); 23 | 24 | Page pageUser(); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /springboot-pagehelper/src/test/java/com/example/springbootpagehelper/SpringbootPagehelperApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootpagehelper; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootPagehelperApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-rabbitmq/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-rabbitmq/README.md: -------------------------------------------------------------------------------- 1 | # AmqpTemplate,RabbitTemplate 2 | ```aidl 3 | Spring AMQP提供了一个发送和接收消息的操作模板类AmqpTemplate。 AmqpTemplate它定义包含了发送和接收消息等的一些基本的操作功能。RabbitTemplate是AmqpTemplate的一个实现。 4 | RabbitTemplate支持消息的确认与返回,为了返回消息,RabbitTemplate 需要设置mandatory 属性为true,并且CachingConnectionFactory 的publisherReturns属性也需要设置为true。返回的消息会根据它注册的RabbitTemplate.ReturnCallback setReturnCallback 回调发送到给客户端,一个RabbitTemplate仅能支持一个ReturnCallback 。 5 | 为了确认Confirms消息, CachingConnectionFactory 的publisherConfirms 属性也需要设置为true,确认的消息会根据它注册的RabbitTemplate.ConfirmCallback setConfirmCallback回调发送到给客户端。一个RabbitTemplate也仅能支持一个ConfirmCallback。 6 | ``` 7 | 8 | # 常用API 9 | 10 | //消息的标识,false只确认当前一个消息收到,true确认所有consumer获得的消息 11 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); 12 | 13 | //ack返回false,并重新回到队列 14 | channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true); 15 | 16 | //拒绝消息 17 | channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); 18 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/SpringbootRabbitmqApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootRabbitmqApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootRabbitmqApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/config/RabbitMqConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.config; 2 | 3 | import org.springframework.amqp.core.Queue; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * descripiton: 设置队列 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/3/22 12 | * @time: 23:49 13 | * @modifier: 14 | * @since: 15 | */ 16 | @Configuration 17 | public class RabbitMqConfig { 18 | 19 | @Bean 20 | public Queue kinsonQueue() { 21 | return new Queue("kinson"); 22 | } 23 | 24 | @Bean 25 | public Queue kinsonQueue2() { 26 | return new Queue("kinson2"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/domain/MessageObj.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/3/26 10 | * @time: 12:12 11 | * @modifier: 12 | * @since: 13 | */ 14 | public class MessageObj implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | private Integer id; 19 | 20 | private String name; 21 | 22 | private boolean isAck; 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public boolean isAck() { 41 | return isAck; 42 | } 43 | 44 | public void setAck(boolean ack) { 45 | isAck = ack; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return String.format("id=%d,name=%s", id, name); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/receive/MyReceiver1.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.receive; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | //监听队列kinson 9 | @RabbitListener(queues = {"kinson"}) 10 | public class MyReceiver1 { 11 | 12 | @RabbitHandler 13 | public void receiver(String msg) { 14 | System.out.println("MyReceiver1 :" + msg); 15 | } 16 | } -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/receive/MyReceiver2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.receive; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | //监听队列kinson 9 | @RabbitListener(queues = {"kinson"}) 10 | public class MyReceiver2 { 11 | 12 | @RabbitHandler 13 | public void receiver(String msg) { 14 | System.out.println("MyReceiver2 :" + msg); 15 | } 16 | } -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/receive/MyReceiver3.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.receive; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | //监听队列kinson2 9 | @RabbitListener(queues = {"kinson2"}) 10 | public class MyReceiver3 { 11 | 12 | @RabbitHandler 13 | public void receiver(String msg) { 14 | System.out.println("MyReceiver3 :" + msg); 15 | } 16 | } -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/receive/MyTopicReceiver1.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.receive; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | //监听队列topic.msg 9 | @RabbitListener(queues = {"topic.msg"}) 10 | public class MyTopicReceiver1 { 11 | 12 | @RabbitHandler 13 | public void receiver(String msg) { 14 | System.out.println("MyTopicReceiver1 :" + msg); 15 | } 16 | } -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/com/example/springbootrabbitmq/receive/MyTopicReceiver2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq.receive; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | //监听队列topic.msgs 9 | @RabbitListener(queues = {"topic.msgs"}) 10 | public class MyTopicReceiver2 { 11 | 12 | @RabbitHandler 13 | public void receiver(String msg) { 14 | System.out.println("MyTopicReceiver2 :" + msg); 15 | } 16 | } -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | spring.application.name=springboot-rabbitmq 3 | spring.rabbitmq.host=192.168.242.131 4 | spring.rabbitmq.port=5672 5 | spring.rabbitmq.username=guest 6 | spring.rabbitmq.password=guest 7 | # 开启发送确认 8 | spring.rabbitmq.publisher-confirms=true 9 | # 开启发送失败退回 10 | spring.rabbitmq.publisher-returns=true 11 | # 开启ACK 12 | spring.rabbitmq.listener.direct.acknowledge-mode=manual 13 | spring.rabbitmq.listener.simple.acknowledge-mode=manual 14 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/test/java/com/example/springbootrabbitmq/SpringbootRabbitmqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrabbitmq; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootRabbitmqApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-redis-cluster/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-redis-cluster/README.md: -------------------------------------------------------------------------------- 1 | ## 2 | [Redis 一主二从三哨兵](https://www.cnblogs.com/kingsonfu/p/10407601.html) -------------------------------------------------------------------------------- /springboot-redis-cluster/src/main/java/com/example/springbootrediscluster/SpringbootRedisClusterApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrediscluster; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootRedisClusterApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootRedisClusterApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-redis-cluster/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | # Redis 5 | spring.redis: 6 | sentinel: 7 | #与redis环境配置的保持一致 8 | master: mymaster 9 | #节点集合以,隔开 10 | nodes: localhost:26388,localhost:26380,localhost:26381 11 | password: root 12 | timeout: 1000 13 | jedis.pool: 14 | #jedis最大分配对象 15 | maxTotal: 1024 16 | #jedis最大保存idel状态对象数 17 | maxIdle: 200 18 | #jedis池没有对象返回时,最大等待时间 19 | maxWaitMillis: 10000 20 | testOnBorrow: true 21 | testOnReturn: true 22 | blockWhenExhausted: false 23 | #Idle时进行连接扫描 24 | testWhileIdle: true 25 | #表示idle object evitor两次扫描之间要sleep的毫秒数 26 | timeBetweenEvictionRunsMillis: 30000 27 | #表示idle object evitor每次扫描的最多的对象数 28 | numTestsPerEvictionRun: 10 29 | #表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义 30 | minEvictableIdleTimeMillis: 60000 -------------------------------------------------------------------------------- /springboot-redis-cluster/src/test/java/com/example/springbootrediscluster/SpringbootRedisClusterApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrediscluster; 2 | 3 | import com.example.springbootrediscluster.config.client.RedisClient; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class SpringbootRedisClusterApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | @Autowired 19 | private RedisClient redisClient; 20 | 21 | @Test 22 | public void redis() { 23 | redisClient.set("slot_curr_num_key", 6); 24 | 25 | System.out.println(redisClient.get("slot_curr_num_key")); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-redis/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/SpringbootRedisApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootRedisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootRedisApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/utils/redis/CommonOperUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis.utils.redis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/2/22 10 | * @time: 22:04 11 | * @modifier: 12 | * @since: 13 | */ 14 | public class CommonOperUtil { 15 | 16 | public void oper(Jedis jedis) { 17 | //是否存在key 18 | Boolean exists = jedis.exists("append"); 19 | Boolean exists2 = jedis.exists("exists2"); 20 | System.out.println("exists :" + exists + "---" + exists2); 21 | 22 | //是否存在keys 23 | Long exists1 = jedis.exists("append", "exists2"); 24 | System.out.println("exists :" + exists1); 25 | 26 | //删除key 27 | Long del = jedis.del("incr"); 28 | System.out.println("del :" + del); 29 | Long del1 = jedis.del("k1", "k2", "k3", "k8", "k9"); 30 | System.out.println("del1 :" + del); 31 | 32 | //类型 33 | String type = jedis.type("remain_num_key"); 34 | System.out.println("类型:" + type); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/utils/redis/HashOperUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis.utils.redis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * descripiton: List 列表操作 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/2/22 12 | * @time: 22:04 13 | * @modifier: 14 | * @since: 15 | */ 16 | public class HashOperUtil { 17 | 18 | public static void oper(Jedis jedis) { 19 | 20 | Long id = jedis.hset("hash", "id", "1"); 21 | Long name = jedis.hset("hash", "name", "fjw"); 22 | System.out.println("id:" + id + "---name:" + name); 23 | String id2 = jedis.hget("hash", "id"); 24 | System.out.println("id2:" + id2 + "---type:" + jedis.type("hash")); 25 | Map hgetAll = jedis.hgetAll("hash"); 26 | System.out.println("hgetAll:" + hgetAll); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/utils/redis/ListOperUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis.utils.redis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * descripiton: List 列表操作 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/2/22 10 | * @time: 22:04 11 | * @modifier: 12 | * @since: 13 | */ 14 | public class ListOperUtil { 15 | 16 | public static void oper(Jedis jedis) { 17 | 18 | Long lpush = jedis.lpush("list", "a", "b", "c"); 19 | String list = jedis.lpop("list"); 20 | System.out.println("lpush:" + lpush + "---" + list + "---type:" + jedis.type("list")); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/utils/redis/SetOperUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis.utils.redis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * descripiton: Set 集合操作 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/2/22 13 | * @time: 22:04 14 | * @modifier: 15 | * @since: 16 | */ 17 | public class SetOperUtil { 18 | 19 | public static void oper(Jedis jedis) { 20 | 21 | Long id = jedis.sadd("set", "1"); 22 | Long id2 = jedis.sadd("set", "1", "12"); 23 | Set smembers = jedis.smembers("set"); 24 | System.out.println("smembers:" + smembers); 25 | System.out.println("set type:" + jedis.type("hash")); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/example/springbootredis/utils/redis/ZSetOperUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootredis.utils.redis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.Set; 6 | 7 | /** 8 | * descripiton: ZSet 有序集合操作 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/2/22 12 | * @time: 22:04 13 | * @modifier: 14 | * @since: 15 | */ 16 | public class ZSetOperUtil { 17 | 18 | public static void oper(Jedis jedis) { 19 | 20 | jedis.zadd("zset", 3, "3"); 21 | jedis.zadd("zset", 4, "5"); 22 | jedis.zadd("zset", 5, "5"); 23 | jedis.zadd("zset", 6, "6"); 24 | Set zset = jedis.zrange("zset", 0, -1); 25 | System.out.println("zset:" + zset); 26 | System.out.println("zset type:" + jedis.type("zset")); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8008 3 | 4 | # Redis 5 | spring.redis: 6 | host: localhost 7 | port: 6379 8 | password: root 9 | timeout: 1000 10 | jedis.pool: 11 | #jedis最大分配对象 12 | maxTotal: 1024 13 | #jedis最大保存idel状态对象数 14 | maxIdle: 200 15 | #jedis池没有对象返回时,最大等待时间 16 | maxWaitMillis: 1000 17 | #当该属性为true时,在调用borrowObject方法返回连接前,会调用validated方法进行校验。若校验失败,连接会从连接池中移除并销毁。同时会尝试重新借一个新的连接对象。 18 | testOnBorrow: true 19 | #若testOnReturn属性设置为true,归还连接时,会进行检查,检查不通过,销毁 20 | testOnReturn: true 21 | #连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true 22 | blockWhenExhausted: false 23 | 24 | -------------------------------------------------------------------------------- /springboot-rpc/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml -------------------------------------------------------------------------------- /springboot-rpc/README.md: -------------------------------------------------------------------------------- 1 | # RPC远程调用示例学习 2 | 3 | ## springboot commandRunner和ApplicationRunner 4 | ```text 5 | 应用服务器启动时,加载一些数据和执行一些初始化动作,如读取配置文件或者读取数据库连接等,当有多个类实现这些接口时可通过加@Order注解来控制执行的先后顺序,值越小优先级越高 6 | 7 | 两者的区别在于: 8 | ApplicationRunner中run方法的参数为ApplicationArguments,而CommandLineRunner接口中run方法的参数为String数组。 9 | 想要更详细地获取命令行参数,那就使用ApplicationRunner接口。 10 | ApplicationRunner是针对main方法的参数args做了一层封装,存在形式为key=value模式,可以通过key来获取对应的value值。而CommandLineRunner只是以值的形式存在着。 11 | 12 | ``` 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/SpringbootRpcApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootRpcApplication { 8 | 9 | public static void main(String[] args) { 10 | System.out.println("i am begin..."); 11 | SpringApplication.run(SpringbootRpcApplication.class, args); 12 | } 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/annotation/RpcService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * descripiton: 12 | * 13 | * @author: kinson(2219945910 @ qq.com) 14 | * @date: 2019/8/4 15 | * @time: 13:16 16 | * @modifier: 17 | * @since: 18 | */ 19 | @Target(ElementType.TYPE) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | @Component 22 | public @interface RpcService { 23 | 24 | Class value(); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/channelhandel/RpcEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.channelhandel; 2 | 3 | import com.example.springbootrpc.model.RpcRequest; 4 | import com.example.springbootrpc.utils.SerializationUtil; 5 | import io.netty.buffer.ByteBuf; 6 | import io.netty.channel.ChannelHandlerContext; 7 | import io.netty.handler.codec.MessageToByteEncoder; 8 | 9 | /** 10 | * descripiton: 11 | * 12 | * @author: kinson(2219945910 @ qq.com) 13 | * @date: 2019/8/10 14 | * @time: 17:21 15 | * @modifier: 16 | * @since: 17 | */ 18 | public class RpcEncoder extends MessageToByteEncoder { 19 | 20 | private Class genericClass; 21 | 22 | public RpcEncoder(Class genericClass) { 23 | this.genericClass = genericClass; 24 | } 25 | 26 | @Override 27 | public void encode(ChannelHandlerContext ctx, Object in, ByteBuf out) throws Exception { 28 | if (genericClass.isInstance(in)) { 29 | byte[] data = SerializationUtil.serialize(in); 30 | out.writeInt(data.length); 31 | out.writeBytes(data); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/client/AsyncRpcCallback.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.client; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/8/15 8 | * @time: 22:00 9 | * @modifier: 10 | * @since: 11 | */ 12 | public interface AsyncRpcCallback { 13 | 14 | void success(Object result); 15 | 16 | void fail(Exception e); 17 | } 18 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/client/RpcClientInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.client; 2 | 3 | import com.example.springbootrpc.channelhandel.RpcDecoder; 4 | import com.example.springbootrpc.channelhandel.RpcEncoder; 5 | import com.example.springbootrpc.model.RpcRequest; 6 | import com.example.springbootrpc.model.RpcResponse; 7 | import io.netty.channel.ChannelInitializer; 8 | import io.netty.channel.ChannelPipeline; 9 | import io.netty.channel.socket.SocketChannel; 10 | import io.netty.handler.codec.LengthFieldBasedFrameDecoder; 11 | 12 | 13 | /** 14 | * descripiton: 15 | * 16 | * @author: kinson(2219945910 @ qq.com) 17 | * @date: 2019/8/14 18 | * @time: 0:04 19 | * @modifier: 20 | * @since: 21 | */ 22 | public class RpcClientInitializer extends ChannelInitializer { 23 | @Override 24 | protected void initChannel(SocketChannel socketChannel) throws Exception { 25 | ChannelPipeline cp = socketChannel.pipeline(); 26 | cp.addLast(new RpcEncoder(RpcRequest.class)); 27 | cp.addLast(new LengthFieldBasedFrameDecoder(65536, 0, 4, 0, 0)); 28 | cp.addLast(new RpcDecoder(RpcResponse.class)); 29 | cp.addLast(new RpcClientHandler()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/client/proxy/IAsyncObjectProxy.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.client.proxy; 2 | 3 | import com.example.springbootrpc.client.RpcFuture; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/8/13 10 | * @time: 23:06 11 | * @modifier: 12 | * @since: 13 | */ 14 | public interface IAsyncObjectProxy { 15 | 16 | RpcFuture call(String funcName, Object... args); 17 | } 18 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/controller/SpringbootRpcController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * descripiton: 8 | * 9 | * @author: kinson(2219945910 @ qq.com) 10 | * @date: 2019/1/12 11 | * @time: 21:38 12 | * @modifier: 13 | * @since: 14 | */ 15 | @RestController 16 | @RequestMapping(value = "/start") 17 | public class SpringbootRpcController { 18 | 19 | @RequestMapping(value = "/hello") 20 | // @ResponseBody 21 | public String hello() { 22 | System.out.println("coming in"); 23 | return "hello, Springboot"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/model/RpcRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * descripiton: Rpc请求对象 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/8/10 10 | * @time: 17:32 11 | * @modifier: 12 | * @since: 13 | */ 14 | @Data 15 | public class RpcRequest { 16 | 17 | /** 18 | * 请求id 19 | */ 20 | private String requestId; 21 | 22 | /** 23 | * 类名 24 | */ 25 | private String className; 26 | 27 | /** 28 | * 方法名 29 | */ 30 | private String methodName; 31 | 32 | /** 33 | * 参数类型 34 | */ 35 | private Class[] parameterTypes; 36 | 37 | /** 38 | * 参数 39 | */ 40 | private Object[] parameters; 41 | } 42 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/model/RpcResponse.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * descripiton: Rpc请求响应体 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/8/10 10 | * @time: 17:32 11 | * @modifier: 12 | * @since: 13 | */ 14 | @Data 15 | public class RpcResponse { 16 | /** 17 | * 请求id 18 | */ 19 | private String requestId; 20 | 21 | /** 22 | * 错误信息 23 | */ 24 | private String error; 25 | 26 | /** 27 | * 结果 28 | */ 29 | private Object result; 30 | 31 | public boolean isError() { 32 | return error != null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/runner/MyAppRunner.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.runner; 2 | 3 | import org.springframework.boot.ApplicationArguments; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.core.annotation.Order; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/8/3 13 | * @time: 0:54 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Component 18 | @Order(2) 19 | public class MyAppRunner implements ApplicationRunner { 20 | 21 | @Override 22 | public void run(ApplicationArguments args) throws Exception { 23 | System.out.println("i am MyAppRunner running..." + args.getOptionValues("1")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/runner/MyRunner.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.runner; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/8/2 12 | * @time: 23:52 13 | * @modifier: 14 | * @since: 15 | */ 16 | @Component 17 | @Order(1) 18 | public class MyRunner implements CommandLineRunner { 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | System.out.println("i am MyRunner running..." + args[3]); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/java/com/example/springbootrpc/runner/MyRunner2.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.runner; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.core.annotation.Order; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/8/2 12 | * @time: 23:52 13 | * @modifier: 14 | * @since: 15 | */ 16 | @Component 17 | @Order(2) 18 | public class MyRunner2 implements CommandLineRunner { 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | System.out.println("i am MyRunner2 running..." + args.length + "---" + args[0]); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /springboot-rpc/src/main/resources/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 3 | # rpc server 4 | server.address=127.0.0.1:2888 5 | -------------------------------------------------------------------------------- /springboot-rpc/src/test/java/com/example/springbootrpc/SpringbootRpcApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootRpcApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-rpc/src/test/java/com/example/springbootrpc/server/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootrpc.server; 2 | 3 | 4 | import com.example.springbootrpc.annotation.RpcService; 5 | import com.example.springbootrpc.client.HelloService; 6 | import com.example.springbootrpc.client.Person; 7 | 8 | @RpcService(HelloService.class) 9 | public class HelloServiceImpl implements HelloService { 10 | 11 | public HelloServiceImpl() { 12 | 13 | } 14 | 15 | @Override 16 | public String hello(String name) { 17 | return "Hello! " + name; 18 | } 19 | 20 | @Override 21 | public String hello(Person person) { 22 | return "Hello! " + person.getFirstName() + " " + person.getLastName(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-rpc/src/test/resources/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 3 | # rpc server 4 | server.address=127.0.0.1:2888 5 | -------------------------------------------------------------------------------- /springboot-scheduled/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-scheduled/src/main/java/com/example/springbootscheduled/SpringbootScheduledApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootscheduled; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | import org.springframework.scheduling.annotation.Scheduled; 7 | 8 | @SpringBootApplication 9 | //开启对定时任务的支持,这种方式是在同一个线程中串行执行,适合单个线程任务处理 10 | @EnableScheduling 11 | public class SpringbootScheduledApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringbootScheduledApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-scheduled/src/main/java/com/example/springbootscheduled/config/AsyncScheduledConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootscheduled.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 7 | 8 | /** 9 | * descripiton: 多线程模式 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/2/17 13 | * @time: 20:34 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Configuration 18 | @EnableAsync 19 | public class AsyncScheduledConfig { 20 | 21 | //线程池配置参数(可通过配置文件读取) 22 | //核心线程池数量 23 | private int corePoolSize = 10; 24 | //最大线程池数量 25 | private int maxPoolSize = 200; 26 | //队列容量 27 | private int queueCapacity = 10; 28 | 29 | @Bean 30 | public ThreadPoolTaskExecutor taskExecutor() { 31 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 32 | executor.setCorePoolSize(corePoolSize); 33 | executor.setMaxPoolSize(maxPoolSize); 34 | executor.setQueueCapacity(queueCapacity); 35 | 36 | executor.initialize(); 37 | 38 | return executor; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /springboot-scheduled/src/main/java/com/example/springbootscheduled/quartz/TestQuartz.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootscheduled.quartz; 2 | 3 | import org.quartz.JobExecutionContext; 4 | import org.quartz.JobExecutionException; 5 | import org.springframework.scheduling.quartz.QuartzJobBean; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * descripiton: Quartz任务类 11 | * 12 | * @author: kinson(2219945910 @ qq.com) 13 | * @date: 2019/2/17 14 | * @time: 21:14 15 | * @modifier: 16 | * @since: 17 | */ 18 | public class TestQuartz extends QuartzJobBean { 19 | 20 | @Override 21 | protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { 22 | System.out.println(Thread.currentThread().getName() + " quartz task " + new Date()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-scheduled/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /springboot-scheduled/src/test/java/com/example/springbootscheduled/SpringbootScheduledTestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootscheduled; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootScheduledTestApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-shiro/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootShiroApplication.class); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/SpringbootShiroApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro; 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.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | 8 | @SpringBootApplication 9 | @MapperScan(basePackages = "com.example.springbootshiro.mapper") 10 | public class SpringbootShiroApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringbootShiroApplication.class, args); 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/config/FreeMarkerConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.config; 2 | 3 | import com.example.springbootshiro.tags.CustomTagDirective; 4 | import com.jagregory.shiro.freemarker.ShiroTags; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | @Configuration 11 | public class FreeMarkerConfig { 12 | 13 | @Autowired 14 | protected freemarker.template.Configuration configuration; 15 | 16 | @Autowired 17 | protected CustomTagDirective customTagDirective; 18 | 19 | /** 20 | * 添加自定义标签 21 | */ 22 | @PostConstruct 23 | public void setSharedVariable() { 24 | System.out.println("=================初始化自定义tag配置================="); 25 | configuration.setSharedVariable("customTag", customTagDirective); 26 | //shiro标签 27 | configuration.setSharedVariable("shiro", new ShiroTags()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.config; 2 | 3 | import com.example.springbootshiro.interceptor.RememberAuthenticationInterceptor; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | @Configuration 10 | public class WebMvcConfig implements WebMvcConfigurer { 11 | 12 | @Autowired 13 | private RememberAuthenticationInterceptor rememberAuthenticationInterceptor; 14 | 15 | @Override 16 | public void addInterceptors(InterceptorRegistry registry) { 17 | registry.addInterceptor(rememberAuthenticationInterceptor) 18 | .excludePathPatterns("/login", "/error/**", "/assets/**", "/static/**") 19 | .addPathPatterns("/**"); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/constants/CommonConstants.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.constants; 2 | 3 | /** 4 | * descripiton: 5 | * 6 | * @author: kinson(2219945910 @ qq.com) 7 | * @date: 2019/2/13 8 | * @time: 21:42 9 | * @modifier: 10 | * @since: 11 | */ 12 | public class CommonConstants { 13 | 14 | /** 15 | * 安全密码(UUID生成),作为盐值用于用户密码的加密 16 | */ 17 | public static final String SALT_SECURITY_KEY = "684123f8f17944e8b0a531045453e1f1"; 18 | 19 | /** 20 | * 程序默认的错误状态码 21 | */ 22 | public static final int DEFAULT_ERROR_CODE = 500; 23 | 24 | /** 25 | * 程序默认的成功状态码 26 | */ 27 | public static final int DEFAULT_SUCCESS_CODE = 200; 28 | 29 | /** 30 | * User 的 session key; 31 | */ 32 | public static final String USER_SESSION_KEY = "user"; 33 | } 34 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | @Controller 10 | public class IndexController { 11 | private static final Logger logger = LoggerFactory.getLogger(IndexController.class); 12 | 13 | @GetMapping("/index") 14 | public String index(Model model) { 15 | return "index"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/controller/RenderController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.controller; 2 | 3 | import com.example.springbootshiro.utils.ResultUtil; 4 | import org.apache.shiro.authz.annotation.RequiresPermissions; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.servlet.ModelAndView; 8 | 9 | @Controller 10 | public class RenderController { 11 | 12 | @RequiresPermissions("users") 13 | @GetMapping("/users") 14 | public ModelAndView user() { 15 | return ResultUtil.view("user/list"); 16 | } 17 | 18 | @RequiresPermissions("resources") 19 | @GetMapping("/resources") 20 | public ModelAndView resources() { 21 | return ResultUtil.view("resources/list"); 22 | } 23 | 24 | @RequiresPermissions("roles") 25 | @GetMapping("/roles") 26 | public ModelAndView roles() { 27 | return ResultUtil.view("role/list"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.controller; 2 | 3 | import com.example.springbootshiro.service.SysUserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | @Controller 10 | public class TestController { 11 | 12 | @Autowired 13 | private SysUserService userService; 14 | 15 | @RequestMapping(value = "test") 16 | @ResponseBody 17 | public Object test() { 18 | return userService.getByUserName("root"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/SysRole.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.Transient; 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | 13 | @Data 14 | @EqualsAndHashCode(callSuper = false) 15 | public class SysRole implements Serializable { 16 | 17 | private static final long serialVersionUID = 5088697673359856350L; 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private Long id; 22 | 23 | private Date createTime; 24 | private Date updateTime; 25 | private String name; 26 | private String description; 27 | private Boolean available; 28 | 29 | @Transient 30 | private Integer selected; 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/SysRoleResources.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = false) 14 | public class SysRoleResources implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Long id; 21 | 22 | private Date createTime; 23 | private Date updateTime; 24 | private Long roleId; 25 | private Long resourcesId; 26 | } 27 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/SysUser.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = false) 14 | public class SysUser implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Long id; 21 | 22 | private Date createTime; 23 | private Date updateTime; 24 | private String username; 25 | private String password; 26 | private String nickname; 27 | private String mobile; 28 | private String email; 29 | private String qq; 30 | private Date birthday; 31 | private Integer gender; 32 | private String avatar; 33 | private String userType; 34 | private String regIp; 35 | private String lastLoginIp; 36 | private Date lastLoginTime; 37 | private Integer loginCount; 38 | private String remark; 39 | private Integer status; 40 | } 41 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/SysUserRole.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | @EqualsAndHashCode(callSuper = false) 14 | public class SysUserRole implements Serializable { 15 | 16 | private static final long serialVersionUID = 5088697673359856350L; 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Long id; 21 | 22 | private Date createTime; 23 | private Date updateTime; 24 | private Long userId; 25 | private Long roleId; 26 | } 27 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/vo/BaseConditionVO.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain.vo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | import org.springframework.format.annotation.DateTimeFormat; 6 | 7 | import java.util.Date; 8 | 9 | @Data 10 | @EqualsAndHashCode(callSuper = false) 11 | public class BaseConditionVO { 12 | public final static int DEFAULT_PAGE_SIZE = 10; 13 | private int pageNumber = 1; 14 | private int pageSize = 0; 15 | private int pageStart = 0; 16 | private String orderField; 17 | private String orderDirection; 18 | private String keywords; 19 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 20 | private Date startDate; 21 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 22 | private Date endDate; 23 | 24 | public int getPageSize() { 25 | return pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE; 26 | } 27 | 28 | public int getPageStart() { 29 | return pageNumber > 0 ? (pageNumber - 1) * getPageSize() : 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/vo/PageResult.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain.vo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | @EqualsAndHashCode(callSuper = false) 10 | public class PageResult { 11 | private Long total; 12 | private List rows; 13 | 14 | public PageResult(Long total, List rows) { 15 | this.total = total; 16 | this.rows = rows; 17 | } 18 | 19 | public PageResult() { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/vo/ResourceConditionVO.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain.vo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | @Data 7 | @EqualsAndHashCode(callSuper = false) 8 | public class ResourceConditionVO extends BaseConditionVO { 9 | private String type; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/vo/RoleConditionVO.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain.vo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | @Data 7 | @EqualsAndHashCode(callSuper = false) 8 | public class RoleConditionVO extends BaseConditionVO { 9 | private Role role; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/domain/vo/UserConditionVO.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.domain.vo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | @Data 7 | @EqualsAndHashCode(callSuper = false) 8 | public class UserConditionVO extends BaseConditionVO { 9 | private User user; 10 | } 11 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/enums/ResourceTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.enums; 2 | 3 | public enum ResourceTypeEnum { 4 | 5 | menu("菜单"), button("按钮"); 6 | 7 | private final String info; 8 | 9 | private ResourceTypeEnum(String info) { 10 | this.info = info; 11 | } 12 | 13 | public String getInfo() { 14 | return info; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/enums/ResponseStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.enums; 2 | 3 | public enum ResponseStatusEnum { 4 | 5 | SUCCESS(200, "操作成功!"), 6 | ERROR(500, "服务器未知错误!"), 7 | UNAUTHORIZED(500, "尚未登录!"), 8 | FORBIDDEN(500, "您没有操作权限!"), 9 | NOT_FOUND(500, "资源不存在!"), 10 | LOGIN_ERROR(500, "账号或密码错误!"), 11 | USER_EXIST(500, "已存在的用户!"), 12 | INVALID_AUTHCODE(500, "手机验证码无效!"), 13 | INVALID_TOKEN(500, "无效的TOKEN,您没有操作权限!"), 14 | INVALID_ACCESS(500, "无效的请求,该请求已过期!"), 15 | DELETE_ERROR(500, "删除失败!"); 16 | 17 | private Integer code; 18 | private String message; 19 | 20 | ResponseStatusEnum(Integer code, String message) { 21 | this.code = code; 22 | this.message = message; 23 | } 24 | 25 | public static ResponseStatusEnum getResponseStatus(String message) { 26 | for (ResponseStatusEnum ut : ResponseStatusEnum.values()) { 27 | if (ut.getMessage() == message) { 28 | return ut; 29 | } 30 | } 31 | return null; 32 | } 33 | 34 | public Integer getCode() { 35 | return code; 36 | } 37 | 38 | public String getMessage() { 39 | return message; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/enums/UserStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.enums; 2 | 3 | public enum UserStatusEnum { 4 | 5 | NORMAL(1, "正常"), 6 | DISABLE(0, "禁用"), 7 | ; 8 | private Integer code; 9 | private String desc; 10 | 11 | UserStatusEnum(Integer code, String desc) { 12 | this.code = code; 13 | this.desc = desc; 14 | } 15 | 16 | public static UserStatusEnum get(Integer code) { 17 | if (null == code) { 18 | return NORMAL; 19 | } 20 | UserStatusEnum[] enums = UserStatusEnum.values(); 21 | for (UserStatusEnum anEnum : enums) { 22 | if (anEnum.getCode().equals(code)) { 23 | return anEnum; 24 | } 25 | } 26 | return NORMAL; 27 | } 28 | 29 | public Integer getCode() { 30 | return code; 31 | } 32 | 33 | public String getDesc() { 34 | return desc; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/enums/UserTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.enums; 2 | 3 | import org.springframework.util.StringUtils; 4 | 5 | public enum UserTypeEnum { 6 | ROOT("超级管理员"), 7 | ADMIN("管理员"), 8 | USER("系统会员"), 9 | UNKNOW("未知"); 10 | private String desc; 11 | 12 | UserTypeEnum(String desc) { 13 | this.desc = desc; 14 | } 15 | 16 | public static UserTypeEnum getByType(String type) { 17 | if (StringUtils.isEmpty(type)) { 18 | return UserTypeEnum.UNKNOW; 19 | } 20 | for (UserTypeEnum ut : UserTypeEnum.values()) { 21 | if (ut.toString().equalsIgnoreCase(type)) { 22 | return ut; 23 | } 24 | } 25 | return UserTypeEnum.UNKNOW; 26 | } 27 | 28 | public String getDesc() { 29 | return desc; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/mapper/SysRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.mapper; 2 | 3 | import com.example.springbootshiro.domain.SysRole; 4 | import com.example.springbootshiro.domain.vo.RoleConditionVO; 5 | import com.example.springbootshiro.plugin.BaseMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Repository 11 | public interface SysRoleMapper extends BaseMapper { 12 | 13 | /** 14 | * 分页查询 15 | * 16 | * @param vo 17 | * @return 18 | */ 19 | List findPageBreakByCondition(RoleConditionVO vo); 20 | 21 | /** 22 | * 该节代码参考自http://blog.csdn.net/poorcoder_/article/details/71374002 23 | * 感谢网友 24 | * 25 | * @param userId 26 | * @return 27 | */ 28 | List queryRoleListWithSelected(Integer userId); 29 | 30 | List listRolesByUserId(Long userId); 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/mapper/SysRoleResourcesMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.mapper; 2 | 3 | import com.example.springbootshiro.domain.SysRoleResources; 4 | import com.example.springbootshiro.plugin.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface SysRoleResourcesMapper extends BaseMapper { 9 | } 10 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/mapper/SysUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.mapper; 2 | 3 | import com.example.springbootshiro.domain.SysUser; 4 | import com.example.springbootshiro.domain.vo.UserConditionVO; 5 | import com.example.springbootshiro.plugin.BaseMapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Repository 11 | public interface SysUserMapper extends BaseMapper { 12 | 13 | List findPageBreakByCondition(UserConditionVO vo); 14 | 15 | List listByRoleId(Long roleId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/mapper/SysUserRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.mapper; 2 | 3 | import com.example.springbootshiro.domain.SysUserRole; 4 | import com.example.springbootshiro.plugin.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface SysUserRoleMapper extends BaseMapper { 11 | List findUserIdByRoleId(Integer roleId); 12 | } 13 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/plugin/BaseMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.plugin; 2 | 3 | import tk.mybatis.mapper.common.Mapper; 4 | import tk.mybatis.mapper.common.MySqlMapper; 5 | 6 | public interface BaseMapper extends Mapper, MySqlMapper { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/service/SysRoleResourcesService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.service; 2 | 3 | import com.example.springbootshiro.domain.vo.RoleResources; 4 | 5 | public interface SysRoleResourcesService extends AbstractService { 6 | 7 | /** 8 | * 添加角色资源 9 | * 10 | * @param roleId 11 | * @param resourcesIds 12 | */ 13 | void addRoleResources(Long roleId, String resourcesIds); 14 | 15 | /** 16 | * 通过角色id批量删除 17 | * 18 | * @param roleId 19 | */ 20 | void removeByRoleId(Long roleId); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/service/SysRoleService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.service; 2 | 3 | import com.example.springbootshiro.domain.vo.Role; 4 | import com.example.springbootshiro.domain.vo.RoleConditionVO; 5 | import com.github.pagehelper.PageInfo; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public interface SysRoleService extends AbstractService { 11 | 12 | /** 13 | * 获取ztree使用的角色列表 14 | * 15 | * @param uid 16 | * @return 17 | */ 18 | List> queryRoleListWithSelected(Integer uid); 19 | 20 | /** 21 | * 分页查询 22 | * 23 | * @param vo 24 | * @return 25 | */ 26 | PageInfo findPageBreakByCondition(RoleConditionVO vo); 27 | 28 | /** 29 | * 获取用户的角色 30 | * 31 | * @param userId 32 | * @return 33 | */ 34 | List listRolesByUserId(Long userId); 35 | } 36 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/service/SysUserRoleService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.service; 2 | 3 | import com.example.springbootshiro.domain.vo.UserRole; 4 | 5 | public interface SysUserRoleService extends AbstractService { 6 | 7 | /** 8 | * 添加用户角色 9 | * 10 | * @param userId 11 | * @param roleIds 12 | */ 13 | void addUserRole(Long userId, String roleIds); 14 | 15 | /** 16 | * 根据用户ID删除用户角色 17 | * 18 | * @param userId 19 | */ 20 | void removeByUserId(Long userId); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.service; 2 | 3 | import com.example.springbootshiro.domain.vo.User; 4 | import com.example.springbootshiro.domain.vo.UserConditionVO; 5 | import com.github.pagehelper.PageInfo; 6 | 7 | import java.util.List; 8 | 9 | public interface SysUserService extends AbstractService { 10 | 11 | /** 12 | * 分页查询 13 | * 14 | * @param vo 15 | * @return 16 | */ 17 | PageInfo findPageBreakByCondition(UserConditionVO vo); 18 | 19 | /** 20 | * 更新用户最后一次登录的状态信息 21 | * 22 | * @param user 23 | * @return 24 | */ 25 | User updateUserLastLoginInfo(User user); 26 | 27 | /** 28 | * 根据用户名查找 29 | * 30 | * @param userName 31 | * @return 32 | */ 33 | User getByUserName(String userName); 34 | 35 | /** 36 | * 通过角色Id获取用户列表 37 | * 38 | * @param roleId 39 | * @return 40 | */ 41 | List listByRoleId(Long roleId); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/utils/IpUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.utils; 2 | 3 | import org.springframework.util.StringUtils; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | public class IpUtil { 8 | 9 | /** 10 | * 获取真实IP 11 | * 12 | * @param request 13 | * @return 14 | */ 15 | public static String getRealIp(HttpServletRequest request) { 16 | String ip = request.getHeader("x-forwarded-for"); 17 | return checkIp(ip) ? ip : ( 18 | checkIp(ip = request.getHeader("Proxy-Client-IP")) ? ip : ( 19 | checkIp(ip = request.getHeader("WL-Proxy-Client-IP")) ? ip : 20 | request.getRemoteAddr())); 21 | } 22 | 23 | /** 24 | * 校验IP 25 | * 26 | * @param ip 27 | * @return 28 | */ 29 | private static boolean checkIp(String ip) { 30 | return !StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip); 31 | } 32 | } -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/example/springbootshiro/utils/PasswordUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro.utils; 2 | 3 | import com.example.springbootshiro.constants.CommonConstants; 4 | 5 | public class PasswordUtil { 6 | 7 | /** 8 | * AES 加密 9 | * 10 | * @param password 未加密的密码 11 | * @param salt 盐值,默认使用用户名就可 12 | * @return 13 | * @throws Exception 14 | */ 15 | public static String encrypt(String password, String salt) throws Exception { 16 | return AesUtil.encrypt(Md5Util.MD5(salt + CommonConstants.SALT_SECURITY_KEY), password); 17 | } 18 | 19 | /** 20 | * AES 解密 21 | * 22 | * @param encryptPassword 加密后的密码 23 | * @param salt 盐值,默认使用用户名就可 24 | * @return 25 | * @throws Exception 26 | */ 27 | public static String decrypt(String encryptPassword, String salt) throws Exception { 28 | return AesUtil.decrypt(Md5Util.MD5(salt + CommonConstants.SALT_SECURITY_KEY), encryptPassword); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{yyyy-MM-dd HH:mm:ss} [%class:%line] %-5level %logger - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/mybatis/SysUserRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 20 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/back_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/back_disabled.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/back_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/back_enabled.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/back_enabled_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/back_enabled_hover.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/chooseImg_N.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/chooseImg_N.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/chooseImg_S.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/chooseImg_S.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/favicon.ico -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/favicon.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/forward_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/forward_disabled.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/forward_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/forward_enabled.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/forward_enabled_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/forward_enabled_hover.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/loading.gif -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/picture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/picture.jpg -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/transparent.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/upload.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/static/assets/images/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-shiro/src/main/resources/static/assets/images/user.png -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | <#include "layout/header.ftl"/> 2 |
3 |
4 |
5 |

6 | Springboot Shiro学习 7 |

8 |
9 |
10 |
11 | 12 | <#include "layout/footer.ftl"/> -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/layout/setting.ftl: -------------------------------------------------------------------------------- 1 |
2 | 22 |
-------------------------------------------------------------------------------- /springboot-shiro/src/test/java/com/example/springbootshiro/SpringbootShiroApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootshiro; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootShiroApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-start/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml -------------------------------------------------------------------------------- /springboot-start/doc/新建springboot项目过程.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-start/doc/新建springboot项目过程.doc -------------------------------------------------------------------------------- /springboot-start/src/main/java/com/example/springbootstart/SpringbootStartApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootstart; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootStartApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootStartApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /springboot-start/src/main/java/com/example/springbootstart/controller/StartController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootstart.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * descripiton: 8 | * 9 | * @author: kinson(2219945910 @ qq.com) 10 | * @date: 2019/1/12 11 | * @time: 21:38 12 | * @modifier: 13 | * @since: 14 | */ 15 | @RestController 16 | @RequestMapping(value = "/start") 17 | public class StartController { 18 | 19 | @RequestMapping(value = "/hello") 20 | // @ResponseBody 21 | public String hello() { 22 | System.out.println("coming in"); 23 | return "hello, Springboot"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-start/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-start/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-start/src/test/java/com/example/springbootstart/SpringbootStartApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootstart; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootStartApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /springboot-storage/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-storage/src/main/java/com/example/springbootqiniu/SpringbootStorageApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootqiniu; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootStorageApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootStorageApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-storage/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | storage: 5 | #accessKey 6 | AK: xxxx 7 | #secretKey 8 | SK: xxxx 9 | #访问域名 10 | domain: xxxx 11 | #存储名 12 | bucket: xxxx -------------------------------------------------------------------------------- /springboot-storage/src/main/resources/static/images/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-storage/src/main/resources/static/images/user.png -------------------------------------------------------------------------------- /springboot-storage/src/test/java/com/example/springbootqiniu/SpringbootStorageApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootqiniu; 2 | 3 | import com.example.springbootqiniu.storage.AliOssStorage; 4 | import com.example.springbootqiniu.storage.QiNiuStorage; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | public class SpringbootStorageApplicationTests { 14 | 15 | @Test 16 | public void contextLoads() { 17 | } 18 | 19 | @Autowired 20 | private QiNiuStorage qiNiuStorage; 21 | 22 | @Autowired 23 | private AliOssStorage aliOssStorage; 24 | 25 | @Test 26 | public void test() { 27 | // qiNiuStorage.upload(); 28 | // qiNiuStorage.deleteFile(); 29 | aliOssStorage.upload(); 30 | aliOssStorage.delete(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-swagger/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/java/com/example/springbootswagger/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootswagger; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootSwaggerApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/java/com/example/springbootswagger/SpringbootSwaggerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootswagger; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 6 | 7 | 8 | @SpringBootApplication 9 | public class SpringbootSwaggerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootSwaggerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/java/com/example/springbootswagger/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootswagger.domain; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910@qq.com) 9 | * @date: 2019/9/11 10 | * @time: 0:20 11 | * @modifier: 12 | * @since: 13 | */ 14 | @Data 15 | public class User { 16 | 17 | private Long id; 18 | 19 | private String name; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 控制开启或关闭swagger 2 | swagger.enabled=true 3 | -------------------------------------------------------------------------------- /springboot-swagger/src/test/java/com/example/springbootswagger/SpringbootSwaggerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootswagger; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootSwaggerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-thymeleaf/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/example/springbootthymeleaf/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootthymeleaf; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootThymeleafApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/example/springbootthymeleaf/SpringbootThymeleafApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootthymeleaf; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootThymeleafApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootThymeleafApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/example/springbootthymeleaf/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootthymeleaf.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.ui.ModelMap; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | /** 9 | * descripiton: 10 | * 11 | * @author: kinson(2219945910 @ qq.com) 12 | * @date: 2019/2/17 13 | * @time: 12:03 14 | * @modifier: 15 | * @since: 16 | */ 17 | @Controller 18 | @RequestMapping(value = "thymeleaf") 19 | public class IndexController { 20 | 21 | @RequestMapping(value = "index/hello") 22 | public String index(Model model, ModelMap modelMap) { 23 | 24 | model.addAttribute("hello", "thymeleaf"); 25 | 26 | modelMap.addAttribute("hi", "thymeleaf"); 27 | 28 | return "index"; 29 | } 30 | 31 | @RequestMapping(value = "hello") 32 | public String hello(ModelMap modelMap) { 33 | 34 | modelMap.put("hei", "thymeleaf"); 35 | 36 | return "hello"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | #thymeleaf 3 | spring.thymeleaf.cache=false 4 | spring.thymeleaf.prefix=classpath:/templates/ 5 | spring.thymeleaf.check-template-location=true 6 | spring.thymeleaf.suffix=.html 7 | spring.thymeleaf.encoding=UTF-8 8 | spring.thymeleaf.servlet.content-type=text/html 9 | spring.thymeleaf.mode=HTML 10 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/static/css/style.css: -------------------------------------------------------------------------------- 1 | h4 { 2 | color: red; 3 | } 4 | 5 | p { 6 | color: blue; 7 | } -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | Spring Boot Application 9 | 10 | 11 | 12 | 13 | 14 |

hei

15 | 16 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Spring Boot Application 7 | 8 | 9 | 10 | 11 |

Welcome to Thymeleaf Spring Boot web application

12 |

hello

13 |

hi

14 | 15 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/test/java/com/example/springbootthymeleaf/SpringbootThymeleafApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootthymeleaf; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootThymeleafApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-transactional/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/java/com/example/springboottransactional/SpringbootTransactionalApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springboottransactional; 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.transaction.annotation.EnableTransactionManagement; 7 | 8 | @SpringBootApplication 9 | @EnableTransactionManagement 10 | @MapperScan(basePackages = {"com.example.springboottransactional.mapper"}) 11 | public class SpringbootTransactionalApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringbootTransactionalApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/java/com/example/springboottransactional/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.example.springboottransactional.domain; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * descripiton: 7 | * 8 | * @author: kinson(2219945910 @ qq.com) 9 | * @date: 2019/1/31 10 | * @time: 21:42 11 | * @modifier: 12 | * @since: 13 | */ 14 | @Data 15 | public class User { 16 | 17 | private Integer userId; 18 | 19 | private String userName; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/java/com/example/springboottransactional/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.springboottransactional.mapper; 2 | 3 | import com.example.springboottransactional.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:43 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserMapper { 17 | 18 | List selectUserList(); 19 | 20 | User selectUserById(final Integer id); 21 | 22 | void delete(final Integer id); 23 | 24 | void update(final User user); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/java/com/example/springboottransactional/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.springboottransactional.service; 2 | 3 | import com.example.springboottransactional.domain.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * descripiton: 9 | * 10 | * @author: kinson(2219945910 @ qq.com) 11 | * @date: 2019/1/31 12 | * @time: 21:55 13 | * @modifier: 14 | * @since: 15 | */ 16 | public interface UserService { 17 | 18 | List listUser(); 19 | 20 | User selectUserById(final Integer id); 21 | 22 | void delete(final Integer id); 23 | 24 | void update(final User user); 25 | } 26 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #设置应用端口 2 | server: 3 | port: 8080 4 | 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | 12 | # MyBatis 13 | mybatis: 14 | type-aliases-package: com.example.springboottransactional.domain 15 | mapper-locations: classpath:/mybatis/*.xml 16 | #sql打印配置 17 | configuration: 18 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 19 | -------------------------------------------------------------------------------- /springboot-transactional/src/main/resources/mybatis/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 19 | 20 | 21 | update user set user_name = #{userName} where user_id = #{userId} 22 | 23 | 24 | 25 | delete from user where user_id = #{id} 26 | 27 | 28 | -------------------------------------------------------------------------------- /springboot-transactional/src/test/java/com/example/springboottransactional/SpringbootTransactionalApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springboottransactional; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootTransactionalApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-webservice/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-webservice/src/main/java/com/example/springbootwebservice/SpringbootWebserviceApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootWebserviceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootWebserviceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-webservice/src/main/java/com/example/springbootwebservice/config/WSConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebservice.config; 2 | 3 | import com.example.springbootwebservice.config.client.WsClient; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller; 7 | 8 | @Configuration 9 | public class WSConfig { 10 | 11 | @Bean 12 | public Jaxb2Marshaller marshaller() { 13 | 14 | Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 15 | marshaller.setContextPath("com.example.springbootwebservice.domain"); 16 | return marshaller; 17 | } 18 | 19 | @Bean 20 | public WsClient wsClient(Jaxb2Marshaller marshaller) { 21 | 22 | WsClient client = new WsClient(); 23 | client.setDefaultUri("http://127.0.0.1:8080/ws/countries.wsdl"); 24 | client.setMarshaller(marshaller); 25 | client.setUnmarshaller(marshaller); 26 | 27 | return client; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /springboot-webservice/src/main/java/com/example/springbootwebservice/config/client/WsClient.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebservice.config.client; 2 | 3 | import com.example.springbootwebservice.domain.GetCountryRequest; 4 | import com.example.springbootwebservice.domain.GetCountryResponse; 5 | import org.springframework.ws.client.core.support.WebServiceGatewaySupport; 6 | 7 | public class WsClient extends WebServiceGatewaySupport { 8 | 9 | public GetCountryResponse getCountry(String name) { 10 | 11 | GetCountryRequest request = new GetCountryRequest(); 12 | request.setName(name); 13 | //连接服务端 14 | GetCountryResponse response = (GetCountryResponse) getWebServiceTemplate() 15 | .marshalSendAndReceive( 16 | "http://127.0.0.1:8080/ws/countries.wsdl", 17 | request); 18 | 19 | return response; 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-webservice/src/main/java/com/example/springbootwebservice/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebservice.controller; 2 | 3 | import com.example.springbootwebservice.config.client.WsClient; 4 | import com.example.springbootwebservice.domain.GetCountryResponse; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class IndexController { 11 | 12 | @Autowired 13 | private WsClient wsClient; 14 | 15 | @RequestMapping("getCountry") 16 | public Object getCountry(String name) { 17 | GetCountryResponse response = wsClient.getCountry(name); 18 | 19 | return response.getCountry(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /springboot-webservice/src/main/java/com/example/springbootwebservice/domain/Currency.java: -------------------------------------------------------------------------------- 1 | 2 | package com.example.springbootwebservice.domain; 3 | 4 | import javax.xml.bind.annotation.XmlEnum; 5 | import javax.xml.bind.annotation.XmlType; 6 | 7 | 8 | /** 9 | *

currency�� Java �ࡣ 10 | * 11 | *

����ģʽƬ��ָ�������ڴ����е�Ԥ�����ݡ� 12 | *

13 | *

14 |  * <simpleType name="currency">
15 |  *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
16 |  *     <enumeration value="GBP"/>
17 |  *     <enumeration value="EUR"/>
18 |  *     <enumeration value="PLN"/>
19 |  *   </restriction>
20 |  * </simpleType>
21 |  * 
22 | */ 23 | @XmlType(name = "currency", namespace = "http://127.0.0.1:8080/ws") 24 | @XmlEnum 25 | public enum Currency { 26 | 27 | GBP, 28 | EUR, 29 | PLN; 30 | 31 | public String value() { 32 | return name(); 33 | } 34 | 35 | public static Currency fromValue(String v) { 36 | return valueOf(v); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /springboot-webservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /springboot-webservice/src/test/java/com/example/springbootwebservice/SpringbootWebserviceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootWebserviceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-websocket/.gitignore: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Build Tools 3 | 4 | .gradle 5 | /build/ 6 | !gradle/wrapper/gradle-wrapper.jar 7 | 8 | target/ 9 | !.mvn/wrapper/maven-wrapper.jar 10 | 11 | ###################################################################### 12 | # IDE 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | 28 | ### NetBeans ### 29 | nbproject/private/ 30 | build/* 31 | nbbuild/ 32 | dist/ 33 | nbdist/ 34 | .nb-gradle/ 35 | 36 | ###################################################################### 37 | # Others 38 | *.log 39 | *.xml.versionsBackup 40 | 41 | !*/build/*.java 42 | !*/build/*.html 43 | !*/build/*.xml 44 | -------------------------------------------------------------------------------- /springboot-websocket/README.md: -------------------------------------------------------------------------------- 1 | # springboot集成websocket 2 | 3 | ## pom依赖引入 4 | 5 | 6 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootWebsocketApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/SpringbootWebsocketApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootWebsocketApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootWebsocketApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter; 6 | 7 | /** 8 | * 开启WebSocket支持 9 | */ 10 | @Configuration 11 | public class WebSocketConfig { 12 | 13 | @Bean 14 | public ServerEndpointExporter serverEndpointExporter() { 15 | return new ServerEndpointExporter(); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/server/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket.server; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.example.springbootwebsocket.domain.Message; 5 | import com.example.springbootwebsocket.utils.StringUtil; 6 | 7 | /** 8 | * 公共逻辑 9 | */ 10 | public abstract class BaseController extends AbstractWsController { 11 | 12 | private static final String CONNECT_TYPE_TEXT = "text"; 13 | 14 | /** 15 | * 接受客户端发送的字符串 16 | * 17 | * @param message 字符串消息 18 | */ 19 | @Override 20 | protected void onMessage(String message) { 21 | Message msg = JSONObject.parseObject(message, Message.class); 22 | msg.setHost(getUserName()); 23 | if (CONNECT_TYPE_TEXT.equals(getConnectType())) { 24 | msg.setMsg(StringUtil.txt2htm(msg.getMsg())); 25 | if (msg.getDests() == null) { 26 | broadcast2All(msg.toString()); 27 | } else { 28 | broadcast2Special(msg.toString(), msg.getDests()); 29 | } 30 | } else { 31 | broadcast2Others(msg.toString()); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/server/BaseMediaController.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket.server; 2 | 3 | import javax.websocket.EndpointConfig; 4 | import javax.websocket.Session; 5 | import java.io.IOException; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * 公共逻辑 11 | */ 12 | public abstract class BaseMediaController extends BaseController { 13 | 14 | @Override 15 | public void onOpen(Session session, EndpointConfig config) { 16 | // 设置用户信息 17 | Map> map = session.getRequestParameterMap(); 18 | setSession(session); 19 | List uids = map.get("uid"); 20 | if (uids == null) { 21 | try { 22 | this.getSession().close(); 23 | } catch (IOException ignored) { 24 | } 25 | } else { 26 | setUserName(uids.get(0)); 27 | super.onOpen(session, config); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/com/example/springbootwebsocket/utils/IdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket.utils; 2 | 3 | import java.util.concurrent.locks.Lock; 4 | import java.util.concurrent.locks.ReentrantLock; 5 | 6 | /** 7 | * 获取随机id (时间戳 + 服务器id + 2位数字序号) 8 | * 9 | */ 10 | public class IdGenerator { 11 | 12 | private static int SERVER_ID = 0; 13 | private static final long LIMIT = 10; 14 | private static final Lock LOCK = new ReentrantLock(); 15 | private static long LastTime = System.currentTimeMillis(); 16 | private static int COUNT = 0; 17 | 18 | public static String getNextId() { 19 | LOCK.lock(); 20 | try { 21 | while (true) { 22 | long now = System.currentTimeMillis(); 23 | if (now == LastTime) { 24 | if (++COUNT == LIMIT) { 25 | try { 26 | Thread.currentThread(); 27 | Thread.sleep(1); 28 | } catch (InterruptedException ignored) { 29 | } 30 | continue; 31 | } 32 | } else { 33 | LastTime = now; 34 | COUNT = 0; 35 | } 36 | break; 37 | } 38 | } finally { 39 | LOCK.unlock(); 40 | } 41 | 42 | return String.format("%d%d%02d", LastTime, SERVER_ID, COUNT); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver 3 | spring.datasource.url = jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 4 | spring.datasource.username = root 5 | spring.datasource.password = xxx 6 | 7 | spring.thymeleaf.cache=false 8 | spring.thymeleaf.prefix=classpath:/templates/ 9 | spring.thymeleaf.check-template-location=true 10 | spring.thymeleaf.suffix=.html 11 | spring.thymeleaf.encoding=UTF-8 12 | spring.thymeleaf.servlet.content-type=text/html 13 | spring.thymeleaf.mode=HTML5 14 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/Toolbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/Toolbar.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/btn_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/btn_close_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_down.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/btn_close_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_hover.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/canvaspost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/canvaspost.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/headpic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/headpic.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/mod_chat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_chat.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/mod_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_file.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/mod_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_video.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/mod_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_voice.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/photo_loading.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/photo_loading.jpg -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/sprite_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/sprite_main.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/static/pic/websocket/videopost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/videopost.png -------------------------------------------------------------------------------- /springboot-websocket/src/main/resources/templates/index3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /springboot-websocket/src/test/java/com/example/springbootwebsocket/SpringbootWebsocketApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.springbootwebsocket; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootWebsocketApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------