├── .gitignore
├── README.md
├── chapter1-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter1
│ │ │ ├── Chapter1Application.java
│ │ │ └── controller
│ │ │ └── HelloController.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter1
│ └── Chapter1ApplicationTests.java
├── chapter2-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter21
│ │ │ ├── Chapter21Application.java
│ │ │ ├── controller
│ │ │ └── HelloController.java
│ │ │ └── service
│ │ │ └── BlogService.java
│ └── resources
│ │ ├── application-dev.properties
│ │ ├── application-online.properties
│ │ ├── application-test.properties
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter21
│ └── Chapter21ApplicationTests.java
├── chapter3-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter31
│ │ │ ├── Chapter31Application.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ └── domain
│ │ │ └── User.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter31
│ └── Chapter31ApplicationTests.java
├── chapter3-2
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter32
│ │ │ ├── Chapter32Application.java
│ │ │ └── controller
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ └── index.html
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter32
│ └── Chapter32ApplicationTests.java
├── chapter3-3
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter33
│ │ │ ├── Chapter33Application.java
│ │ │ └── controller
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ ├── index.ftl
│ │ └── login.ftl
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter33
│ └── Chapter33ApplicationTests.java
├── chapter3-4
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter34
│ │ │ ├── Chapter34Application.java
│ │ │ └── controller
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ └── index.vm
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter34
│ └── Chapter34ApplicationTests.java
├── chapter3-5
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter35
│ │ │ ├── Chapter35Application.java
│ │ │ ├── config
│ │ │ └── SwaggerConfig.java
│ │ │ └── controller
│ │ │ └── HelloController.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter35
│ └── Chapter35ApplicationTests.java
├── chapter3-6
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter36
│ │ │ ├── Chapter36Application.java
│ │ │ ├── controller
│ │ │ └── HelloController.java
│ │ │ ├── dto
│ │ │ └── ErrorInfo.java
│ │ │ └── exception
│ │ │ ├── GlobalExceptionHandler.java
│ │ │ └── MyException.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ ├── error.html
│ │ └── index.html
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter36
│ └── Chapter36ApplicationTests.java
├── chapter3-7
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── README.md
├── front-vue
│ ├── .babelrc
│ ├── .editorconfig
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .postcssrc.js
│ ├── README.md
│ ├── config
│ │ ├── dev.env.js
│ │ ├── index.js
│ │ └── prod.env.js
│ ├── index.html
│ ├── package.json
│ ├── src
│ │ ├── App.vue
│ │ ├── assets
│ │ │ └── logo.png
│ │ ├── components
│ │ │ └── HelloWorld.vue
│ │ ├── main.js
│ │ └── router
│ │ │ └── index.js
│ ├── static
│ │ └── .gitkeep
│ └── yarn.lock
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter37
│ │ │ ├── Chapter37Application.java
│ │ │ ├── config
│ │ │ └── WebMvcConfig.java
│ │ │ └── controller
│ │ │ └── IndexController.java
│ └── resources
│ │ ├── application.properties
│ │ ├── static
│ │ ├── css
│ │ │ └── app.739f1ad65f043fab3efe7a450cd54da9.css
│ │ └── js
│ │ │ ├── app.de27c634d7ad9dab3885.js
│ │ │ ├── app.de27c634d7ad9dab3885.js.map
│ │ │ ├── manifest.ff985a587e3fe0e8abca.js
│ │ │ ├── manifest.ff985a587e3fe0e8abca.js.map
│ │ │ ├── vendor.dea99b46850552e56485.js
│ │ │ └── vendor.dea99b46850552e56485.js.map
│ │ └── templates
│ │ └── index.ftl
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter37
│ └── Chapter37ApplicationTests.java
├── chapter4-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter41
│ │ │ ├── Chapter41Application.java
│ │ │ └── service
│ │ │ ├── UserService.java
│ │ │ └── UserServiceImpl.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter41
│ └── Chapter41ApplicationTests.java
├── chapter4-10
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── data
│ └── elasticsearch
│ │ └── nodes
│ │ └── 0
│ │ ├── _state
│ │ └── global-0.st
│ │ └── node.lock
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter410
│ │ │ ├── Chapter410Application.java
│ │ │ ├── config
│ │ │ └── ElasticSearchConfig.java
│ │ │ ├── domain
│ │ │ └── User.java
│ │ │ ├── repository
│ │ │ └── UserRepository.java
│ │ │ └── service
│ │ │ ├── UserService.java
│ │ │ └── UserServiceImpl.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter410
│ └── Chapter410ApplicationTests.java
├── chapter4-11
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter411
│ │ │ ├── Chapter411Application.java
│ │ │ ├── domain
│ │ │ └── User.java
│ │ │ ├── repository
│ │ │ └── UserRepository.java
│ │ │ └── service
│ │ │ ├── UserService.java
│ │ │ └── UserServiceImpl.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter411
│ └── Chapter411ApplicationTests.java
├── chapter4-12
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter412
│ │ │ ├── Chapter412Application.java
│ │ │ ├── codegen
│ │ │ ├── GenerationCodeUtil.java
│ │ │ ├── GenerationRepo.java
│ │ │ ├── GenerationService.java
│ │ │ ├── SimpleConfGenerator.java
│ │ │ └── SimpleJavaGenerator.java
│ │ │ ├── config
│ │ │ ├── BdUseDbConfig.java
│ │ │ ├── DadaDbConfig.java
│ │ │ ├── JOOQConfig.java
│ │ │ ├── SpringTransaction.java
│ │ │ └── SpringTransactionProvider.java
│ │ │ ├── constant
│ │ │ └── Constants.java
│ │ │ ├── entity
│ │ │ └── test
│ │ │ │ ├── DefaultCatalog.java
│ │ │ │ ├── Keys.java
│ │ │ │ ├── Tables.java
│ │ │ │ ├── Test.java
│ │ │ │ └── tables
│ │ │ │ ├── User.java
│ │ │ │ ├── pojos
│ │ │ │ └── User.java
│ │ │ │ └── records
│ │ │ │ └── UserRecord.java
│ │ │ ├── repository
│ │ │ ├── BaseRepository.java
│ │ │ ├── TestBaseRepository.java
│ │ │ └── test
│ │ │ │ └── UserRepository.java
│ │ │ ├── service
│ │ │ └── test
│ │ │ │ └── UserService.java
│ │ │ └── utils
│ │ │ └── CamelUnderlineTransformUtils.java
│ └── resources
│ │ ├── application.properties
│ │ └── test_2017-11-06.sql
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter412
│ └── Chapter412ApplicationTests.java
├── chapter4-13
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter413
│ │ │ ├── Chapter413Application.java
│ │ │ ├── controller
│ │ │ └── CityController.java
│ │ │ ├── domain
│ │ │ └── City.java
│ │ │ └── mapper
│ │ │ └── CityMapper.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter413
│ └── Chapter413ApplicationTests.java
├── chapter4-2
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter42
│ │ │ ├── Chapter42Application.java
│ │ │ ├── dao
│ │ │ └── BdChargeInfoRepository.java
│ │ │ └── domain
│ │ │ └── BdChargeInfo.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter42
│ └── Chapter42ApplicationTests.java
├── chapter4-3
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter43
│ │ │ ├── Chapter43Application.java
│ │ │ └── config
│ │ │ └── DataSourceConfig.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter43
│ └── Chapter43ApplicationTests.java
├── chapter4-4
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter44
│ │ │ ├── Chapter44Application.java
│ │ │ ├── DataSourceConfig.java
│ │ │ ├── PrimaryConfig.java
│ │ │ ├── SecondaryConfig.java
│ │ │ └── domain
│ │ │ ├── p
│ │ │ ├── User.java
│ │ │ └── UserRepository.java
│ │ │ └── s
│ │ │ ├── Message.java
│ │ │ └── MessageRepository.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter44
│ └── Chapter44ApplicationTests.java
├── chapter4-5
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter45
│ │ │ ├── Chapter45Application.java
│ │ │ ├── RedisConfig.java
│ │ │ ├── RedisObjectSerializer.java
│ │ │ └── domain
│ │ │ └── User.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter45
│ └── Chapter45ApplicationTests.java
├── chapter4-6
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter46
│ │ │ ├── Chapter46Application.java
│ │ │ └── domain
│ │ │ ├── User.java
│ │ │ └── UserRepository.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter46
│ └── Chapter46ApplicationTests.java
├── chapter4-7
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter47
│ │ │ ├── Chapter47Application.java
│ │ │ └── domain
│ │ │ ├── User.java
│ │ │ └── UserMapper.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter47
│ └── Chapter47ApplicationTests.java
├── chapter4-8
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter48
│ │ │ ├── Chapter48Application.java
│ │ │ └── domain
│ │ │ ├── User.java
│ │ │ └── UserMapper.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter48
│ └── Chapter48ApplicationTests.java
├── chapter4-9
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter49
│ │ │ ├── Chapter49Application.java
│ │ │ ├── domain
│ │ │ ├── User.java
│ │ │ └── UserRepository.java
│ │ │ └── service
│ │ │ └── UserService.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter49
│ └── Chapter49ApplicationTests.java
├── chapter5-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter51
│ │ │ ├── Chapter51Application.java
│ │ │ └── task
│ │ │ └── ScheduledTasks.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter51
│ └── Chapter51ApplicationTests.java
├── chapter5-2
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter52
│ │ │ ├── Chapter52Application.java
│ │ │ └── task
│ │ │ └── Task.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter52
│ └── Chapter52ApplicationTests.java
├── chapter5-3
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── logs
│ ├── all.log
│ ├── error.log
│ └── my.log
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter53
│ │ │ └── Chapter53Application.java
│ └── resources
│ │ ├── application-dev.properties
│ │ ├── application-prod.properties
│ │ ├── application-test.properties
│ │ ├── application.properties
│ │ └── log4j.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter53
│ └── Chapter53ApplicationTests.java
├── chapter5-4
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter54
│ │ │ ├── Chapter54Application.java
│ │ │ ├── aspect
│ │ │ └── WebLogAspect.java
│ │ │ ├── log
│ │ │ └── MongoAppender.java
│ │ │ └── web
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── log4j.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter54
│ └── Chapter54ApplicationTests.java
├── chapter5-5
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── logs
│ ├── all.log
│ ├── error.log
│ └── my.log
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter55
│ │ │ ├── Chapter55Application.java
│ │ │ ├── aspect
│ │ │ └── WebLogAspect.java
│ │ │ └── web
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── log4j.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter55
│ └── Chapter55ApplicationTests.java
├── chapter5-6
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter56
│ │ │ ├── Chapter56Application.java
│ │ │ ├── config
│ │ │ └── WebSecurityConfig.java
│ │ │ └── web
│ │ │ └── HelloController.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ ├── hello.html
│ │ ├── index.html
│ │ └── login.html
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter56
│ └── Chapter56ApplicationTests.java
├── chapter6-1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── man.jpg
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter61
│ │ │ └── Chapter61Application.java
│ └── resources
│ │ ├── application.properties
│ │ └── templates
│ │ └── template.vm
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter61
│ └── Chapter61ApplicationTests.java
├── chapter6-2
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter62
│ │ │ ├── Chapter62Application.java
│ │ │ └── rabbit
│ │ │ ├── RabbitConfig.java
│ │ │ ├── Receiver.java
│ │ │ └── Sender.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter62
│ └── Chapter62ApplicationTests.java
├── chapter6-3
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter63
│ │ │ ├── Chapter63Application.java
│ │ │ ├── EventConfig.java
│ │ │ ├── Events.java
│ │ │ ├── StateMachineConfig.java
│ │ │ └── States.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter63
│ └── Chapter63ApplicationTests.java
├── chapter6-4
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── frank
│ │ │ └── chapter64
│ │ │ ├── Chapter64Application.java
│ │ │ ├── config
│ │ │ ├── DataflowJobConfig.java
│ │ │ ├── EmbedZookeeperServer.java
│ │ │ ├── JobEventConfig.java
│ │ │ ├── SimpleJobConfig.java
│ │ │ └── ZookeeperRegistryCenterConfig.java
│ │ │ ├── domain
│ │ │ └── Foo.java
│ │ │ ├── job
│ │ │ ├── dataflow
│ │ │ │ └── SpringDataflowJob.java
│ │ │ └── simple
│ │ │ │ └── SpringSimpleJob.java
│ │ │ └── repository
│ │ │ └── FooRepository.java
│ └── resources
│ │ ├── application-dev.properties
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── frank
│ └── chapter64
│ └── Chapter64ApplicationTests.java
├── chapter7-1-1
├── .gitignore
├── .idea
│ └── workspace.xml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── william
│ │ └── chapter711
│ │ └── Chapter711Application.java
│ └── resources
│ └── application.properties
└── chapter7-1
├── .gitignore
├── pom.xml
└── src
└── main
├── java
└── com
│ └── william
│ └── chapter71
│ ├── autoconfigure
│ ├── GreeterAutoConfiguration.java
│ └── GreeterProperties.java
│ └── domain
│ ├── Greeter.java
│ └── GreeterConfig.java
└── resources
└── META-INF
└── spring.factories
/.gitignore:
--------------------------------------------------------------------------------
1 | .mvn/*
2 | mvnw
3 | mvnw.cmd
4 | *.iml
5 | target/*
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SpringBootDemo
2 | SpringBoot教程系列,用于实战SprinBoot常用到的技术点
3 |
--------------------------------------------------------------------------------
/chapter1-1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter1-1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter1-1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter1-1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter1-1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.frank
7 | chapter1
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | chapter1
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.4.0.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 | test
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/chapter1-1/src/main/java/com/frank/chapter1/Chapter1Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter1;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter1Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter1Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter1-1/src/main/java/com/frank/chapter1/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter1.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * Created by jianweilin on 2017/10/9.
9 | */
10 | @RestController
11 | public class HelloController {
12 | @RequestMapping(value = "/hello",method = RequestMethod.GET)
13 | public String index(){
14 | return "Hello World!";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter1-1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter1-1/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter1-1/src/test/java/com/frank/chapter1/Chapter1ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter1;
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 Chapter1ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter2-1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter2-1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter2-1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter2-1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter2-1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.frank
7 | chapter2-1
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | chapter2-1
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.4.0.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 | test
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/chapter2-1/src/main/java/com/frank/chapter21/Chapter21Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter21;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter21Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter21Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter2-1/src/main/java/com/frank/chapter21/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter21.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestMethod;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * Created by jianweilin on 2017/10/9.
9 | */
10 | @RestController
11 | public class HelloController {
12 | @RequestMapping(value = "/hello",method= RequestMethod.GET)
13 | public String index(){
14 | return "Hello World!";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter2-1/src/main/java/com/frank/chapter21/service/BlogService.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter21.service;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * Created by jianweilin on 2017/10/9.
8 | */
9 | @Component
10 | public class BlogService {
11 |
12 | @Value("${com.frank.blog.name}")
13 | private String name;
14 | @Value("${com.frank.blog.title}")
15 | private String title;
16 | @Value("${com.frank.blog.desc}")
17 | private String desc;
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 |
27 | public String getTitle() {
28 | return title;
29 | }
30 |
31 | public void setTitle(String title) {
32 | this.title = title;
33 | }
34 |
35 | public String getDesc() {
36 | return desc;
37 | }
38 |
39 | public void setDesc(String desc) {
40 | this.desc = desc;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/chapter2-1/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | server.port=1111
--------------------------------------------------------------------------------
/chapter2-1/src/main/resources/application-online.properties:
--------------------------------------------------------------------------------
1 | server.port=2222
--------------------------------------------------------------------------------
/chapter2-1/src/main/resources/application-test.properties:
--------------------------------------------------------------------------------
1 | server.port=3333
--------------------------------------------------------------------------------
/chapter2-1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | com.frank.blog.name=dayday up
2 | com.frank.blog.title=SpringBoot
3 | com.frank.blog.desc=${com.frank.blog.name},writing ${com.frank.blog.title}
4 | spring.profiles.active=dev
--------------------------------------------------------------------------------
/chapter2-1/src/test/java/com/frank/chapter21/Chapter21ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter21;
2 |
3 | import com.frank.chapter21.service.BlogService;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | public class Chapter21ApplicationTests {
15 | private static final Logger logger = LoggerFactory.getLogger(Chapter21ApplicationTests.class);
16 |
17 | @Autowired
18 | private BlogService blogService;
19 |
20 | @Test
21 | public void test_001() {
22 | logger.info("name: " + blogService.getName());
23 | logger.info("title: " + blogService.getTitle());
24 | logger.info("desc: " + blogService.getDesc());
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/chapter3-1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-1/src/main/java/com/frank/chapter31/Chapter31Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter31;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter31Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter31Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-1/src/main/java/com/frank/chapter31/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter31.controller;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.frank.chapter31.domain.User;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by jianweilin on 2017/10/11.
13 | */
14 | @RestController
15 | public class UserController {
16 | private static final Logger logger = LoggerFactory.getLogger(UserController.class);
17 |
18 | @RequestMapping(value = "/list",method = RequestMethod.GET)
19 | public List getUserList(){
20 | return User.initUsers();
21 | }
22 |
23 | @RequestMapping(value = "/",method = RequestMethod.POST)
24 | public String postUser(@ModelAttribute User user){
25 | logger.info("user => " + JSON.toJSONString(user));
26 | return "add success";
27 | }
28 |
29 | @RequestMapping(value = "/{id}",method = RequestMethod.GET)
30 | public User getUser(@PathVariable Long id) {
31 | logger.info("userId => " + id);
32 | return new User(id,"init",0);
33 | }
34 |
35 | @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
36 | public User putUser(@PathVariable Long id,@ModelAttribute User user) {
37 | logger.info("userId => " + id);
38 | return new User(id,user.getName(),user.getAge());
39 | }
40 |
41 | @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
42 | public String deleteUser(@PathVariable Long id) {
43 | logger.info("delte userId => " + id);
44 | return "delete success";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/chapter3-1/src/main/java/com/frank/chapter31/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter31.domain;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by jianweilin on 2017/10/11.
8 | */
9 | public class User {
10 | private Long id;
11 | private String name;
12 | private Integer age;
13 |
14 | public static List initUsers(){
15 | return Arrays.asList(new User(1L, "张三", 21), new User(2L, "李四", 22));
16 | }
17 |
18 | public User() {
19 | }
20 |
21 | public User(Long id, String name, Integer age) {
22 | this.id = id;
23 | this.name = name;
24 | this.age = age;
25 | }
26 |
27 | public Long getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Long id) {
32 | this.id = id;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public Integer getAge() {
44 | return age;
45 | }
46 |
47 | public void setAge(Integer age) {
48 | this.age = age;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapter3-1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-1/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter3-1/src/test/java/com/frank/chapter31/Chapter31ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter31;
2 |
3 | import com.frank.chapter31.controller.UserController;
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 | import org.springframework.test.web.servlet.MockMvc;
10 | import org.springframework.test.web.servlet.RequestBuilder;
11 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
12 |
13 | import static org.hamcrest.core.IsEqual.equalTo;
14 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
17 |
18 |
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | public class Chapter31ApplicationTests {
22 |
23 | private MockMvc mockMvc;
24 |
25 | @Before
26 | public void setUp(){
27 | mockMvc = MockMvcBuilders.standaloneSetup(new UserController()).build();
28 | }
29 |
30 | @Test
31 | public void test_001() throws Exception {
32 | // 测试UserController
33 | RequestBuilder request = null;
34 |
35 | request = post("/")
36 | .param("id","1")
37 | .param("name","测试大师")
38 | .param("age","11");
39 | mockMvc.perform(request).andExpect(status().isOk())
40 | .andExpect(content().string(equalTo("add success")));
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/chapter3-2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-2/src/main/java/com/frank/chapter32/Chapter32Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter32;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter32Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter32Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-2/src/main/java/com/frank/chapter32/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter32.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.ui.ModelMap;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | /**
10 | * Created by jianweilin on 2017/10/11.
11 | */
12 | @Controller
13 | public class HelloController {
14 | @ResponseBody
15 | @RequestMapping(value = "/hello",method = RequestMethod.GET)
16 | public String hello() {
17 | return "Hello World!";
18 | }
19 |
20 | @RequestMapping("/")
21 | public String index(ModelMap map){
22 | map.addAttribute("host","http://www.jianwl.com");
23 | return "index";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/chapter3-2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-2/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter3-2/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Hello World
9 |
10 |
--------------------------------------------------------------------------------
/chapter3-2/src/test/java/com/frank/chapter32/Chapter32ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter32;
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 Chapter32ApplicationTests {
11 | @Test
12 | public void test_001(){
13 |
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter3-3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-3/src/main/java/com/frank/chapter33/Chapter33Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter33;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter33Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter33Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-3/src/main/java/com/frank/chapter33/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter33.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.ui.ModelMap;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | /**
9 | * Created by jianweilin on 2017/10/11.
10 | */
11 | @Controller
12 | public class HelloController {
13 |
14 | @RequestMapping(value = "/index",method = RequestMethod.GET)
15 | public String index(ModelMap map) {
16 | map.addAttribute("host","http://www.jianwl.com");
17 | return "index";
18 | }
19 |
20 | @RequestMapping(value = "/",method = RequestMethod.GET)
21 | public String home() {
22 | return "login";
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/chapter3-3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=9000
--------------------------------------------------------------------------------
/chapter3-3/src/main/resources/templates/index.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | FreeMarker模板引擎
9 | ${host}
10 |
11 |
--------------------------------------------------------------------------------
/chapter3-3/src/main/resources/templates/login.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | 小工具平台
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/chapter3-3/src/test/java/com/frank/chapter33/Chapter33ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter33;
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 Chapter33ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter3-4/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-4/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-4/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-4/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-4/src/main/java/com/frank/chapter34/Chapter34Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter34;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter34Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter34Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-4/src/main/java/com/frank/chapter34/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter34.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.ui.ModelMap;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 |
8 | /**
9 | * Created by jianweilin on 2017/10/11.
10 | */
11 | @Controller
12 | public class HelloController {
13 | @RequestMapping(value = "/",method = RequestMethod.GET)
14 | public String index(ModelMap map) {
15 | map.addAttribute("host","http://www.jianwl.com");
16 | return "index";
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/chapter3-4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-4/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter3-4/src/main/resources/templates/index.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Velocity模板
9 | ${host}
10 |
11 |
--------------------------------------------------------------------------------
/chapter3-4/src/test/java/com/frank/chapter34/Chapter34ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter34;
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 Chapter34ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter3-5/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-5/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-5/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-5/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-5/src/main/java/com/frank/chapter35/Chapter35Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter35;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter35Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter35Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-5/src/main/java/com/frank/chapter35/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter35.controller;
2 |
3 | import io.swagger.annotations.*;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestMethod;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | /**
10 | *
11 | * Created by jianweilin on 2017/10/11.
12 | */
13 | @Api(value = "Hello接口模块")
14 | @RestController
15 | public class HelloController {
16 |
17 | // @ApiImplicitParams(
18 | // value = {
19 | // @ApiImplicitParam(paramType = "header",name="User-Id",required = true,dataType = "string"),
20 | // @ApiImplicitParam(paramType = "header",name="User-Token",required = true,dataType = "string")
21 | // }
22 | // )
23 | @ApiOperation(value = "hello world接口",notes = "swagger文档,请访问http://localhost:8080/swagger-ui.html")
24 | @RequestMapping(value = "/hello",method = RequestMethod.GET)
25 | public String index(@ApiParam(value = "名字",required = true)@RequestParam String name){
26 | return "Hello World: " + name ;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/chapter3-5/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-5/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter3-5/src/test/java/com/frank/chapter35/Chapter35ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter35;
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 Chapter35ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter3-6/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-6/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-6/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-6/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/java/com/frank/chapter36/Chapter36Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter36Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter36Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/java/com/frank/chapter36/controller/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36.controller;
2 |
3 | import com.frank.chapter36.exception.MyException;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.ui.ModelMap;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 |
9 | /**
10 | * Created by jianweilin on 2017/10/11.
11 | */
12 | @Controller
13 | public class HelloController {
14 |
15 | @RequestMapping(value = "/hello",method = RequestMethod.GET)
16 | public String hello() throws Exception {
17 | throw new Exception("发生错误");
18 | }
19 |
20 | @RequestMapping("/json")
21 | public String json() throws MyException {
22 | throw new MyException("发生错误2");
23 | }
24 |
25 | @RequestMapping("/")
26 | public String index(ModelMap map){
27 | map.addAttribute("host","http://jianwl.com");
28 | return "index";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/java/com/frank/chapter36/dto/ErrorInfo.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36.dto;
2 |
3 | /**
4 | * Created by jianweilin on 2017/10/11.
5 | */
6 | public class ErrorInfo {
7 | public static final Integer OK = 0;
8 | public static final Integer ERROR = 100;
9 |
10 | private Integer code;
11 | private String message;
12 | private String url;
13 | private T data;
14 |
15 | public static Integer getOK() {
16 | return OK;
17 | }
18 |
19 | public static Integer getERROR() {
20 | return ERROR;
21 | }
22 |
23 | public Integer getCode() {
24 | return code;
25 | }
26 |
27 | public void setCode(Integer code) {
28 | this.code = code;
29 | }
30 |
31 | public String getMessage() {
32 | return message;
33 | }
34 |
35 | public void setMessage(String message) {
36 | this.message = message;
37 | }
38 |
39 | public String getUrl() {
40 | return url;
41 | }
42 |
43 | public void setUrl(String url) {
44 | this.url = url;
45 | }
46 |
47 | public T getData() {
48 | return data;
49 | }
50 |
51 | public void setData(T data) {
52 | this.data = data;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/java/com/frank/chapter36/exception/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36.exception;
2 |
3 | import com.frank.chapter36.dto.ErrorInfo;
4 | import org.springframework.web.bind.annotation.ControllerAdvice;
5 | import org.springframework.web.bind.annotation.ExceptionHandler;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 | import org.springframework.web.servlet.ModelAndView;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 |
11 | /**
12 | * Created by jianweilin on 2017/10/11.
13 | */
14 | @ControllerAdvice
15 | public class GlobalExceptionHandler {
16 | @ExceptionHandler(value = Exception.class)
17 | public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception{
18 | ModelAndView mav = new ModelAndView();
19 | mav.addObject("exception",e);
20 | mav.addObject("url",req.getRequestURL());
21 | mav.setViewName("error");
22 | return mav;
23 | }
24 |
25 | @ExceptionHandler(value = MyException.class)
26 | @ResponseBody
27 | public ErrorInfo jsonErrorHandler(HttpServletRequest req, MyException e) throws Exception {
28 | ErrorInfo r = new ErrorInfo<>();
29 | r.setCode(ErrorInfo.ERROR);
30 | r.setData("Some Data");
31 | r.setMessage(e.getMessage());
32 | r.setUrl(req.getRequestURL().toString());
33 | return r;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/java/com/frank/chapter36/exception/MyException.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36.exception;
2 |
3 | /**
4 | * Created by jianweilin on 2017/10/11.
5 | */
6 | public class MyException extends Exception{
7 | public MyException(String message) {
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-6/src/main/resources/application.properties
--------------------------------------------------------------------------------
/chapter3-6/src/main/resources/templates/error.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 统一异常处理
6 |
7 |
8 | Error Handler
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter3-6/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | Hello World!
9 |
10 |
--------------------------------------------------------------------------------
/chapter3-6/src/test/java/com/frank/chapter36/Chapter36ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter36;
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 Chapter36ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter3-7/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter3-7/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-7/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter3-7/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter3-7/README.md:
--------------------------------------------------------------------------------
1 | ## Running Project
2 |
3 | ``` bash
4 | # use npm install vue-cli
5 | npm install -g vue-cli
6 |
7 | # init front-vue
8 | vue init webpack front-vue
9 |
10 | # cd front-vue project & run
11 | cd front-vue
12 | npm run dev
13 |
14 | # compile
15 | npm run build
16 |
17 | # copy index.html to springboot resource templates folder,rename index.ftl & copy js & css resource to springboot resources
18 |
19 | # run springboot
20 | ```
21 |
22 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
23 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parser: 'babel-eslint',
6 | parserOptions: {
7 | sourceType: 'module'
8 | },
9 | env: {
10 | browser: true,
11 | },
12 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
13 | extends: 'standard',
14 | // required to lint *.vue files
15 | plugins: [
16 | 'html'
17 | ],
18 | // add your custom rules here
19 | 'rules': {
20 | // allow paren-less arrow functions
21 | 'arrow-parens': 0,
22 | // allow async-await
23 | 'generator-star-spacing': 0,
24 | // allow debugger during development
25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {}
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/README.md:
--------------------------------------------------------------------------------
1 | # front-vue
2 |
3 | > A Vue.js project
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/config/index.js:
--------------------------------------------------------------------------------
1 |
2 | 'use strict'
3 | // Template version: 1.1.3
4 | // see http://vuejs-templates.github.io/webpack for documentation.
5 |
6 | const path = require('path')
7 |
8 | module.exports = {
9 | build: {
10 | env: require('./prod.env'),
11 | index: path.resolve(__dirname, '../dist/index.ftl'),
12 | assetsRoot: path.resolve(__dirname, '../dist'),
13 | assetsSubDirectory: 'static',
14 | assetsPublicPath: '/',
15 | productionSourceMap: true,
16 | // Gzip off by default as many popular static hosts such as
17 | // Surge or Netlify already gzip all static assets for you.
18 | // Before setting to `true`, make sure to:
19 | // npm install --save-dev compression-webpack-plugin
20 | productionGzip: false,
21 | productionGzipExtensions: ['js', 'css'],
22 | // Run the build command with an extra argument to
23 | // View the bundle analyzer report after build finishes:
24 | // `npm run build --report`
25 | // Set to `true` or `false` to always turn it on or off
26 | bundleAnalyzerReport: process.env.npm_config_report
27 | },
28 | dev: {
29 | env: require('./dev.env'),
30 | port: process.env.PORT || 8080,
31 | autoOpenBrowser: true,
32 | assetsSubDirectory: 'static',
33 | assetsPublicPath: '/',
34 | proxyTable: {},
35 | // CSS Sourcemaps off by default because relative paths are "buggy"
36 | // with this option, according to the CSS-Loader README
37 | // (https://github.com/webpack/css-loader#sourcemaps)
38 | // In our experience, they generally work as expected,
39 | // just be aware of this issue when enabling this option.
40 | cssSourceMap: false
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | front-vue
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |

4 |
5 |
6 |
7 |
8 |
13 |
14 |
24 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-7/front-vue/src/assets/logo.png
--------------------------------------------------------------------------------
/chapter3-7/front-vue/src/components/HelloWorld.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{ msg }}
4 |
Essential Links
5 |
13 |
Ecosystem
14 |
20 |
21 |
22 |
23 |
33 |
34 |
35 |
54 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue'
4 | import App from './App'
5 | import router from './router'
6 |
7 | Vue.config.productionTip = false
8 |
9 | /* eslint-disable no-new */
10 | new Vue({
11 | el: '#app',
12 | router,
13 | template: '',
14 | components: { App }
15 | })
16 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 | import HelloWorld from '@/components/HelloWorld'
4 |
5 | Vue.use(Router)
6 |
7 | export default new Router({
8 | routes: [
9 | {
10 | path: '/',
11 | name: 'Hello',
12 | component: HelloWorld
13 | }
14 | ]
15 | })
16 |
--------------------------------------------------------------------------------
/chapter3-7/front-vue/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter3-7/front-vue/static/.gitkeep
--------------------------------------------------------------------------------
/chapter3-7/src/main/java/com/frank/chapter37/Chapter37Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter37;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter37Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter37Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter3-7/src/main/java/com/frank/chapter37/config/WebMvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter37.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6 |
7 | /**
8 | * @author jianweilin
9 | * @date 2017/11/12
10 | */
11 | @Configuration
12 | public class WebMvcConfig extends WebMvcConfigurerAdapter {
13 | @Override
14 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
15 | registry.addResourceHandler("/static/**")
16 | .addResourceLocations("classpath:/static/");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/chapter3-7/src/main/java/com/frank/chapter37/controller/IndexController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter37.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestMethod;
6 |
7 | /**
8 | * @author jianweilin
9 | * @date 2017/11/12
10 | */
11 | @Controller
12 | public class IndexController {
13 | @RequestMapping(value = "/index",method = RequestMethod.GET)
14 | public String index(){
15 | return "index";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/chapter3-7/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8001
--------------------------------------------------------------------------------
/chapter3-7/src/main/resources/static/css/app.739f1ad65f043fab3efe7a450cd54da9.css:
--------------------------------------------------------------------------------
1 | #app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px}h1[data-v-40211da4],h2[data-v-40211da4]{font-weight:400}ul[data-v-40211da4]{list-style-type:none;padding:0}li[data-v-40211da4]{display:inline-block;margin:0 10px}a[data-v-40211da4]{color:#42b983}
--------------------------------------------------------------------------------
/chapter3-7/src/main/resources/static/js/manifest.ff985a587e3fe0e8abca.js:
--------------------------------------------------------------------------------
1 | !function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,a,c){for(var i,u,f,s=0,l=[];sfront-vue
--------------------------------------------------------------------------------
/chapter3-7/src/test/java/com/frank/chapter37/Chapter37ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter37;
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 Chapter37ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/chapter4-1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-1/src/main/java/com/frank/chapter41/Chapter41Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter41;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter41Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter41Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-1/src/main/java/com/frank/chapter41/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter41.service;
2 |
3 | /**
4 | * Created by jianweilin on 2017/10/11.
5 | */
6 | public interface UserService {
7 |
8 | void create(String name, Integer age);
9 |
10 | void deleteByName(String name);
11 |
12 | Integer getAllUsers();
13 |
14 | void deleteAllUsers();
15 | }
16 |
--------------------------------------------------------------------------------
/chapter4-1/src/main/java/com/frank/chapter41/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter41.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.jdbc.core.JdbcTemplate;
5 | import org.springframework.stereotype.Service;
6 |
7 | /**
8 | * Created by jianweilin on 2017/10/11.
9 | */
10 | @Service
11 | public class UserServiceImpl implements UserService {
12 |
13 | @Autowired
14 | private JdbcTemplate jdbcTemplate;
15 |
16 | @Override
17 | public void create(String name, Integer age) {
18 | jdbcTemplate.update("insert into bd_charge_info(name,age) values(?,?)",name,age);
19 | }
20 |
21 | @Override
22 | public void deleteByName(String name) {
23 | jdbcTemplate.update("DELETE FROM bd_charge_info where name = ?",name);
24 | }
25 |
26 | @Override
27 | public Integer getAllUsers() {
28 | return jdbcTemplate.queryForObject("select count(1) from bd_charge_info",Integer.class);
29 | }
30 |
31 | @Override
32 | public void deleteAllUsers() {
33 | jdbcTemplate.update("delete from bd_charge_info");
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/chapter4-1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/test
2 | spring.datasource.username=root
3 | spring.datasource.password=root
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
--------------------------------------------------------------------------------
/chapter4-1/src/test/java/com/frank/chapter41/Chapter41ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter41;
2 |
3 | import com.frank.chapter41.service.UserService;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest
15 | public class Chapter41ApplicationTests {
16 | private static final Logger logger = LoggerFactory.getLogger(Chapter41ApplicationTests.class);
17 | @Autowired
18 | private UserService userService;
19 |
20 | @Before
21 | public void setUp(){
22 | userService.deleteAllUsers();
23 | }
24 |
25 | @Test
26 | public void test_001(){
27 | userService.create("a",11);
28 | userService.create("b",21);
29 | userService.create("c",31);
30 |
31 | logger.info("user size => " + userService.getAllUsers());
32 | userService.deleteByName("a");
33 | logger.info("user size => " + userService.getAllUsers());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/chapter4-10/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-10/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-10/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-10/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-10/data/elasticsearch/nodes/0/_state/global-0.st:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-10/data/elasticsearch/nodes/0/_state/global-0.st
--------------------------------------------------------------------------------
/chapter4-10/data/elasticsearch/nodes/0/node.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-10/data/elasticsearch/nodes/0/node.lock
--------------------------------------------------------------------------------
/chapter4-10/src/main/java/com/frank/chapter410/Chapter410Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter410;
2 |
3 | import com.frank.chapter410.domain.User;
4 | import com.frank.chapter410.service.UserService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.CommandLineRunner;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 |
10 | @SpringBootApplication
11 | public class Chapter410Application implements CommandLineRunner {
12 |
13 |
14 | @Autowired
15 | private UserService userService;
16 |
17 | @Override
18 | public void run(String... args) throws Exception {
19 | // System.out.println("<<<<<< Elasticsearch 参数配置开始 >>>>>>>");
20 | // Map parameters = elasticsearchOperations.getClient().settings().getAsMap();
21 | // parameters.entrySet().forEach(entry -> {
22 | // System.out.println(entry.getKey() + " = " + entry.getValue());
23 | // });
24 | // System.out.println(">>>>>> Elasticsearch 参数配置结束 <<<<<<<<\n\n");
25 |
26 | System.out.println("<<<<<< Elasticsearch 初始化数据开始 >>>>>>>");
27 | userService.save(new User(1L,"张三","18817394122"));
28 | userService.save(new User(2L,"李四","18817394132"));
29 | userService.save(new User(3L,"王二麻子","18817394142"));
30 | userService.save(new User(4L,"赵六子","18817394152"));
31 | System.out.println("<<<<<< Elasticsearch 初始化数据结束 >>>>>>>\n\n");
32 | }
33 |
34 | public static void main(String[] args) {
35 | SpringApplication.run(Chapter410Application.class, args);
36 | }
37 |
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/chapter4-10/src/main/java/com/frank/chapter410/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter410.domain;
2 |
3 | import org.springframework.data.annotation.Id;
4 | import org.springframework.data.elasticsearch.annotations.Document;
5 |
6 | /**
7 | * @author jianweilin
8 | * @date 2017/10/24
9 | */
10 | @Document(indexName = "frank", type = "user")
11 | public class User {
12 | @Id
13 | private Long id;
14 |
15 | private String userName;
16 |
17 | private String userPhone;
18 |
19 | public User() {
20 | }
21 |
22 | public User(Long id, String userName, String userPhone) {
23 | this.id = id;
24 | this.userName = userName;
25 | this.userPhone = userPhone;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getUserName() {
37 | return userName;
38 | }
39 |
40 | public void setUserName(String userName) {
41 | this.userName = userName;
42 | }
43 |
44 | public String getUserPhone() {
45 | return userPhone;
46 | }
47 |
48 | public void setUserPhone(String userPhone) {
49 | this.userPhone = userPhone;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "User{" +
55 | "id=" + id +
56 | ", userName='" + userName + '\'' +
57 | ", userPhone='" + userPhone + '\'' +
58 | '}';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/chapter4-10/src/main/java/com/frank/chapter410/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter410.repository;
2 |
3 |
4 | import com.frank.chapter410.domain.User;
5 | import org.springframework.data.domain.Page;
6 | import org.springframework.data.domain.Pageable;
7 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * @author jianweilin
13 | * @date 2017/10/24
14 | */
15 | public interface UserRepository extends ElasticsearchRepository {
16 | /**
17 | * 根据用户名,获取用户分页列表
18 | * @param userName 用户名
19 | * @param pageable 分页模型
20 | * @return 分页用户列表
21 | */
22 | Page findByUserName(String userName, Pageable pageable);
23 |
24 | /**
25 | * 根据用户手机号,获取用户列表
26 | * @param userPhone 用户手机
27 | * @return 用户列表
28 | */
29 | List findByUserPhone(String userPhone);
30 | }
31 |
--------------------------------------------------------------------------------
/chapter4-10/src/main/java/com/frank/chapter410/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter410.service;
2 |
3 | import com.frank.chapter410.domain.User;
4 | import org.springframework.data.domain.Page;
5 | import org.springframework.data.domain.PageRequest;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @author jianweilin
11 | * @date 2017/10/24
12 | */
13 | public interface UserService {
14 | User save(User user);
15 |
16 | void deleteByUserId(Long userId);
17 |
18 | User findByUserId(Long userId);
19 |
20 | Iterable findAll();
21 |
22 | Page findByUserName(String userName, PageRequest pageRequest);
23 |
24 | List findByUserPhone(String userPhone);
25 | }
26 |
--------------------------------------------------------------------------------
/chapter4-10/src/main/java/com/frank/chapter410/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter410.service;
2 |
3 | import com.frank.chapter410.domain.User;
4 | import com.frank.chapter410.repository.UserRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.data.domain.Page;
7 | import org.springframework.data.domain.PageRequest;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * @author jianweilin
14 | * @date 2017/10/24
15 | */
16 | @Service
17 | public class UserServiceImpl implements UserService {
18 |
19 | @Autowired
20 | private UserRepository userRepository;
21 |
22 | @Override
23 | public User save(User user) {
24 | return userRepository.save(user);
25 | }
26 |
27 | @Override
28 | public void deleteByUserId(Long userId) {
29 | userRepository.delete(userId);
30 | }
31 |
32 | @Override
33 | public User findByUserId(Long userId) {
34 | return userRepository.findOne(userId);
35 | }
36 |
37 | @Override
38 | public Iterable findAll() {
39 | return userRepository.findAll();
40 | }
41 |
42 | @Override
43 | public Page findByUserName(String userName, PageRequest pageRequest) {
44 | return userRepository.findByUserName(userName,pageRequest);
45 | }
46 |
47 | @Override
48 | public List findByUserPhone(String userPhone) {
49 | return userRepository.findByUserPhone(userPhone);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/chapter4-10/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | elasticsearch.clustername=frank_cluster
2 | elasticsearch.host=localhost
3 | # 9100 - 9200 Http -> Http传输; 9300 - 9400 Node -> Node传输
4 | elasticsearch.port=9300
--------------------------------------------------------------------------------
/chapter4-11/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-11/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-11/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-11/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/java/com/frank/chapter411/Chapter411Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter411;
2 |
3 | import com.frank.chapter411.domain.User;
4 | import com.frank.chapter411.service.UserService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.CommandLineRunner;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 |
10 | @SpringBootApplication
11 | public class Chapter411Application implements CommandLineRunner {
12 | @Autowired
13 | private UserService userService;
14 |
15 | @Override
16 | public void run(String... args) throws Exception {
17 | System.out.println("<<<<<< Elasticsearch 初始化数据开始 >>>>>>>");
18 | userService.save(new User(1L,"张三","18817394122"));
19 | userService.save(new User(2L,"李四","18817394132"));
20 | userService.save(new User(3L,"王二麻子","18817394142"));
21 | userService.save(new User(4L,"赵六子","18817394152"));
22 | System.out.println("<<<<<< Elasticsearch 初始化数据结束 >>>>>>>\n\n");
23 | }
24 |
25 | public static void main(String[] args) {
26 | SpringApplication.run(Chapter411Application.class, args);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/java/com/frank/chapter411/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter411.domain;
2 |
3 | import org.springframework.data.annotation.Id;
4 | import org.springframework.data.elasticsearch.annotations.Document;
5 |
6 | /**
7 | * @author jianweilin
8 | * @date 2017/10/24
9 | */
10 | @Document(indexName = "frank", type = "user")
11 | public class User {
12 | @Id
13 | private Long id;
14 |
15 | private String userName;
16 |
17 | private String userPhone;
18 |
19 | public User() {
20 | }
21 |
22 | public User(Long id, String userName, String userPhone) {
23 | this.id = id;
24 | this.userName = userName;
25 | this.userPhone = userPhone;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getUserName() {
37 | return userName;
38 | }
39 |
40 | public void setUserName(String userName) {
41 | this.userName = userName;
42 | }
43 |
44 | public String getUserPhone() {
45 | return userPhone;
46 | }
47 |
48 | public void setUserPhone(String userPhone) {
49 | this.userPhone = userPhone;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "User{" +
55 | "id=" + id +
56 | ", userName='" + userName + '\'' +
57 | ", userPhone='" + userPhone + '\'' +
58 | '}';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/java/com/frank/chapter411/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter411.repository;
2 |
3 |
4 | import com.frank.chapter411.domain.User;
5 | import org.springframework.data.domain.Page;
6 | import org.springframework.data.domain.Pageable;
7 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * @author jianweilin
13 | * @date 2017/10/24
14 | */
15 | public interface UserRepository extends ElasticsearchRepository {
16 | /**
17 | * 根据用户名,获取用户分页列表
18 | * @param userName 用户名
19 | * @param pageable 分页模型
20 | * @return 分页用户列表
21 | */
22 | Page findByUserName(String userName, Pageable pageable);
23 |
24 | /**
25 | * 根据用户手机号,获取用户列表
26 | * @param userPhone 用户手机
27 | * @return 用户列表
28 | */
29 | List findByUserPhone(String userPhone);
30 | }
31 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/java/com/frank/chapter411/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter411.service;
2 |
3 | import com.frank.chapter411.domain.User;
4 | import org.springframework.data.domain.Page;
5 | import org.springframework.data.domain.PageRequest;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @author jianweilin
11 | * @date 2017/10/24
12 | */
13 | public interface UserService {
14 | User save(User user);
15 |
16 | void deleteByUserId(Long userId);
17 |
18 | User findByUserId(Long userId);
19 |
20 | Iterable findAll();
21 |
22 | Page findByUserName(String userName, PageRequest pageRequest);
23 |
24 | List findByUserPhone(String userPhone);
25 | }
26 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/java/com/frank/chapter411/service/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter411.service;
2 |
3 | import com.frank.chapter411.domain.User;
4 | import com.frank.chapter411.repository.UserRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.data.domain.Page;
7 | import org.springframework.data.domain.PageRequest;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * @author jianweilin
14 | * @date 2017/10/24
15 | */
16 | @Service
17 | public class UserServiceImpl implements UserService {
18 |
19 | @Autowired
20 | private UserRepository userRepository;
21 |
22 | @Override
23 | public User save(User user) {
24 | return userRepository.save(user);
25 | }
26 |
27 | @Override
28 | public void deleteByUserId(Long userId) {
29 | userRepository.delete(userId);
30 | }
31 |
32 | @Override
33 | public User findByUserId(Long userId) {
34 | return userRepository.findOne(userId);
35 | }
36 |
37 | @Override
38 | public Iterable findAll() {
39 | return userRepository.findAll();
40 | }
41 |
42 | @Override
43 | public Page findByUserName(String userName, PageRequest pageRequest) {
44 | return userRepository.findByUserName(userName,pageRequest);
45 | }
46 |
47 | @Override
48 | public List findByUserPhone(String userPhone) {
49 | return userRepository.findByUserPhone(userPhone);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/chapter4-11/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.data.elasticsearch.cluster-name=frank_cluster
2 | spring.data.elasticsearch.cluster-nodes=localhost:9300
--------------------------------------------------------------------------------
/chapter4-12/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-12/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-12/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-12/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/Chapter412Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter412Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter412Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/codegen/SimpleConfGenerator.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412.codegen;
2 |
3 | import org.jooq.util.jaxb.Generator;
4 |
5 | /**
6 | * Created by HYL on 2016/11/11.
7 | */
8 | public class SimpleConfGenerator extends Generator {
9 |
10 | @Override
11 | public String getName() {
12 | return "com.frank.chapter412.codegen.SimpleJavaGenerator";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/config/SpringTransaction.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412.config;
2 |
3 | import org.jooq.Transaction;
4 | import org.springframework.transaction.TransactionStatus;
5 |
6 | /**
7 | * Adapts a Spring transaction for JOOQ.
8 | *
9 | * @author Lukas Eder
10 | * @author Andreas Ahlenstorf
11 | * @author Phillip Webb
12 | */
13 | public class SpringTransaction implements Transaction {
14 |
15 | // Based on the jOOQ-spring-example from https://github.com/jOOQ/jOOQ
16 |
17 | private final TransactionStatus transactionStatus;
18 |
19 | SpringTransaction(TransactionStatus transactionStatus) {
20 | this.transactionStatus = transactionStatus;
21 | }
22 |
23 | public TransactionStatus getTxStatus() {
24 | return this.transactionStatus;
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/config/SpringTransactionProvider.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412.config;
2 |
3 | import org.jooq.TransactionContext;
4 | import org.jooq.TransactionProvider;
5 | import org.springframework.transaction.PlatformTransactionManager;
6 | import org.springframework.transaction.TransactionDefinition;
7 | import org.springframework.transaction.TransactionStatus;
8 | import org.springframework.transaction.support.DefaultTransactionDefinition;
9 |
10 | public class SpringTransactionProvider implements TransactionProvider {
11 |
12 | // Based on the jOOQ-spring-example from https://github.com/jOOQ/jOOQ
13 |
14 | private final PlatformTransactionManager transactionManager;
15 |
16 | public SpringTransactionProvider(PlatformTransactionManager transactionManager) {
17 | this.transactionManager = transactionManager;
18 | }
19 |
20 | @Override
21 | public void begin(TransactionContext context) {
22 | TransactionDefinition definition = new DefaultTransactionDefinition(
23 | TransactionDefinition.PROPAGATION_NESTED);
24 | TransactionStatus status = this.transactionManager.getTransaction(definition);
25 | context.transaction(new SpringTransaction(status));
26 | }
27 |
28 | @Override
29 | public void commit(TransactionContext ctx) {
30 | this.transactionManager.commit(getTransactionStatus(ctx));
31 | }
32 |
33 | @Override
34 | public void rollback(TransactionContext ctx) {
35 | this.transactionManager.rollback(getTransactionStatus(ctx));
36 | }
37 |
38 | private TransactionStatus getTransactionStatus(TransactionContext ctx) {
39 | SpringTransaction transaction = (SpringTransaction) ctx.transaction();
40 | return transaction.getTxStatus();
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/constant/Constants.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412.constant;
2 |
3 | /**
4 | * @author jianweilin
5 | * @date 2017/11/6
6 | */
7 | public class Constants {
8 | public static final String BD_USE_READ_DB = "dslContextBdUseReadDb";
9 | public static final String BD_USE_WRITE_DB = "dslContextBdUseWriteDb";
10 |
11 | public static final String DADA_READ_DB = "dslContextDadaReadDb";
12 | public static final String DADA_WRITE_DB = "dslContextDadaWriteDb";
13 | }
14 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/entity/test/DefaultCatalog.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by jOOQ
3 | */
4 | package com.frank.chapter412.entity.test;
5 |
6 |
7 | import java.util.ArrayList;
8 | import java.util.Arrays;
9 | import java.util.List;
10 |
11 | import javax.annotation.Generated;
12 |
13 | import org.jooq.Schema;
14 | import org.jooq.impl.CatalogImpl;
15 |
16 |
17 | /**
18 | * This class is generated by jOOQ.
19 | */
20 | @Generated(
21 | value = {
22 | "http://www.jooq.org",
23 | "jOOQ version:3.8.4"
24 | },
25 | comments = "This class is generated by jOOQ"
26 | )
27 | @SuppressWarnings({ "all", "unchecked", "rawtypes" })
28 | public class DefaultCatalog extends CatalogImpl {
29 |
30 | private static final long serialVersionUID = 307308603;
31 |
32 | /**
33 | * The reference instance of
34 | */
35 | public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog();
36 |
37 | /**
38 | * The schema test
.
39 | */
40 | public final Test TEST = com.frank.chapter412.entity.test.Test.TEST;
41 |
42 | /**
43 | * No further instances allowed
44 | */
45 | private DefaultCatalog() {
46 | super("");
47 | }
48 |
49 | @Override
50 | public final List getSchemas() {
51 | List result = new ArrayList();
52 | result.addAll(getSchemas0());
53 | return result;
54 | }
55 |
56 | private final List getSchemas0() {
57 | return Arrays.asList(
58 | Test.TEST);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/entity/test/Tables.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by jOOQ
3 | */
4 | package com.frank.chapter412.entity.test;
5 |
6 |
7 | import com.frank.chapter412.entity.test.tables.User;
8 |
9 | import javax.annotation.Generated;
10 |
11 |
12 | /**
13 | * Convenience access to all tables in test
14 | */
15 | @Generated(
16 | value = {
17 | "http://www.jooq.org",
18 | "jOOQ version:3.8.4"
19 | },
20 | comments = "This class is generated by jOOQ"
21 | )
22 | @SuppressWarnings({ "all", "unchecked", "rawtypes" })
23 | public class Tables {
24 |
25 | /**
26 | * The table test.user
.
27 | */
28 | public static final User USER = com.frank.chapter412.entity.test.tables.User.USER;
29 | }
30 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/entity/test/Test.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by jOOQ
3 | */
4 | package com.frank.chapter412.entity.test;
5 |
6 |
7 | import com.frank.chapter412.entity.test.tables.User;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 | import java.util.List;
12 |
13 | import javax.annotation.Generated;
14 |
15 | import org.jooq.Catalog;
16 | import org.jooq.Table;
17 | import org.jooq.impl.SchemaImpl;
18 |
19 |
20 | /**
21 | * This class is generated by jOOQ.
22 | */
23 | @Generated(
24 | value = {
25 | "http://www.jooq.org",
26 | "jOOQ version:3.8.4"
27 | },
28 | comments = "This class is generated by jOOQ"
29 | )
30 | @SuppressWarnings({ "all", "unchecked", "rawtypes" })
31 | public class Test extends SchemaImpl {
32 |
33 | private static final long serialVersionUID = -1583381313;
34 |
35 | /**
36 | * The reference instance of test
37 | */
38 | public static final Test TEST = new Test();
39 |
40 | /**
41 | * The table test.user
.
42 | */
43 | public final User USER = com.frank.chapter412.entity.test.tables.User.USER;
44 |
45 | /**
46 | * No further instances allowed
47 | */
48 | private Test() {
49 | super("test", null);
50 | }
51 |
52 |
53 | /**
54 | * {@inheritDoc}
55 | */
56 | @Override
57 | public Catalog getCatalog() {
58 | return DefaultCatalog.DEFAULT_CATALOG;
59 | }
60 |
61 | @Override
62 | public final List> getTables() {
63 | List result = new ArrayList();
64 | result.addAll(getTables0());
65 | return result;
66 | }
67 |
68 | private final List> getTables0() {
69 | return Arrays.>asList(
70 | User.USER);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/repository/TestBaseRepository.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by GenerationCodeUtil.
3 | */
4 | package com.frank.chapter412.repository;
5 |
6 | import org.apache.commons.lang3.tuple.Pair;
7 | import org.jooq.DSLContext;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.beans.factory.annotation.Qualifier;
10 |
11 | import java.io.Serializable;
12 |
13 | import static com.frank.chapter412.constant.Constants.*;
14 |
15 |
16 | public abstract class TestBaseRepository extends BaseRepository {
17 |
18 | @Autowired
19 | @Qualifier(BD_USE_READ_DB)
20 | protected DSLContext dslRead;
21 |
22 | @Autowired
23 | @Qualifier(BD_USE_WRITE_DB)
24 | protected DSLContext dslWrite;
25 |
26 | @Override
27 | protected Pair dslSelect() {
28 | return Pair.of(dslRead, dslWrite);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/repository/test/UserRepository.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by GenerationCodeUtil.
3 | */
4 | package com.frank.chapter412.repository.test;
5 |
6 | import org.apache.commons.lang3.tuple.Pair;
7 | import org.jooq.Table;
8 | import org.jooq.UpdatableRecord;
9 | import org.springframework.stereotype.Repository;
10 |
11 |
12 | import com.frank.chapter412.entity.test.tables.records.UserRecord;
13 | import com.frank.chapter412.repository.TestBaseRepository;
14 | import static com.frank.chapter412.entity.test.Tables.USER;
15 |
16 | @Repository
17 | public class UserRepository extends TestBaseRepository {
18 |
19 | @Override
20 | protected Pair, Table extends UpdatableRecord>> mapping() {
21 | return Pair.of(UserRecord.class, USER);
22 | }
23 |
24 | public void AddUser(UserRecord userRecord){
25 | dslWrite.executeInsert(userRecord);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/service/test/UserService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This class is generated by GenerationCodeUtil.
3 | */
4 |
5 | package com.frank.chapter412.service.test;
6 | import org.springframework.stereotype.Service;
7 |
8 |
9 | @Service
10 | public class UserService {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-12/src/main/java/com/frank/chapter412/utils/CamelUnderlineTransformUtils.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412.utils;
2 |
3 | import java.util.regex.Matcher;
4 |
5 | import static java.util.regex.Pattern.compile;
6 |
7 | public class CamelUnderlineTransformUtils {
8 |
9 | private static final char UNDERLINE = '_';
10 |
11 | /**
12 | * 驼峰转下划线
13 | * @param str
14 | * @return
15 | */
16 | public static String camelToUnderline(String str) {
17 | if (str == null || "".equals(str.trim())) {
18 | return "";
19 | }
20 | int len = str.length();
21 | StringBuilder sb = new StringBuilder(len);
22 | for (int i = 0; i < len; i++) {
23 | char c = str.charAt(i);
24 | if (Character.isUpperCase(c)) {
25 | sb.append(UNDERLINE);
26 | sb.append(Character.toLowerCase(c));
27 | } else {
28 | sb.append(c);
29 | }
30 | }
31 | return sb.toString();
32 | }
33 |
34 | /**
35 | * 下划线转驼峰
36 | * @param str
37 | * @return
38 | */
39 | public static String underlineToCamel(String str) {
40 | if (str == null || "".equals(str.trim())) return "";
41 | StringBuilder sb = new StringBuilder(str);
42 | Matcher mc = compile("_").matcher(str);
43 | int i = 0;
44 | while (mc.find()) {
45 | int position = mc.end() - (i++);
46 | sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
47 | }
48 | return sb.toString();
49 | }
50 | }
--------------------------------------------------------------------------------
/chapter4-12/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # bd_use 读库
2 | db.bduse.read.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true
3 | db.bduse.read.username=root
4 | db.bduse.read.password=root
5 | db.bduse.read.initialSize=1
6 | db.bduse.read.minIdle=1
7 | db.bduse.read.maxActive=100
8 | db.bduse.read.filters=stat
9 |
10 | # bd_use 写库
11 | db.bduse.write.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true
12 | db.bduse.write.username=root
13 | db.bduse.write.password=root
14 | db.bduse.write.initialSize=1
15 | db.bduse.write.minIdle=1
16 | db.bduse.write.maxActive=100
17 | db.bduse.write.filters=stat
18 |
19 | # dada 读库
20 | db.dada.read.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true
21 | db.dada.read.username=root
22 | db.dada.read.password=root
23 | db.dada.read.initialSize=1
24 | db.dada.read.minIdle=1
25 | db.dada.read.maxActive=100
26 | db.dada.read.filters=stat
27 |
28 | # dada 写库
29 | db.dada.write.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true
30 | db.dada.write.username=root
31 | db.dada.write.password=root
32 | db.dada.write.initialSize=1
33 | db.dada.write.minIdle=1
34 | db.dada.write.maxActive=100
35 | db.dada.write.filters=stat
--------------------------------------------------------------------------------
/chapter4-12/src/main/resources/test_2017-11-06.sql:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-12/src/main/resources/test_2017-11-06.sql
--------------------------------------------------------------------------------
/chapter4-12/src/test/java/com/frank/chapter412/Chapter412ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter412;
2 |
3 | import com.frank.chapter412.entity.test.tables.records.UserRecord;
4 | import com.frank.chapter412.repository.test.UserRepository;
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 Chapter412ApplicationTests {
14 |
15 | @Autowired
16 | private UserRepository userRepository;
17 |
18 | @Test
19 | public void test_001(){
20 | UserRecord userRecord = new UserRecord();
21 | userRecord.setName("张三");
22 | userRecord.setAge(23);
23 | userRepository.AddUser(userRecord);
24 | System.out.println("新增用户成功!");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/chapter4-13/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/chapter4-13/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-13/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-13/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-13/src/main/java/com/frank/chapter413/Chapter413Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter413;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.mybatis.spring.annotation.MapperScan;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 |
8 | @MapperScan("com.frank.chapter413")
9 | @SpringBootApplication
10 | @Slf4j
11 | public class Chapter413Application{
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(Chapter413Application.class, args);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/chapter4-13/src/main/java/com/frank/chapter413/controller/CityController.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter413.controller;
2 |
3 | import com.frank.chapter413.domain.City;
4 | import com.frank.chapter413.mapper.CityMapper;
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 | import java.util.List;
10 |
11 | /**
12 | * @author jianweilin
13 | * @date 2018/9/12
14 | */
15 | @RestController
16 | public class CityController {
17 |
18 | @Autowired
19 | private CityMapper cityMapper;
20 |
21 | @RequestMapping("/getCitys")
22 | public List getCitys(){
23 | return cityMapper.getAll();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/chapter4-13/src/main/java/com/frank/chapter413/domain/City.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter413.domain;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author jianweilin
7 | * @date 2018/9/12
8 | */
9 | @Data
10 | public class City {
11 | private Long id;
12 | private String cityName;
13 | private String state;
14 | private String country;
15 | }
16 |
--------------------------------------------------------------------------------
/chapter4-13/src/main/java/com/frank/chapter413/mapper/CityMapper.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter413.mapper;
2 |
3 | import com.frank.chapter413.domain.City;
4 | import org.apache.ibatis.annotations.*;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author jianweilin
10 | * @date 2018/9/12
11 | */
12 | public interface CityMapper {
13 | @Select("SELECT city_name, country, state FROM city")
14 | @Results({@Result(property = "cityName", column = "city_name")})
15 | List getAll();
16 |
17 | @Select("SELECT * FROM city where id = #{id}")
18 | @Results({@Result(property = "cityName", column = "city_name"),
19 | @Result(property = "country", column = "country")})
20 | City getOne(Long id);
21 |
22 | @Insert("INSERT INTO city(city_name,state,country) VALUES(#{cityName}, #{state}, #{country})")
23 | void insert(City city);
24 |
25 | @Update("UPDATE city set city_name=${cityName} where id #{id}")
26 | void update(City city);
27 |
28 | @Delete("DELETE FROM city where id = #{id}")
29 | void delete(Long id);
30 | }
31 |
--------------------------------------------------------------------------------
/chapter4-13/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | mybatis.type-aliases-package=com.frank.chapter413
2 |
3 | spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
4 | spring.datasource.username=root
5 | spring.datasource.password=root
--------------------------------------------------------------------------------
/chapter4-13/src/test/java/com/frank/chapter413/Chapter413ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter413;
2 |
3 | import org.junit.ClassRule;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.boot.test.rule.OutputCapture;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 |
10 | @RunWith(SpringRunner.class)
11 | @SpringBootTest
12 | public class Chapter413ApplicationTests {
13 | @ClassRule
14 | public static OutputCapture out = new OutputCapture();
15 |
16 | @Test
17 | public void test_001(){
18 | String output = out.toString();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/chapter4-2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-2/src/main/java/com/frank/chapter42/Chapter42Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter42;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter42Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter42Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-2/src/main/java/com/frank/chapter42/dao/BdChargeInfoRepository.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter42.dao;
2 |
3 | import com.frank.chapter42.domain.BdChargeInfo;
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 | /**
9 | * Created by jianweilin on 2017/10/11.
10 | */
11 | public interface BdChargeInfoRepository extends JpaRepository {
12 | BdChargeInfo findByName(String name);
13 |
14 | BdChargeInfo findByNameAndAge(String name,Integer age);
15 |
16 | @Query("select b from BdChargeInfo b where b.name=:name")
17 | BdChargeInfo findUser(@Param("name") String name);
18 | }
19 |
--------------------------------------------------------------------------------
/chapter4-2/src/main/java/com/frank/chapter42/domain/BdChargeInfo.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter42.domain;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | /**
9 | * Created by jianweilin on 2017/10/11.
10 | */
11 | @Entity
12 | public class BdChargeInfo{
13 |
14 | @Id
15 | @GeneratedValue
16 | private Integer id;
17 |
18 | @Column(nullable = false)
19 | private String name;
20 |
21 | @Column(nullable = false)
22 | private Integer age;
23 |
24 | public BdChargeInfo(String name, Integer age) {
25 | this.name = name;
26 | this.age = age;
27 | }
28 |
29 | public BdChargeInfo() {
30 | }
31 |
32 | public Integer getId() {
33 | return id;
34 | }
35 |
36 | public void setId(Integer id) {
37 | this.id = id;
38 | }
39 |
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | public Integer getAge() {
49 | return age;
50 | }
51 |
52 | public void setAge(Integer age) {
53 | this.age = age;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/chapter4-2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/test
2 | spring.datasource.username=root
3 | spring.datasource.password=root
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5 |
6 | # 自动创建 & 移除表
7 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
--------------------------------------------------------------------------------
/chapter4-2/src/test/java/com/frank/chapter42/Chapter42ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter42;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.frank.chapter42.dao.BdChargeInfoRepository;
5 | import com.frank.chapter42.domain.BdChargeInfo;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest
16 | public class Chapter42ApplicationTests {
17 | private static final Logger logger = LoggerFactory.getLogger(Chapter42ApplicationTests.class);
18 | @Autowired
19 | private BdChargeInfoRepository bdChargeInfoRepository;
20 |
21 | @Test
22 | public void test_001(){
23 | bdChargeInfoRepository.save(new BdChargeInfo("AA",10));
24 | bdChargeInfoRepository.save(new BdChargeInfo("BB",20));
25 |
26 | logger.info("all size => " + bdChargeInfoRepository.findAll().size());
27 | logger.info("findbyName => " + JSON.toJSONString(bdChargeInfoRepository.findByName("AA")));
28 | logger.info("findByNameAndAge => " + JSON.toJSONString(bdChargeInfoRepository.findByNameAndAge("BB",20)));
29 | logger.info("findUser => " + JSON.toJSONString(bdChargeInfoRepository.findUser("AA")));
30 |
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/chapter4-3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-3/src/main/java/com/frank/chapter43/Chapter43Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter43;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter43Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter43Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-3/src/main/java/com/frank/chapter43/config/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter43.config;
2 |
3 | import org.springframework.beans.factory.annotation.Qualifier;
4 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.context.annotation.Primary;
9 | import org.springframework.jdbc.core.JdbcTemplate;
10 |
11 | import javax.sql.DataSource;
12 |
13 | /**
14 | * Created by jianweilin on 2017/10/12.
15 | */
16 | @Configuration
17 | public class DataSourceConfig {
18 | @Bean(name = "primaryDataSource")
19 | @Qualifier("primaryDataSource")
20 | @ConfigurationProperties(prefix = "spring.datasource.primary")
21 | public DataSource primaryDataSource(){
22 | return DataSourceBuilder.create().build();
23 | }
24 |
25 | @Bean(name = "secondaryDataSource")
26 | @Qualifier("secondaryDataSource")
27 | @Primary
28 | @ConfigurationProperties(prefix = "spring.datasource.secondary")
29 | public DataSource secondaryDataSource(){
30 | return DataSourceBuilder.create().build();
31 | }
32 |
33 | @Bean(name = "primaryJdbcTemplate")
34 | public JdbcTemplate primaryJdbcTemplate(@Qualifier("primaryDataSource") DataSource dataSource){
35 | return new JdbcTemplate(dataSource);
36 | }
37 |
38 | @Bean(name = "secondaryJdbcTemplate")
39 | public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource dataSource){
40 | return new JdbcTemplate(dataSource);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/chapter4-3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1
2 | spring.datasource.primary.username=root
3 | spring.datasource.primary.password=root
4 | spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
5 |
6 | spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2
7 | spring.datasource.secondary.username=root
8 | spring.datasource.secondary.password=root
9 | spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver
--------------------------------------------------------------------------------
/chapter4-3/src/test/java/com/frank/chapter43/Chapter43ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter43;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.beans.factory.annotation.Qualifier;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.jdbc.core.JdbcTemplate;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | @RunWith(SpringRunner.class)
13 | @SpringBootTest
14 | public class Chapter43ApplicationTests {
15 |
16 | @Autowired
17 | @Qualifier("primaryJdbcTemplate")
18 | private JdbcTemplate jdbcTemplate1;
19 |
20 | @Autowired
21 | @Qualifier("secondaryJdbcTemplate")
22 | private JdbcTemplate jdbcTemplate2;
23 |
24 | @Before
25 | public void setUp(){
26 | jdbcTemplate1.update("DELETE FROM USER ");
27 | jdbcTemplate2.update("DELETE FROM USER ");
28 | }
29 |
30 | @Test
31 | public void test() throws Exception {
32 | jdbcTemplate1.update("INSERT INTO user(name,age) values(?,?)","AA",23);
33 | jdbcTemplate1.update("INSERT INTO user(name,age) values(?,?)","BB",24);
34 | jdbcTemplate2.update("INSERT INTO user(name,age) values(?,?)","CC",25);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/chapter4-4/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-4/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-4/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-4/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/Chapter44Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter44Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter44Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44;
2 |
3 | import org.springframework.beans.factory.annotation.Qualifier;
4 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.context.annotation.Primary;
9 |
10 | import javax.sql.DataSource;
11 |
12 | /**
13 | * Created by jianweilin on 2017/10/12.
14 | */
15 | @Configuration
16 | public class DataSourceConfig {
17 |
18 | @Bean(name = "primaryDataSource")
19 | @Qualifier("primaryDataSource")
20 | @ConfigurationProperties(prefix = "spring.datasource.primary")
21 | public DataSource primaryDataSource(){
22 | return DataSourceBuilder.create().build();
23 | }
24 |
25 | @Bean(name = "secondaryDataSource")
26 | @Qualifier("secondaryDataSource")
27 | @Primary
28 | @ConfigurationProperties(prefix = "spring.datasource.secondary")
29 | public DataSource secondaryDataSource(){
30 | return DataSourceBuilder.create().build();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/domain/p/User.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44.domain.p;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | /**
9 | * Created by jianweilin on 2017/10/12.
10 | */
11 | @Entity
12 | public class User {
13 | @Id
14 | @GeneratedValue
15 | private Long id;
16 |
17 | @Column(nullable = false)
18 | private String name;
19 |
20 | @Column(nullable = false)
21 | private Integer age;
22 |
23 | public User(String name, Integer age) {
24 | this.name = name;
25 | this.age = age;
26 | }
27 |
28 | public User() {
29 | }
30 |
31 | public Long getId() {
32 | return id;
33 | }
34 |
35 | public void setId(Long id) {
36 | this.id = id;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | public Integer getAge() {
48 | return age;
49 | }
50 |
51 | public void setAge(Integer age) {
52 | this.age = age;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/domain/p/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44.domain.p;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | /**
6 | * Created by jianweilin on 2017/10/12.
7 | */
8 | public interface UserRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/domain/s/Message.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44.domain.s;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.Id;
7 |
8 | /**
9 | * Created by jianweilin on 2017/10/12.
10 | */
11 | @Entity
12 | public class Message {
13 |
14 | @Id
15 | @GeneratedValue
16 | private Long id;
17 |
18 | @Column(nullable = false)
19 | private String name;
20 |
21 | @Column(nullable = false)
22 | private String content;
23 |
24 | public Message() {
25 | }
26 |
27 | public Message(String name, String content) {
28 | this.name = name;
29 | this.content = content;
30 | }
31 |
32 | public Long getId() {
33 | return id;
34 | }
35 |
36 | public void setId(Long id) {
37 | this.id = id;
38 | }
39 |
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | public String getContent() {
49 | return content;
50 | }
51 |
52 | public void setContent(String content) {
53 | this.content = content;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/java/com/frank/chapter44/domain/s/MessageRepository.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44.domain.s;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | /**
6 | * Created by jianweilin on 2017/10/12.
7 | */
8 | public interface MessageRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/chapter4-4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1
2 | spring.datasource.primary.username=root
3 | spring.datasource.primary.password=root
4 | spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
5 |
6 | spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2
7 | spring.datasource.secondary.username=root
8 | spring.datasource.secondary.password=root
9 | spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver
10 |
11 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
--------------------------------------------------------------------------------
/chapter4-4/src/test/java/com/frank/chapter44/Chapter44ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter44;
2 |
3 | import com.frank.chapter44.domain.p.User;
4 | import com.frank.chapter44.domain.p.UserRepository;
5 | import com.frank.chapter44.domain.s.Message;
6 | import com.frank.chapter44.domain.s.MessageRepository;
7 | import org.junit.Assert;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.boot.test.context.SpringBootTest;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest
17 | public class Chapter44ApplicationTests {
18 |
19 |
20 | @Autowired
21 | private UserRepository userRepository;
22 | @Autowired
23 | private MessageRepository messageRepository;
24 |
25 | @Before
26 | public void setUp() {
27 | }
28 |
29 | @Test
30 | public void test() throws Exception {
31 |
32 | userRepository.save(new User("aaa", 10));
33 | userRepository.save(new User("bbb", 20));
34 | userRepository.save(new User("ccc", 30));
35 | userRepository.save(new User("ddd", 40));
36 | userRepository.save(new User("eee", 50));
37 |
38 | Assert.assertEquals(5, userRepository.findAll().size());
39 |
40 | messageRepository.save(new Message("o1", "aaaaaaaaaa"));
41 | messageRepository.save(new Message("o2", "bbbbbbbbbb"));
42 | messageRepository.save(new Message("o3", "cccccccccc"));
43 |
44 | Assert.assertEquals(3, messageRepository.findAll().size());
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/chapter4-5/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/chapter4-5/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/teruiV/SpringBootDemo/f66a8891ae762be918416e67ba1c0511766fbe1e/chapter4-5/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/chapter4-5/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/chapter4-5/src/main/java/com/frank/chapter45/Chapter45Application.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter45;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Chapter45Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Chapter45Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/chapter4-5/src/main/java/com/frank/chapter45/RedisConfig.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter45;
2 |
3 | import com.frank.chapter45.domain.User;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.data.redis.connection.RedisConnectionFactory;
7 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
8 | import org.springframework.data.redis.core.RedisTemplate;
9 | import org.springframework.data.redis.serializer.StringRedisSerializer;
10 |
11 | /**
12 | * Created by jianweilin on 2017/10/14.
13 | */
14 | @Configuration
15 | public class RedisConfig {
16 | @Bean
17 | JedisConnectionFactory jedisConnectionFactory(){
18 | return new JedisConnectionFactory();
19 | }
20 |
21 | @Bean
22 | public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
23 | RedisTemplate template = new RedisTemplate();
24 | template.setConnectionFactory(jedisConnectionFactory());
25 | template.setKeySerializer(new StringRedisSerializer());
26 | template.setValueSerializer(new RedisObjectSerializer());
27 | return template;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/chapter4-5/src/main/java/com/frank/chapter45/RedisObjectSerializer.java:
--------------------------------------------------------------------------------
1 | package com.frank.chapter45;
2 |
3 | //import com.sun.tools.javac.util.Convert;
4 |
5 | import org.springframework.core.convert.converter.Converter;
6 | import org.springframework.core.serializer.support.DeserializingConverter;
7 | import org.springframework.core.serializer.support.SerializingConverter;
8 | import org.springframework.data.redis.serializer.RedisSerializer;
9 | import org.springframework.data.redis.serializer.SerializationException;
10 |
11 |
12 | /**
13 | * Created by jianweilin on 2017/10/14.
14 | */
15 | public class RedisObjectSerializer implements RedisSerializer