├── .gitignore ├── Java Persistence API 2.0-final-spec.pdf ├── README.md ├── Spring Boot.md ├── Spring Boot核心技术-笔记.pdf ├── SpringBoot课件.pdf ├── SpringBoot高级.pdf ├── SpringBoot高级.pptx ├── cyhNote.txt ├── images ├── 2018-02-04_123955.png ├── concrete-bindings.png ├── legacy.png ├── template-engine.png ├── 搜狗截图20180129151045.png ├── 搜狗截图20180129151112.png ├── 搜狗截图20180129224104.png ├── 搜狗截图20180130161620.png ├── 搜狗截图20180131220946.png ├── 搜狗截图20180131221411.png ├── 搜狗截图20180203164743.png ├── 搜狗截图20180203181108.png ├── 搜狗截图20180203181751.png ├── 搜狗截图20180211130621.png ├── 搜狗截图20180211130721.png ├── 搜狗截图20180211134506.png ├── 搜狗截图20180226173408.png ├── 搜狗截图20180226173527.png ├── 搜狗截图20180226180347.png ├── 搜狗截图20180226180504.png ├── 搜狗截图20180228135513.png ├── 搜狗截图20180301142915.png ├── 搜狗截图20180302114401.png ├── 搜狗截图20180302144835.png ├── 搜狗截图20180302144910.png ├── 搜狗截图20180302221835.png ├── 搜狗截图20180303145450.png ├── 搜狗截图20180303145531.png ├── 搜狗截图20180303165113.png ├── 搜狗截图20180305194443.png ├── 搜狗截图20180306105412.png ├── 搜狗截图20180306145727.png └── 搜狗截图20180306145855.png ├── servlet-3_1-final.pdf ├── spring-boot-01-helloworld ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ ├── HelloController.java │ │ └── atguigu │ │ ├── HelloWorldMainApplication.java │ │ └── controller │ │ └── HelloController.java │ └── resources │ ├── log4j2.xml │ └── logback.xml ├── spring-boot-02-config-autoconfig ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ └── SpringBoot02ConfigAutoconfigApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot02ConfigAutoconfigApplicationTests.java ├── spring-boot-02-config ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot02ConfigApplication.java │ │ │ ├── bean │ │ │ ├── Dog.java │ │ │ └── Person.java │ │ │ ├── config │ │ │ └── MyAppConfig.java │ │ │ ├── controller │ │ │ └── HelloController.java │ │ │ └── service │ │ │ └── HelloService.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-prod.properties │ │ ├── application.properties │ │ ├── application.yml │ │ ├── beans.xml │ │ └── person.properties │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot02ConfigApplicationTests.java ├── spring-boot-03-logging ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ └── SpringBoot03LoggingApplication.java │ └── resources │ │ ├── application.properties │ │ ├── log4j.properties │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot03LoggingApplicationTests.java ├── spring-boot-04-web-restfulcrud ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot04WebRestfulcrudApplication.java │ │ │ ├── component │ │ │ ├── LoginHandlerInterceptor.java │ │ │ ├── MyErrorAttributes.java │ │ │ └── MyLocaleResolver.java │ │ │ ├── config │ │ │ ├── MyMvcConfig.java │ │ │ └── MyServerConfig.java │ │ │ ├── controller │ │ │ ├── EmployeeController.java │ │ │ ├── HelloController.java │ │ │ ├── LoginController.java │ │ │ └── MyExceptionHandler.java │ │ │ ├── dao │ │ │ ├── DepartmentDao.java │ │ │ └── EmployeeDao.java │ │ │ ├── entities │ │ │ ├── Department.java │ │ │ └── Employee.java │ │ │ ├── exception │ │ │ └── UserNotExistException.java │ │ │ ├── filter │ │ │ └── MyFilter.java │ │ │ ├── listener │ │ │ └── MyListener.java │ │ │ └── servlet │ │ │ └── MyServlet.java │ └── resources │ │ ├── application.properties │ │ ├── i18n │ │ ├── login.properties │ │ ├── login_en_US.properties │ │ └── login_zh_CN.properties │ │ ├── public │ │ └── index.html │ │ ├── resources │ │ └── favicon.ico │ │ ├── springmvc.xml │ │ ├── static │ │ └── asserts │ │ │ ├── css │ │ │ ├── bootstrap.min.css │ │ │ ├── dashboard.css │ │ │ └── signin.css │ │ │ ├── img │ │ │ └── bootstrap-solid.svg │ │ │ └── js │ │ │ ├── Chart.min.js │ │ │ ├── bootstrap.min.js │ │ │ ├── feather.min.js │ │ │ ├── jquery-3.2.1.slim.min.js │ │ │ └── popper.min.js │ │ └── templates │ │ ├── commons │ │ └── bar.html │ │ ├── dashboard.html │ │ ├── emp │ │ ├── add.html │ │ └── list.html │ │ ├── error │ │ ├── 404.html │ │ ├── 4xx.html │ │ └── 5xx.html │ │ ├── login.html │ │ └── success.html │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot04WebRestfulcrudApplicationTests.java ├── spring-boot-06-data-jdbc ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot06DataJdbcApplication.java │ │ │ ├── config │ │ │ └── DruidConfig.java │ │ │ └── controller │ │ │ └── HelloController.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ └── department.sql │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot06DataJdbcApplicationTests.java ├── spring-boot-06-data-jpa ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot06DataJpaApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ └── repository │ │ │ └── UserRepository.java │ └── resources │ │ ├── application.properties │ │ └── application.yml │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot06DataJpaApplicationTests.java ├── spring-boot-06-data-mybatis ├── data.sql ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot06DataMybatisApplication.java │ │ │ ├── bean │ │ │ ├── Department.java │ │ │ └── Employee.java │ │ │ ├── config │ │ │ ├── DruidConfig.java │ │ │ └── MyBatisConfig.java │ │ │ ├── controller │ │ │ └── DeptController.java │ │ │ └── mapper │ │ │ ├── DepartmentMapper.java │ │ │ └── EmployeeMapper.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ ├── logback.xml │ │ ├── mybatis │ │ ├── mapper │ │ │ └── EmployeeMapper.xml │ │ └── mybatis-config.xml │ │ └── sql │ │ ├── department.sql │ │ └── employee.sql │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot06DataMybatisApplicationTests.java ├── spring-boot-07-source-debug ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── springboot │ │ │ ├── SpringBoot07Application.java │ │ │ └── listener │ │ │ ├── HelloApplicationContextInitializer.java │ │ │ ├── HelloApplicationRunner.java │ │ │ ├── HelloCommandLineRunner.java │ │ │ └── HelloSpringApplicationRunListener.java │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ └── application.properties │ └── test │ └── java │ └── com │ └── atguigu │ └── springboot │ └── SpringBoot07ApplicationTests.java ├── spring-boot-08-customerized-starter ├── atguigu-spring-boot-starter-autoconfigurer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ └── starter │ │ │ ├── HelloProperties.java │ │ │ ├── HelloService.java │ │ │ └── HelloServiceAutoConfiguration.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── atguigu-spring-boot-starter-test │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── atguigu │ │ │ │ └── springboot │ │ │ │ ├── SpringBoot08StarterTestApplication.java │ │ │ │ └── controller │ │ │ │ └── HelloController.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── logback.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── atguigu │ │ └── springboot │ │ └── SpringBoot08StarterTestApplicationTests.java └── atguigu-spring-boot-starter │ └── pom.xml ├── spring-boot-cyh-01-mybatis-paginator ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── cyh │ │ │ ├── EmployeeApplication.java │ │ │ ├── bean │ │ │ └── Employee.java │ │ │ ├── config │ │ │ └── Config.java │ │ │ └── mapper │ │ │ └── EmployeeMapper.java │ └── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── mybatis │ │ └── mapper │ │ └── EmployeeMapper.xml │ └── test │ └── java │ └── com │ └── cyh │ └── EmployeeTest.java ├── spring-boot-cyh-02-aop ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── cyh │ ├── SpringBootAopApplication.java │ ├── aop │ └── ServiceAop.java │ └── service │ └── MathCalculateService.java ├── spring-boot-cyh-03-data-redis ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── cyh │ │ └── SpringBootRedisApplication.java │ └── resources │ ├── application.properties │ └── logback-spring.xml ├── spring-boot-cyh-04-webmvc-messageConverter ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── cyh │ │ ├── WebMvcMessageConvertApplication.java │ │ └── web │ │ └── mvc │ │ └── message │ │ └── converter │ │ ├── config │ │ ├── DateFormatInterceptor.java │ │ └── MessageConvertConfiguration.java │ │ ├── controller │ │ └── UserController.java │ │ └── entity │ │ └── User.java │ └── resources │ ├── application.properties │ └── log4j2.xml ├── spring-boot-cyh-05-swagger-tomcat-bug ├── cyh.txt ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── cyh │ ├── SwaggerTomcatBugApplication.java │ ├── config │ └── SwaggerConfiguration.java │ └── controller │ └── UserController.java ├── spring-boot-sample-aop ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ └── aop │ │ │ ├── SampleAopApplication.java │ │ │ ├── monitor │ │ │ └── ServiceMonitor.java │ │ │ └── service │ │ │ └── HelloWorldService.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── sample │ └── aop │ └── SampleAopApplicationTests.java ├── spring-boot-sample-data-redis ├── pom.xml └── src │ ├── main │ ├── java │ │ └── sample │ │ │ └── data │ │ │ └── redis │ │ │ └── SampleRedisApplication.java │ └── resources │ │ ├── application.properties │ │ └── logback-spring.xml │ └── test │ └── java │ └── sample │ └── data │ └── redis │ └── SampleRedisApplicationTests.java ├── spring-boot-senior-02-amqp ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── atguigu │ │ │ ├── SpringBootAmqpApplication.java │ │ │ ├── bean │ │ │ └── Book.java │ │ │ ├── config │ │ │ └── MyRabbitMqConfig.java │ │ │ └── service │ │ │ └── BookService.java │ └── resources │ │ ├── application.properties │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── atguigu │ └── SpringBootAmqpApplicationTest.java ├── spring-boot-senior-03-elastic-search ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── cyh │ │ │ ├── ElasticSearchApplication.java │ │ │ └── elastic │ │ │ ├── entity │ │ │ └── Book.java │ │ │ └── repository │ │ │ └── BookRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── cyh │ └── ElasticSearchTest.java └── usingthymeleaf.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # Operating System Files 2 | 3 | *.DS_Store 4 | Thumbs.db 5 | *.sw? 6 | .#* 7 | *# 8 | *~ 9 | *.sublime-* 10 | 11 | # Build Artifacts 12 | 13 | .gradle/ 14 | build/ 15 | target/ 16 | bin/ 17 | dependency-reduced-pom.xml 18 | 19 | # Eclipse Project Files 20 | 21 | .classpath 22 | .project 23 | .settings/ 24 | 25 | # IntelliJ IDEA Files 26 | 27 | *.iml 28 | *.ipr 29 | *.iws 30 | *.idea 31 | 32 | README.html 33 | -------------------------------------------------------------------------------- /Java Persistence API 2.0-final-spec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/Java Persistence API 2.0-final-spec.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springBoot_atguigu 2 | 尚硅谷 SpringBoot 视频教学源码学习 3 | -------------------------------------------------------------------------------- /Spring Boot核心技术-笔记.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/Spring Boot核心技术-笔记.pdf -------------------------------------------------------------------------------- /SpringBoot课件.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/SpringBoot课件.pdf -------------------------------------------------------------------------------- /SpringBoot高级.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/SpringBoot高级.pdf -------------------------------------------------------------------------------- /SpringBoot高级.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/SpringBoot高级.pptx -------------------------------------------------------------------------------- /cyhNote.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/cyhNote.txt -------------------------------------------------------------------------------- /images/2018-02-04_123955.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/2018-02-04_123955.png -------------------------------------------------------------------------------- /images/concrete-bindings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/concrete-bindings.png -------------------------------------------------------------------------------- /images/legacy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/legacy.png -------------------------------------------------------------------------------- /images/template-engine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/template-engine.png -------------------------------------------------------------------------------- /images/搜狗截图20180129151045.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180129151045.png -------------------------------------------------------------------------------- /images/搜狗截图20180129151112.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180129151112.png -------------------------------------------------------------------------------- /images/搜狗截图20180129224104.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180129224104.png -------------------------------------------------------------------------------- /images/搜狗截图20180130161620.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180130161620.png -------------------------------------------------------------------------------- /images/搜狗截图20180131220946.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180131220946.png -------------------------------------------------------------------------------- /images/搜狗截图20180131221411.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180131221411.png -------------------------------------------------------------------------------- /images/搜狗截图20180203164743.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180203164743.png -------------------------------------------------------------------------------- /images/搜狗截图20180203181108.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180203181108.png -------------------------------------------------------------------------------- /images/搜狗截图20180203181751.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180203181751.png -------------------------------------------------------------------------------- /images/搜狗截图20180211130621.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180211130621.png -------------------------------------------------------------------------------- /images/搜狗截图20180211130721.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180211130721.png -------------------------------------------------------------------------------- /images/搜狗截图20180211134506.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180211134506.png -------------------------------------------------------------------------------- /images/搜狗截图20180226173408.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180226173408.png -------------------------------------------------------------------------------- /images/搜狗截图20180226173527.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180226173527.png -------------------------------------------------------------------------------- /images/搜狗截图20180226180347.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180226180347.png -------------------------------------------------------------------------------- /images/搜狗截图20180226180504.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180226180504.png -------------------------------------------------------------------------------- /images/搜狗截图20180228135513.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180228135513.png -------------------------------------------------------------------------------- /images/搜狗截图20180301142915.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180301142915.png -------------------------------------------------------------------------------- /images/搜狗截图20180302114401.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180302114401.png -------------------------------------------------------------------------------- /images/搜狗截图20180302144835.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180302144835.png -------------------------------------------------------------------------------- /images/搜狗截图20180302144910.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180302144910.png -------------------------------------------------------------------------------- /images/搜狗截图20180302221835.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180302221835.png -------------------------------------------------------------------------------- /images/搜狗截图20180303145450.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180303145450.png -------------------------------------------------------------------------------- /images/搜狗截图20180303145531.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180303145531.png -------------------------------------------------------------------------------- /images/搜狗截图20180303165113.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180303165113.png -------------------------------------------------------------------------------- /images/搜狗截图20180305194443.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180305194443.png -------------------------------------------------------------------------------- /images/搜狗截图20180306105412.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180306105412.png -------------------------------------------------------------------------------- /images/搜狗截图20180306145727.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180306145727.png -------------------------------------------------------------------------------- /images/搜狗截图20180306145855.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/images/搜狗截图20180306145855.png -------------------------------------------------------------------------------- /servlet-3_1-final.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/servlet-3_1-final.pdf -------------------------------------------------------------------------------- /spring-boot-01-helloworld/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.atguigu 8 | spring-boot-01-helloworld 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 1.8 19 | ${java.version} 20 | ${java.version} 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-logging 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-log4j2 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spring-boot-01-helloworld/src/main/java/com/HelloController.java: -------------------------------------------------------------------------------- 1 | package com; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | 7 | /** 8 | * 位于 @SpringBootApplication 所在类的外面,不能被自动配置!! 9 | */ 10 | @Controller 11 | public class HelloController { 12 | 13 | @ResponseBody 14 | @RequestMapping("/hello2") 15 | public String hello(){ 16 | return "Hello World!"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-01-helloworld/src/main/java/com/atguigu/HelloWorldMainApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | 8 | /** 9 | * @SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用 10 | */ 11 | @SpringBootApplication 12 | public class HelloWorldMainApplication { 13 | 14 | public static void main(String[] args) { 15 | 16 | // Spring应用启动起来 17 | SpringApplication.run(HelloWorldMainApplication.class,args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-01-helloworld/src/main/java/com/atguigu/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.controller; 2 | 3 | 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | 8 | @Controller 9 | public class HelloController { 10 | 11 | @ResponseBody 12 | @RequestMapping("/hello") 13 | public String hello(){ 14 | return "Hello World!"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-01-helloworld/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring-boot-01-helloworld/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-02-config-autoconfig/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-02-config-autoconfig 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-02-config-autoconfig 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /spring-boot-02-config-autoconfig/src/main/java/com/atguigu/springboot/SpringBoot02ConfigAutoconfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBoot02ConfigAutoconfigApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBoot02ConfigAutoconfigApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-02-config-autoconfig/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-02-config-autoconfig/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-02-config-autoconfig/src/test/java/com/atguigu/springboot/SpringBoot02ConfigAutoconfigApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot02ConfigAutoconfigApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-02-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-02-config 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-02-config 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-web 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-configuration-processor 37 | true 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | test 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-maven-plugin 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/SpringBoot02ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | 8 | //@ImportResource(locations = {"classpath:beans.xml"}) 9 | @SpringBootApplication 10 | public class SpringBoot02ConfigApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBoot02ConfigApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/bean/Dog.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.bean; 2 | 3 | public class Dog { 4 | 5 | private String name; 6 | private Integer age; 7 | 8 | @Override 9 | public String toString() { 10 | return "Dog{" + 11 | "name='" + name + '\'' + 12 | ", age=" + age + 13 | '}'; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public Integer getAge() { 25 | return age; 26 | } 27 | 28 | public void setAge(Integer age) { 29 | this.age = age; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/bean/Person.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.bean; 2 | 3 | 4 | import org.hibernate.validator.constraints.Email; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.PropertySource; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.validation.annotation.Validated; 10 | 11 | import javax.validation.constraints.Null; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | 17 | /** 18 | * 将配置文件中配置的每一个属性的值,映射到这个组件中 19 | * @ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定; 20 | * prefix = "person":配置文件中哪个下面的所有属性进行一一映射 21 | * 22 | * 只有这个组件是容器中的组件,才能容器提供的@ConfigurationProperties功能; 23 | * @ConfigurationProperties(prefix = "person")默认从全局配置文件中获取值; 24 | * 25 | */ 26 | //@PropertySource(value = {"classpath:person.properties"}) 27 | @Component 28 | @ConfigurationProperties(prefix = "person") 29 | //@Validated 30 | public class Person { 31 | 32 | /** 33 | * 34 | * 35 | * 36 | */ 37 | 38 | //lastName必须是邮箱格式 39 | // @Email 40 | //@Value("${person.last-name}") 41 | private String lastName; 42 | //@Value("#{11*2}") 43 | private Integer age; 44 | //@Value("true") 45 | private Boolean boss; 46 | 47 | private Date birth; 48 | //@Value("${person.maps}") 49 | private Map maps; 50 | private List lists; 51 | private Dog dog; 52 | 53 | @Override 54 | public String toString() { 55 | return "Person{" + 56 | "lastName='" + lastName + '\'' + 57 | ", age=" + age + 58 | ", boss=" + boss + 59 | ", birth=" + birth + 60 | ", maps=" + maps + 61 | ", lists=" + lists + 62 | ", dog=" + dog + 63 | '}'; 64 | } 65 | 66 | public String getLastName() { 67 | return lastName; 68 | } 69 | 70 | public void setLastName(String lastName) { 71 | this.lastName = lastName; 72 | } 73 | 74 | public Integer getAge() { 75 | return age; 76 | } 77 | 78 | public void setAge(Integer age) { 79 | this.age = age; 80 | } 81 | 82 | public Boolean getBoss() { 83 | return boss; 84 | } 85 | 86 | public void setBoss(Boolean boss) { 87 | this.boss = boss; 88 | } 89 | 90 | public Date getBirth() { 91 | return birth; 92 | } 93 | 94 | public void setBirth(Date birth) { 95 | this.birth = birth; 96 | } 97 | 98 | public Map getMaps() { 99 | return maps; 100 | } 101 | 102 | public void setMaps(Map maps) { 103 | this.maps = maps; 104 | } 105 | 106 | public List getLists() { 107 | return lists; 108 | } 109 | 110 | public void setLists(List lists) { 111 | this.lists = lists; 112 | } 113 | 114 | public Dog getDog() { 115 | return dog; 116 | } 117 | 118 | public void setDog(Dog dog) { 119 | this.dog = dog; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/config/MyAppConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | 4 | import com.atguigu.springboot.service.HelloService; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @Configuration:指明当前类是一个配置类;就是来替代之前的Spring配置文件 10 | * 11 | * 在配置文件中用标签添加组件 12 | * 13 | */ 14 | @Configuration 15 | public class MyAppConfig { 16 | 17 | //将方法的返回值添加到容器中;容器中这个组件默认的id就是方法名 18 | @Bean 19 | public HelloService helloService02(){ 20 | System.out.println("配置类@Bean给容器中添加组件了..."); 21 | return new HelloService(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class HelloController { 10 | 11 | @Value("${person.last-name}") 12 | private String name; 13 | 14 | @RequestMapping("/sayHello") 15 | public String sayHello(){ 16 | return "Hello "+name; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/java/com/atguigu/springboot/service/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.service; 2 | 3 | public class HelloService { 4 | } 5 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | #server.port=8082 -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | #server.port=80 -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | #spring.profiles.active=dev 3 | 4 | # idea\uFF0Cproperties\u914D\u7F6E\u6587\u4EF6utf-8 5 | # \uFFFD\uFFFD\uFFFD\uFFFDperson\uFFFD\uFFFD\u05B5 6 | person.last-name=\u5F20\u4E09${random.uuid} 7 | person.age=${random.int} 8 | person.birth=2017/12/15 9 | person.boss=false 10 | person.maps.k1=v1 11 | person.maps.k2=14 12 | person.lists=a,b,c 13 | person.dog.name=${person.hello:hello}_dog 14 | person.dog.age=15 15 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 8081 4 | spring: 5 | profiles: 6 | active: prod 7 | 8 | --- 9 | server: 10 | port: 8083 11 | spring: 12 | profiles: dev 13 | 14 | 15 | --- 16 | 17 | server: 18 | port: 8084 19 | spring: 20 | profiles: prod -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /spring-boot-02-config/src/main/resources/person.properties: -------------------------------------------------------------------------------- 1 | person.last-name=\u674E\u56DB 2 | person.age=12 3 | person.birth=2017/12/15 4 | person.boss=false 5 | person.maps.k1=v1 6 | person.maps.k2=14 7 | person.lists=a,b,c 8 | person.dog.name=dog 9 | person.dog.age=15 -------------------------------------------------------------------------------- /spring-boot-02-config/src/test/java/com/atguigu/springboot/SpringBoot02ConfigApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import com.atguigu.springboot.bean.Person; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | 12 | /** 13 | * SpringBoot单元测试; 14 | * 15 | * 可以在测试期间很方便的类似编码一样进行自动注入等容器的功能 16 | * 17 | */ 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | public class SpringBoot02ConfigApplicationTests { 21 | 22 | @Autowired 23 | Person person; 24 | 25 | @Autowired 26 | ApplicationContext ioc; 27 | 28 | @Test 29 | public void testHelloService(){ 30 | boolean b = ioc.containsBean("helloService02"); 31 | System.out.println(b); 32 | } 33 | 34 | 35 | @Test 36 | public void contextLoads() { 37 | System.out.println(person); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-03-logging/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-03-logging 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-03-logging 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-logging 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-log4j2 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /spring-boot-03-logging/src/main/java/com/atguigu/springboot/SpringBoot03LoggingApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.slf4j.LoggerFactory; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class SpringBoot03LoggingApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(SpringBoot03LoggingApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-03-logging/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-03-logging/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-03-logging/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-03-logging/src/main/resources/log4j.properties -------------------------------------------------------------------------------- /spring-boot-03-logging/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | %d{yyyy-MM-dd HH:mm:ss.SSS} ----> [%thread] ---> %-5level %logger{50} - %msg%n 26 | 27 | 28 | %d{yyyy-MM-dd HH:mm:ss.SSS} ==== [%thread] ==== %-5level %logger{50} - %msg%n 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | ${LOG_HOME}/${appName}.log 37 | 41 | 42 | 46 | ${LOG_HOME}/${appName}-%d{yyyy-MM-dd}-%i.log 47 | 52 | 365 53 | 56 | 57 | 100MB 58 | 59 | 60 | 61 | 62 | %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n 63 | 64 | 65 | 66 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /spring-boot-03-logging/src/test/java/com/atguigu/springboot/SpringBoot03LoggingApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class SpringBoot03LoggingApplicationTests { 13 | 14 | //记录器 15 | Logger logger = LoggerFactory.getLogger(getClass()); 16 | @Test 17 | public void contextLoads() { 18 | //System.out.println(); 19 | 20 | //日志的级别; 21 | //由低到高 trace 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-04-web-restfulcrud 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-04-web-restfulcrud 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 3.0.9.RELEASE 26 | 27 | 28 | 2.2.2 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | 40 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-thymeleaf 48 | 49 | 50 | 51 | 52 | 53 | org.webjars 54 | jquery 55 | 3.3.1 56 | 57 | 58 | 59 | 60 | org.webjars 61 | bootstrap 62 | 4.0.0 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-maven-plugin 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/SpringBoot04WebRestfulcrudApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.servlet.View; 7 | import org.springframework.web.servlet.ViewResolver; 8 | 9 | import java.util.Locale; 10 | 11 | 12 | @SpringBootApplication 13 | public class SpringBoot04WebRestfulcrudApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(SpringBoot04WebRestfulcrudApplication.class, args); 17 | } 18 | 19 | @Bean 20 | public ViewResolver myViewReolver(){ 21 | return new MyViewResolver(); 22 | } 23 | 24 | public static class MyViewResolver implements ViewResolver{ 25 | 26 | @Override 27 | public View resolveViewName(String viewName, Locale locale) throws Exception { 28 | return null; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/component/LoginHandlerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.component; 2 | 3 | import org.springframework.web.servlet.HandlerInterceptor; 4 | import org.springframework.web.servlet.ModelAndView; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | /** 10 | * 登陆检查, 11 | */ 12 | public class LoginHandlerInterceptor implements HandlerInterceptor { 13 | //目标方法执行之前 14 | @Override 15 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 16 | Object user = request.getSession().getAttribute("loginUser"); 17 | if(user == null){ 18 | //未登陆,返回登陆页面 19 | request.setAttribute("msg","没有权限请先登陆"); 20 | request.getRequestDispatcher("/index.html").forward(request,response); 21 | return false; 22 | }else{ 23 | //已登陆,放行请求 24 | return true; 25 | } 26 | 27 | } 28 | 29 | @Override 30 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 31 | 32 | } 33 | 34 | @Override 35 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/component/MyErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.component; 2 | 3 | import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.context.request.RequestAttributes; 6 | 7 | import java.util.Map; 8 | 9 | //给容器中加入我们自己定义的ErrorAttributes 10 | @Component 11 | public class MyErrorAttributes extends DefaultErrorAttributes { 12 | 13 | //返回值的map就是页面和json能获取的所有字段 14 | @Override 15 | public Map getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) { 16 | Map map = super.getErrorAttributes(requestAttributes, includeStackTrace); 17 | map.put("company","atguigu"); 18 | 19 | //我们的异常处理器携带的数据 20 | Map ext = (Map) requestAttributes.getAttribute("ext", 0); 21 | map.put("ext",ext); 22 | return map; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/component/MyLocaleResolver.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.component; 2 | 3 | import org.springframework.util.StringUtils; 4 | import org.springframework.web.servlet.LocaleResolver; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.util.Locale; 9 | 10 | /** 11 | * 可以在连接上携带区域信息 12 | */ 13 | public class MyLocaleResolver implements LocaleResolver { 14 | 15 | @Override 16 | public Locale resolveLocale(HttpServletRequest request) { 17 | String l = request.getParameter("l"); 18 | Locale locale = Locale.getDefault(); 19 | if(!StringUtils.isEmpty(l)){ 20 | String[] split = l.split("_"); 21 | locale = new Locale(split[0],split[1]); 22 | } 23 | return locale; 24 | } 25 | 26 | @Override 27 | public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/config/MyMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | import com.atguigu.springboot.component.LoginHandlerInterceptor; 4 | import com.atguigu.springboot.component.MyLocaleResolver; 5 | import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; 6 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.servlet.LocaleResolver; 10 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 11 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 12 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 14 | 15 | //使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能 16 | //@EnableWebMvc 不要接管SpringMVC 17 | @Configuration 18 | public class MyMvcConfig extends WebMvcConfigurerAdapter { 19 | 20 | 21 | 22 | @Override 23 | public void addViewControllers(ViewControllerRegistry registry) { 24 | // super.addViewControllers(registry); 25 | //浏览器发送 /atguigu 请求来到 success 26 | registry.addViewController("/atguigu").setViewName("success"); 27 | } 28 | 29 | //所有的WebMvcConfigurerAdapter组件都会一起起作用 30 | @Bean //将组件注册在容器 31 | public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){ 32 | WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() { 33 | @Override 34 | public void addViewControllers(ViewControllerRegistry registry) { 35 | registry.addViewController("/").setViewName("login"); 36 | registry.addViewController("/index.html").setViewName("login"); 37 | registry.addViewController("/main.html").setViewName("dashboard"); 38 | } 39 | 40 | //注册拦截器 41 | @Override 42 | public void addInterceptors(InterceptorRegistry registry) { 43 | //super.addInterceptors(registry); 44 | //静态资源; *.css , *.js 45 | //SpringBoot已经做好了静态资源映射 46 | // registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**") 47 | // .excludePathPatterns("/index.html","/","/user/login"); 48 | } 49 | }; 50 | return adapter; 51 | } 52 | 53 | @Bean 54 | public LocaleResolver localeResolver(){ 55 | 56 | return new MyLocaleResolver(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/config/MyServerConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | import com.atguigu.springboot.filter.MyFilter; 4 | import com.atguigu.springboot.listener.MyListener; 5 | import com.atguigu.springboot.servlet.MyServlet; 6 | import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; 7 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 8 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 9 | import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; 10 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | import java.util.Arrays; 15 | 16 | @Configuration 17 | public class MyServerConfig { 18 | 19 | //注册三大组件 20 | @Bean 21 | public ServletRegistrationBean myServlet(){ 22 | ServletRegistrationBean registrationBean = new ServletRegistrationBean(new MyServlet(),"/myServlet"); 23 | registrationBean.setLoadOnStartup(1); 24 | return registrationBean; 25 | } 26 | 27 | @Bean 28 | public FilterRegistrationBean myFilter(){ 29 | FilterRegistrationBean registrationBean = new FilterRegistrationBean(); 30 | registrationBean.setFilter(new MyFilter()); 31 | registrationBean.setUrlPatterns(Arrays.asList("/hello","/myServlet")); 32 | return registrationBean; 33 | } 34 | 35 | @Bean 36 | public ServletListenerRegistrationBean myListener(){ 37 | ServletListenerRegistrationBean registrationBean = new ServletListenerRegistrationBean<>(new MyListener()); 38 | return registrationBean; 39 | } 40 | 41 | 42 | //配置嵌入式的Servlet容器 43 | @Bean 44 | public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(){ 45 | return new EmbeddedServletContainerCustomizer() { 46 | 47 | //定制嵌入式的Servlet容器相关的规则 48 | @Override 49 | public void customize(ConfigurableEmbeddedServletContainer container) { 50 | container.setPort(8083); 51 | } 52 | }; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/controller/EmployeeController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import com.atguigu.springboot.dao.DepartmentDao; 4 | import com.atguigu.springboot.dao.EmployeeDao; 5 | import com.atguigu.springboot.entities.Department; 6 | import com.atguigu.springboot.entities.Employee; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.Model; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.Collection; 13 | 14 | @Controller 15 | public class EmployeeController { 16 | @Autowired 17 | EmployeeDao employeeDao; 18 | 19 | @Autowired 20 | DepartmentDao departmentDao; 21 | 22 | //查询所有员工返回列表页面 23 | @GetMapping("/emps") 24 | public String list(Model model){ 25 | Collection employees = employeeDao.getAll(); 26 | 27 | //放在请求域中 28 | model.addAttribute("emps",employees); 29 | // thymeleaf默认就会拼串 30 | // classpath:/templates/xxxx.html 31 | return "emp/list"; 32 | } 33 | 34 | //来到员工添加页面 35 | @GetMapping("/emp") 36 | public String toAddPage(Model model){ 37 | //来到添加页面,查出所有的部门,在页面显示 38 | Collection departments = departmentDao.getDepartments(); 39 | model.addAttribute("depts",departments); 40 | return "emp/add"; 41 | } 42 | 43 | //员工添加 44 | //SpringMVC自动将请求参数和入参对象的属性进行一一绑定;要求请求参数的名字和javaBean入参的对象里面的属性名是一样的 45 | @PostMapping("/emp") 46 | public String addEmp(Employee employee){ 47 | //来到员工列表页面 48 | 49 | System.out.println("保存的员工信息:"+employee); 50 | //保存员工 51 | employeeDao.save(employee); 52 | // redirect: 表示重定向到一个地址 /代表当前项目路径 53 | // forward: 表示转发到一个地址 54 | return "redirect:/emps"; 55 | } 56 | 57 | //来到修改页面,查出当前员工,在页面回显 58 | @GetMapping("/emp/{id}") 59 | public String toEditPage(@PathVariable("id") Integer id,Model model){ 60 | Employee employee = employeeDao.get(id); 61 | model.addAttribute("emp",employee); 62 | 63 | //页面要显示所有的部门列表 64 | Collection departments = departmentDao.getDepartments(); 65 | model.addAttribute("depts",departments); 66 | //回到修改页面(add是一个修改添加二合一的页面); 67 | return "emp/add"; 68 | } 69 | 70 | //员工修改;需要提交员工id; 71 | @PutMapping("/emp") 72 | public String updateEmployee(Employee employee){ 73 | System.out.println("修改的员工数据:"+employee); 74 | employeeDao.save(employee); 75 | return "redirect:/emps"; 76 | } 77 | 78 | //员工删除 79 | @DeleteMapping("/emp/{id}") 80 | public String deleteEmployee(@PathVariable("id") Integer id){ 81 | employeeDao.delete(id); 82 | return "redirect:/emps"; 83 | } 84 | 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | 4 | import com.atguigu.springboot.exception.UserNotExistException; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | 10 | import java.util.Arrays; 11 | import java.util.Map; 12 | 13 | @Controller 14 | public class HelloController { 15 | 16 | // @RequestMapping({"/","/index.html"}) 17 | // public String index(){ 18 | // return "index"; 19 | // } 20 | 21 | @ResponseBody 22 | @RequestMapping("/hello") 23 | public String hello(@RequestParam("user") String user){ 24 | if(user.equals("aaa")){ 25 | throw new UserNotExistException(); 26 | } 27 | return "Hello World"; 28 | } 29 | 30 | //查出用户数据,在页面展示 31 | @RequestMapping("/success") 32 | public String success(Map map){ 33 | map.put("hello","你好"); 34 | map.put("users",Arrays.asList("zhangsan","lisi","wangwu")); 35 | return "success"; 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.util.StringUtils; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import javax.servlet.http.HttpSession; 8 | import java.util.Map; 9 | 10 | @Controller 11 | public class LoginController { 12 | 13 | // @DeleteMapping 14 | // @PutMapping 15 | // @GetMapping 16 | 17 | //@RequestMapping(value = "/user/login",method = RequestMethod.POST) 18 | @PostMapping(value = "/user/login") 19 | public String login(@RequestParam("username") String username, 20 | @RequestParam("password") String password, 21 | Map map, HttpSession session){ 22 | if(!StringUtils.isEmpty(username) && "123456".equals(password)){ 23 | //登陆成功,防止表单重复提交,可以重定向到主页 24 | session.setAttribute("loginUser",username); 25 | return "redirect:/main.html"; 26 | }else{ 27 | //登陆失败 28 | 29 | map.put("msg","用户名密码错误"); 30 | return "login"; 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/controller/MyExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import com.atguigu.springboot.exception.UserNotExistException; 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 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | @ControllerAdvice 13 | public class MyExceptionHandler { 14 | 15 | //1、浏览器客户端返回的都是json 16 | // @ResponseBody 17 | // @ExceptionHandler(UserNotExistException.class) 18 | // public Map handleException(Exception e){ 19 | // Map map = new HashMap<>(); 20 | // map.put("code","user.notexist"); 21 | // map.put("message",e.getMessage()); 22 | // return map; 23 | // } 24 | @ExceptionHandler(UserNotExistException.class) 25 | public String handleException(Exception e, HttpServletRequest request){ 26 | Map map = new HashMap<>(); 27 | //传入我们自己的错误状态码 4xx 5xx 28 | /** 29 | * Integer statusCode = (Integer) request 30 | .getAttribute("javax.servlet.error.status_code"); 31 | */ 32 | request.setAttribute("javax.servlet.error.status_code",500); 33 | map.put("code","user.notexist"); 34 | map.put("message","用户出错啦"); 35 | 36 | request.setAttribute("ext",map); 37 | //转发到/error 38 | return "forward:/error"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/dao/DepartmentDao.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.dao; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.atguigu.springboot.entities.Department; 8 | import org.springframework.stereotype.Repository; 9 | 10 | 11 | @Repository 12 | public class DepartmentDao { 13 | 14 | private static Map departments = null; 15 | 16 | static{ 17 | departments = new HashMap(); 18 | 19 | departments.put(101, new Department(101, "D-AA")); 20 | departments.put(102, new Department(102, "D-BB")); 21 | departments.put(103, new Department(103, "D-CC")); 22 | departments.put(104, new Department(104, "D-DD")); 23 | departments.put(105, new Department(105, "D-EE")); 24 | } 25 | 26 | public Collection getDepartments(){ 27 | return departments.values(); 28 | } 29 | 30 | public Department getDepartment(Integer id){ 31 | return departments.get(id); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/dao/EmployeeDao.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.dao; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.atguigu.springboot.entities.Department; 8 | import com.atguigu.springboot.entities.Employee; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Repository; 11 | 12 | @Repository 13 | public class EmployeeDao { 14 | 15 | private static Map employees = null; 16 | 17 | @Autowired 18 | private DepartmentDao departmentDao; 19 | 20 | static{ 21 | employees = new HashMap(); 22 | 23 | employees.put(1001, new Employee(1001, "E-AA", "aa@163.com", 1, new Department(101, "D-AA"))); 24 | employees.put(1002, new Employee(1002, "E-BB", "bb@163.com", 1, new Department(102, "D-BB"))); 25 | employees.put(1003, new Employee(1003, "E-CC", "cc@163.com", 0, new Department(103, "D-CC"))); 26 | employees.put(1004, new Employee(1004, "E-DD", "dd@163.com", 0, new Department(104, "D-DD"))); 27 | employees.put(1005, new Employee(1005, "E-EE", "ee@163.com", 1, new Department(105, "D-EE"))); 28 | } 29 | 30 | private static Integer initId = 1006; 31 | 32 | public void save(Employee employee){ 33 | if(employee.getId() == null){ 34 | employee.setId(initId++); 35 | } 36 | 37 | employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId())); 38 | employees.put(employee.getId(), employee); 39 | } 40 | 41 | //查询所有员工 42 | public Collection getAll(){ 43 | return employees.values(); 44 | } 45 | 46 | public Employee get(Integer id){ 47 | return employees.get(id); 48 | } 49 | 50 | public void delete(Integer id){ 51 | employees.remove(id); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/entities/Department.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.entities; 2 | 3 | public class Department { 4 | 5 | private Integer id; 6 | private String departmentName; 7 | 8 | public Department() { 9 | } 10 | 11 | public Department(int i, String string) { 12 | this.id = i; 13 | this.departmentName = string; 14 | } 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getDepartmentName() { 25 | return departmentName; 26 | } 27 | 28 | public void setDepartmentName(String departmentName) { 29 | this.departmentName = departmentName; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Department [id=" + id + ", departmentName=" + departmentName + "]"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/entities/Employee.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.entities; 2 | 3 | import java.util.Date; 4 | 5 | public class Employee { 6 | 7 | private Integer id; 8 | private String lastName; 9 | 10 | private String email; 11 | //1 male, 0 female 12 | private Integer gender; 13 | private Department department; 14 | private Date birth; 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Integer id) { 21 | this.id = id; 22 | } 23 | 24 | public String getLastName() { 25 | return lastName; 26 | } 27 | 28 | public void setLastName(String lastName) { 29 | this.lastName = lastName; 30 | } 31 | 32 | public String getEmail() { 33 | return email; 34 | } 35 | 36 | public void setEmail(String email) { 37 | this.email = email; 38 | } 39 | 40 | public Integer getGender() { 41 | return gender; 42 | } 43 | 44 | public void setGender(Integer gender) { 45 | this.gender = gender; 46 | } 47 | 48 | public Department getDepartment() { 49 | return department; 50 | } 51 | 52 | public void setDepartment(Department department) { 53 | this.department = department; 54 | } 55 | 56 | public Date getBirth() { 57 | return birth; 58 | } 59 | 60 | public void setBirth(Date birth) { 61 | this.birth = birth; 62 | } 63 | public Employee(Integer id, String lastName, String email, Integer gender, 64 | Department department) { 65 | super(); 66 | this.id = id; 67 | this.lastName = lastName; 68 | this.email = email; 69 | this.gender = gender; 70 | this.department = department; 71 | this.birth = new Date(); 72 | } 73 | 74 | public Employee() { 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "Employee{" + 80 | "id=" + id + 81 | ", lastName='" + lastName + '\'' + 82 | ", email='" + email + '\'' + 83 | ", gender=" + gender + 84 | ", department=" + department + 85 | ", birth=" + birth + 86 | '}'; 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/exception/UserNotExistException.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.exception; 2 | 3 | public class UserNotExistException extends RuntimeException { 4 | 5 | public UserNotExistException() { 6 | super("用户不存在"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/filter/MyFilter.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.filter; 2 | 3 | import javax.servlet.*; 4 | import java.io.IOException; 5 | 6 | public class MyFilter implements Filter { 7 | 8 | @Override 9 | public void init(FilterConfig filterConfig) throws ServletException { 10 | 11 | } 12 | 13 | @Override 14 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 15 | System.out.println("MyFilter process..."); 16 | chain.doFilter(request,response); 17 | 18 | } 19 | 20 | @Override 21 | public void destroy() { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/listener/MyListener.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.listener; 2 | 3 | import javax.servlet.ServletContextEvent; 4 | import javax.servlet.ServletContextListener; 5 | 6 | public class MyListener implements ServletContextListener { 7 | @Override 8 | public void contextInitialized(ServletContextEvent sce) { 9 | System.out.println("contextInitialized...web应用启动"); 10 | } 11 | 12 | @Override 13 | public void contextDestroyed(ServletContextEvent sce) { 14 | System.out.println("contextDestroyed...当前web项目销毁"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/java/com/atguigu/springboot/servlet/MyServlet.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.servlet; 2 | 3 | import javax.servlet.ServletException; 4 | import javax.servlet.http.HttpServlet; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | import java.io.IOException; 8 | 9 | public class MyServlet extends HttpServlet { 10 | 11 | //处理get请求 12 | @Override 13 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 14 | doPost(req,resp); 15 | } 16 | 17 | @Override 18 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 19 | resp.getWriter().write("Hello MyServlet"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #spring.resources.static-locations=classpath:/hello/,classpath:/atguigu/ 2 | # \u9879\u76EE\u8BBF\u95EE\u8DEF\u5F84 3 | server.port=8081 4 | server.context-path=/crud 5 | server.tomcat.uri-encoding=UTF-8 6 | 7 | 8 | spring.mvc.date-format=yyyy-MM-dd 9 | 10 | # \u7981\u7528\u7F13\u5B58 11 | spring.thymeleaf.cache=false 12 | 13 | # \u56FD\u9645\u5316\u914D\u7F6E\u6587\u4EF6\uFF08\u5305\u540D.\u57FA\u7840\u540D\uFF09 14 | spring.messages.basename=i18n.login -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/i18n/login.properties: -------------------------------------------------------------------------------- 1 | login.btn=\u767B\u9646~ 2 | login.password=\u5BC6\u7801~ 3 | login.remember=\u8BB0\u4F4F\u6211~ 4 | login.tip=\u8BF7\u767B\u9646~ 5 | login.username=\u7528\u6237\u540D~ 6 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/i18n/login_en_US.properties: -------------------------------------------------------------------------------- 1 | login.btn=Sign In 2 | login.password=Password 3 | login.remember=Remember Me 4 | login.tip=Please sign in 5 | login.username=UserName -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/i18n/login_zh_CN.properties: -------------------------------------------------------------------------------- 1 | login.btn=\u767B\u9646 2 | login.password=\u5BC6\u7801 3 | login.remember=\u8BB0\u4F4F\u6211 4 | login.tip=\u8BF7\u767B\u5F55 5 | login.username=\u7528\u6237\u540D -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 首页 9 | 10 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-04-web-restfulcrud/src/main/resources/resources/favicon.ico -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/springmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/static/asserts/css/dashboard.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: .875rem; 3 | } 4 | 5 | .feather { 6 | width: 16px; 7 | height: 16px; 8 | vertical-align: text-bottom; 9 | } 10 | 11 | /* 12 | * Sidebar 13 | */ 14 | 15 | .sidebar { 16 | position: fixed; 17 | top: 0; 18 | bottom: 0; 19 | left: 0; 20 | z-index: 100; /* Behind the navbar */ 21 | padding: 0; 22 | box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1); 23 | } 24 | 25 | .sidebar-sticky { 26 | position: -webkit-sticky; 27 | position: sticky; 28 | top: 48px; /* Height of navbar */ 29 | height: calc(100vh - 48px); 30 | padding-top: .5rem; 31 | overflow-x: hidden; 32 | overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ 33 | } 34 | 35 | .sidebar .nav-link { 36 | font-weight: 500; 37 | color: #333; 38 | } 39 | 40 | .sidebar .nav-link .feather { 41 | margin-right: 4px; 42 | color: #999; 43 | } 44 | 45 | .sidebar .nav-link.active { 46 | color: #007bff; 47 | } 48 | 49 | .sidebar .nav-link:hover .feather, 50 | .sidebar .nav-link.active .feather { 51 | color: inherit; 52 | } 53 | 54 | .sidebar-heading { 55 | font-size: .75rem; 56 | text-transform: uppercase; 57 | } 58 | 59 | /* 60 | * Navbar 61 | */ 62 | 63 | .navbar-brand { 64 | padding-top: .75rem; 65 | padding-bottom: .75rem; 66 | font-size: 1rem; 67 | background-color: rgba(0, 0, 0, .25); 68 | box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25); 69 | } 70 | 71 | .navbar .form-control { 72 | padding: .75rem 1rem; 73 | border-width: 0; 74 | border-radius: 0; 75 | } 76 | 77 | .form-control-dark { 78 | color: #fff; 79 | background-color: rgba(255, 255, 255, .1); 80 | border-color: rgba(255, 255, 255, .1); 81 | } 82 | 83 | .form-control-dark:focus { 84 | border-color: transparent; 85 | box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); 86 | } 87 | 88 | /* 89 | * Utilities 90 | */ 91 | 92 | .border-top { border-top: 1px solid #e5e5e5; } 93 | .border-bottom { border-bottom: 1px solid #e5e5e5; } 94 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/static/asserts/css/signin.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | height: 100%; 4 | } 5 | 6 | body { 7 | display: -ms-flexbox; 8 | display: -webkit-box; 9 | display: flex; 10 | -ms-flex-align: center; 11 | -ms-flex-pack: center; 12 | -webkit-box-align: center; 13 | align-items: center; 14 | -webkit-box-pack: center; 15 | justify-content: center; 16 | padding-top: 40px; 17 | padding-bottom: 40px; 18 | /*background-color: #f5f5f5;*/ 19 | } 20 | 21 | .form-signin { 22 | width: 100%; 23 | max-width: 330px; 24 | padding: 15px; 25 | margin: 0 auto; 26 | } 27 | .form-signin .checkbox { 28 | font-weight: 400; 29 | } 30 | .form-signin .form-control { 31 | position: relative; 32 | box-sizing: border-box; 33 | height: auto; 34 | padding: 10px; 35 | font-size: 16px; 36 | } 37 | .form-signin .form-control:focus { 38 | z-index: 2; 39 | } 40 | .form-signin input[type="email"] { 41 | margin-bottom: -1px; 42 | border-bottom-right-radius: 0; 43 | border-bottom-left-radius: 0; 44 | } 45 | .form-signin input[type="password"] { 46 | margin-bottom: 10px; 47 | border-top-left-radius: 0; 48 | border-top-right-radius: 0; 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/static/asserts/img/bootstrap-solid.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/commons/bar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | [[${session.loginUser}]] 11 | 12 | 13 | 14 | Sign out 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | Dashboard (current) 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | Orders 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Products 52 | 53 | 54 | 55 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 员工管理 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Reports 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | Integrations 84 | 85 | 86 | 87 | 88 | 89 | Saved reports 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | Current month 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | Last quarter 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | Social engagement 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | Year-end sale 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/dashboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Dashboard Template for Bootstrap 11 | 12 | 13 | 14 | 15 | 16 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | Dashboard 62 | 63 | 64 | Share 65 | Export 66 | 67 | 68 | 69 | This week 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 93 | 94 | 95 | 96 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/emp/add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Dashboard Template for Bootstrap 12 | 13 | 14 | 15 | 16 | 17 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 64 | 65 | 66 | 67 | LastName 68 | 69 | 70 | 71 | Email 72 | 73 | 74 | 75 | Gender 76 | 77 | 78 | 男 79 | 80 | 81 | 82 | 女 83 | 84 | 85 | 86 | department 87 | 88 | 89 | 1 90 | 91 | 92 | 93 | Birth 94 | 95 | 96 | 添加 97 | 98 | 99 | 100 | 101 | 102 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/emp/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Dashboard Template for Bootstrap 12 | 13 | 14 | 15 | 16 | 17 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 员工添加 57 | 58 | 59 | 60 | 61 | # 62 | lastName 63 | email 64 | gender 65 | department 66 | birth 67 | 操作 68 | 69 | 70 | 71 | 72 | 73 | [[${emp.lastName}]] 74 | 75 | 76 | 77 | 78 | 79 | 编辑 80 | 删除 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 105 | 112 | 113 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Signin Template for Bootstrap 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Please sign in 18 | 19 | 20 | Username 21 | 22 | Password 23 | 24 | 25 | 26 | [[#{login.remember}]] 27 | 28 | 29 | Sign in 30 | © 2017-2018 31 | 中文 32 | English 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/main/resources/templates/success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 成功! 9 | 10 | 这是显示欢迎信息 11 | 12 | 13 | 14 | 15 | 16 | a 17 | 18 | 19 | 20 | [[${user}]] 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-boot-04-web-restfulcrud/src/test/java/com/atguigu/springboot/SpringBoot04WebRestfulcrudApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot04WebRestfulcrudApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-06-data-jdbc 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-06-data-jdbc 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-jdbc 31 | 32 | 33 | mysql 34 | mysql-connector-java 35 | runtime 36 | 37 | 38 | 39 | 40 | 41 | com.alibaba 42 | druid 43 | 1.1.8 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-web 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-starter-test 55 | test 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/java/com/atguigu/springboot/SpringBoot06DataJdbcApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBoot06DataJdbcApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBoot06DataJdbcApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/java/com/atguigu/springboot/config/DruidConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 11 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | import com.alibaba.druid.pool.DruidDataSource; 16 | import com.alibaba.druid.support.http.StatViewServlet; 17 | import com.alibaba.druid.support.http.WebStatFilter; 18 | 19 | @Configuration 20 | public class DruidConfig { 21 | 22 | @ConfigurationProperties(prefix = "spring.datasource") 23 | @Bean 24 | public DataSource druid() { 25 | return new DruidDataSource(); 26 | } 27 | 28 | /** 29 | * 配置Druid的监控 30 | * 1、配置一个管理后台的Servlet 31 | * @return 32 | */ 33 | @Bean 34 | public ServletRegistrationBean statViewServlet() { 35 | ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); 36 | Map initParams = new HashMap<>(4); 37 | initParams.put("loginUsername", "admin"); 38 | initParams.put("loginPassword", "123456"); 39 | //默认就是允许所有访问 40 | initParams.put("allow", ""); 41 | initParams.put("deny", "192.168.15.21"); 42 | 43 | bean.setInitParameters(initParams); 44 | return bean; 45 | } 46 | 47 | 48 | /** 49 | * 2、配置一个web监控的filter 50 | * @return 51 | */ 52 | @Bean 53 | public FilterRegistrationBean webStatFilter() { 54 | FilterRegistrationBean bean = new FilterRegistrationBean(); 55 | bean.setFilter(new WebStatFilter()); 56 | 57 | Map initParams = new HashMap<>(1); 58 | initParams.put("exclusions", "*.js,*.css,/druid/*"); 59 | 60 | bean.setInitParameters(initParams); 61 | 62 | bean.setUrlPatterns(Arrays.asList("/*")); 63 | 64 | return bean; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/java/com/atguigu/springboot/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.jdbc.core.JdbcTemplate; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | @Controller 13 | public class HelloController { 14 | 15 | @Autowired 16 | JdbcTemplate jdbcTemplate; 17 | 18 | 19 | @ResponseBody 20 | @GetMapping("/query") 21 | public Map map() { 22 | List> list = jdbcTemplate.queryForList("select * FROM department"); 23 | return list.get(0); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-06-data-jdbc/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | username: root 4 | password: root 5 | url: jdbc:mysql://localhost/springBoot 6 | driver-class-name: com.mysql.jdbc.Driver 7 | type: com.alibaba.druid.pool.DruidDataSource 8 | 9 | initialSize: 5 10 | minIdle: 5 11 | maxActive: 20 12 | maxWait: 60000 13 | timeBetweenEvictionRunsMillis: 60000 14 | minEvictableIdleTimeMillis: 300000 15 | validationQuery: SELECT 1 FROM DUAL 16 | testWhileIdle: true 17 | testOnBorrow: false 18 | testOnReturn: false 19 | poolPreparedStatements: true 20 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 21 | filters: stat,wall,log4j 22 | maxPoolPreparedStatementPerConnectionSize: 20 23 | useGlobalDataSourceStat: true 24 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 25 | # schema: 26 | # - classpath:department.sql 27 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/main/resources/department.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 本地 5 | Source Server Version : 50528 6 | Source Host : 127.0.0.1:3306 7 | Source Database : restful_crud 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50528 11 | File Encoding : 65001 12 | 13 | Date: 2018-03-05 10:41:40 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for department 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `department`; 22 | CREATE TABLE `department` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `departmentName` varchar(255) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 27 | 28 | -------------------------------------------------------------------------------- /spring-boot-06-data-jdbc/src/test/java/com/atguigu/springboot/SpringBoot06DataJdbcApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 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 SpringBoot06DataJdbcApplicationTests { 17 | 18 | 19 | @Autowired 20 | DataSource dataSource; 21 | 22 | @Test 23 | public void contextLoads() throws SQLException { 24 | //org.apache.tomcat.jdbc.pool.DataSource 25 | System.out.println(dataSource.getClass()); 26 | 27 | Connection connection = dataSource.getConnection(); 28 | System.out.println(connection); 29 | connection.close(); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-06-data-jpa 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-06-data-jpa 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-data-jpa 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-jdbc 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/java/com/atguigu/springboot/SpringBoot06DataJpaApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBoot06DataJpaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBoot06DataJpaApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/java/com/atguigu/springboot/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.atguigu.springboot.entity.User; 9 | import com.atguigu.springboot.repository.UserRepository; 10 | 11 | @RestController 12 | public class UserController { 13 | 14 | @Autowired 15 | UserRepository userRepository; 16 | 17 | @GetMapping("/user/{id}") 18 | public User getUser(@PathVariable("id") Integer id) { 19 | User user = userRepository.findOne(id); 20 | return user; 21 | } 22 | 23 | @GetMapping("/user") 24 | public User insertUser(User user) { 25 | User save = userRepository.save(user); 26 | return save; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/java/com/atguigu/springboot/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.entity; 2 | 3 | 4 | import javax.persistence.Column; 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | 11 | @Entity 12 | @Table(name = "tbl_user") 13 | public class User { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Integer id; 18 | 19 | @Column(name = "last_name", length = 50) 20 | private String lastName; 21 | 22 | @Column 23 | private String email; 24 | 25 | public Integer getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Integer id) { 30 | this.id = id; 31 | } 32 | 33 | public String getLastName() { 34 | return lastName; 35 | } 36 | 37 | public void setLastName(String lastName) { 38 | this.lastName = lastName; 39 | } 40 | 41 | public String getEmail() { 42 | return email; 43 | } 44 | 45 | public void setEmail(String email) { 46 | this.email = email; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/java/com/atguigu/springboot/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.atguigu.springboot.entity.User; 6 | 7 | public interface UserRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-06-data-jpa/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:mysql://192.168.15.22/jpa 4 | username: root 5 | password: 123456 6 | driver-class-name: com.mysql.jdbc.Driver 7 | jpa: 8 | hibernate: 9 | #更新或者创建数据表结构 10 | ddl-auto: update 11 | #控制台显示SQL 12 | show-sql: true 13 | -------------------------------------------------------------------------------- /spring-boot-06-data-jpa/src/test/java/com/atguigu/springboot/SpringBoot06DataJpaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot06DataJpaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() {} 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/data.sql: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE IF EXISTS department; 3 | 4 | CREATE TABLE IF NOT EXISTS department ( 5 | `id` int PRIMARY KEY AUTO_INCREMENT, 6 | `department_name` VARCHAR(255) 7 | ); 8 | 9 | INSERT INTO department(department_name) VALUES ('RD'); 10 | INSERT INTO department(department_name) VALUES ('HR'); -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-06-data-mybatis 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-06-data-mybatis 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-jdbc 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 1.3.1 40 | 41 | 42 | 43 | mysql 44 | mysql-connector-java 45 | runtime 46 | 47 | 48 | 49 | 50 | 51 | com.alibaba 52 | druid 53 | 1.1.8 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | net.minidev 64 | json-smart 65 | 2.2.1 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/SpringBoot06DataMybatisApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @MapperScan(value = "com.atguigu.springboot.mapper") 8 | @SpringBootApplication 9 | public class SpringBoot06DataMybatisApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBoot06DataMybatisApplication.class, args); 13 | } 14 | } 15 | 16 | /** 17 | * @EnableTransactionManagement 18 | * 19 | * 基本上等同于 20 | * 但是,在 SpringBoot 环境中,也可以不加此注解!! 21 | * 因为,SpringBoot 会自动注入 DataSourceTransactionManagerAutoConfiguration 22 | * 有了此类,就会注入 DataSourceTransactionManager 23 | * 24 | * 但是,如果是在非 SpringBoot 环境中,也想要使用纯注解的方式来使用事务的话,就需要加上 @EnableTransactionManagement 注解 25 | */ 26 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/bean/Department.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.bean; 2 | 3 | public class Department { 4 | 5 | private Integer id; 6 | private String departmentName; 7 | 8 | public void setId(Integer id) { 9 | this.id = id; 10 | } 11 | 12 | public void setDepartmentName(String departmentName) { 13 | this.departmentName = departmentName; 14 | } 15 | 16 | public Integer getId() { 17 | return id; 18 | } 19 | 20 | public String getDepartmentName() { 21 | return departmentName; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/bean/Employee.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.bean; 2 | 3 | public class Employee { 4 | 5 | private Integer id; 6 | private String lastName; 7 | private Integer gender; 8 | private String email; 9 | private Integer dId; 10 | 11 | public void setId(Integer id) { 12 | this.id = id; 13 | } 14 | 15 | public void setLastName(String lastName) { 16 | this.lastName = lastName; 17 | } 18 | 19 | public void setGender(Integer gender) { 20 | this.gender = gender; 21 | } 22 | 23 | public void setEmail(String email) { 24 | this.email = email; 25 | } 26 | 27 | public void setdId(Integer dId) { 28 | this.dId = dId; 29 | } 30 | 31 | public Integer getId() { 32 | return id; 33 | } 34 | 35 | public String getLastName() { 36 | return lastName; 37 | } 38 | 39 | public Integer getGender() { 40 | return gender; 41 | } 42 | 43 | public String getEmail() { 44 | return email; 45 | } 46 | 47 | public Integer getdId() { 48 | return dId; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/config/DruidConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.sql.DataSource; 8 | 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 11 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | import com.alibaba.druid.pool.DruidDataSource; 16 | import com.alibaba.druid.support.http.StatViewServlet; 17 | import com.alibaba.druid.support.http.WebStatFilter; 18 | 19 | @Configuration 20 | public class DruidConfig { 21 | 22 | @ConfigurationProperties(prefix = "spring.datasource") 23 | @Bean 24 | public DataSource druid() { 25 | return new DruidDataSource(); 26 | } 27 | 28 | //配置Druid的监控 29 | //1、配置一个管理后台的Servlet 30 | @Bean 31 | public ServletRegistrationBean statViewServlet() { 32 | ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); 33 | Map initParams = new HashMap<>(); 34 | 35 | initParams.put("loginUsername", "admin"); 36 | initParams.put("loginPassword", "123456"); 37 | //默认就是允许所有访问 38 | initParams.put("allow", ""); 39 | initParams.put("deny", "192.168.15.21"); 40 | 41 | bean.setInitParameters(initParams); 42 | return bean; 43 | } 44 | 45 | 46 | //2、配置一个web监控的filter 47 | @Bean 48 | public FilterRegistrationBean webStatFilter() { 49 | FilterRegistrationBean bean = new FilterRegistrationBean(); 50 | bean.setFilter(new WebStatFilter()); 51 | 52 | Map initParams = new HashMap<>(); 53 | initParams.put("exclusions", "*.js,*.css,/druid/*"); 54 | 55 | bean.setInitParameters(initParams); 56 | 57 | bean.setUrlPatterns(Arrays.asList("/*")); 58 | 59 | return bean; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/config/MyBatisConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.config; 2 | 3 | import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class MyBatisConfig { 9 | 10 | @Bean 11 | public ConfigurationCustomizer configurationCustomizer() { 12 | return configuration -> configuration.setMapUnderscoreToCamelCase(true); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/controller/DeptController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.transaction.annotation.Transactional; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.atguigu.springboot.bean.Department; 11 | import com.atguigu.springboot.bean.Employee; 12 | import com.atguigu.springboot.mapper.DepartmentMapper; 13 | import com.atguigu.springboot.mapper.EmployeeMapper; 14 | 15 | @RestController 16 | public class DeptController { 17 | 18 | @Autowired 19 | DepartmentMapper departmentMapper; 20 | 21 | @Autowired 22 | EmployeeMapper employeeMapper; 23 | 24 | 25 | @GetMapping("/dept/{id}") 26 | public Department getDepartment(@PathVariable("id") Integer id) { 27 | return departmentMapper.getDeptById(id); 28 | } 29 | 30 | @GetMapping("/dept") 31 | @Transactional 32 | public Department insertDept(Department department) { 33 | departmentMapper.insertDept(department); 34 | System.err.println("Inserted successfully"); 35 | System.err.println("---> 1/0 = " + (1 / 0)); 36 | return department; 37 | } 38 | 39 | @GetMapping("/emp/{id}") 40 | public Employee getEmp(@PathVariable("id") Integer id) { 41 | return employeeMapper.getEmpById(id); 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/mapper/DepartmentMapper.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.mapper; 2 | 3 | import org.apache.ibatis.annotations.Delete; 4 | import org.apache.ibatis.annotations.Insert; 5 | import org.apache.ibatis.annotations.Options; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.apache.ibatis.annotations.Update; 8 | 9 | import com.atguigu.springboot.bean.Department; 10 | 11 | 12 | /** 13 | * 指定这是一个操作数据库的mapper 14 | */ 15 | //@Mapper 16 | public interface DepartmentMapper { 17 | 18 | @Select("select * from department where id=#{id}") 19 | Department getDeptById(Integer id); 20 | 21 | @Delete("delete from department where id=#{id}") 22 | int deleteDeptById(Integer id); 23 | 24 | @Options(useGeneratedKeys = true, keyProperty = "id") 25 | @Insert("insert into department(department_name) values(#{departmentName})") 26 | int insertDept(Department department); 27 | 28 | @Update("update department set department_name=#{departmentName} where id=#{id}") 29 | int updateDept(Department department); 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/java/com/atguigu/springboot/mapper/EmployeeMapper.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.mapper; 2 | 3 | import com.atguigu.springboot.bean.Employee; 4 | 5 | /** 6 | * @Mapper 或者 @MapperScan 将接口扫描装配到容器中 7 | */ 8 | public interface EmployeeMapper { 9 | 10 | Employee getEmpById(Integer id); 11 | 12 | void insertEmp(Employee employee); 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-06-data-mybatis/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | username: root 4 | password: root 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/mybatis 7 | type: com.alibaba.druid.pool.DruidDataSource 8 | # 数据源其他配置 9 | initialSize: 5 10 | minIdle: 5 11 | maxActive: 20 12 | maxWait: 60000 13 | timeBetweenEvictionRunsMillis: 60000 14 | minEvictableIdleTimeMillis: 300000 15 | validationQuery: SELECT 1 FROM DUAL 16 | testWhileIdle: true 17 | testOnBorrow: false 18 | testOnReturn: false 19 | poolPreparedStatements: true 20 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 21 | filters: stat,wall,log4j 22 | maxPoolPreparedStatementPerConnectionSize: 20 23 | useGlobalDataSourceStat: true 24 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 25 | mybatis: 26 | # 指定全局配置文件位置 27 | config-location: classpath:mybatis/mybatis-config.xml 28 | # 指定sql映射文件位置 29 | mapper-locations: classpath:mybatis/mapper/*.xml 30 | 31 | # schema: 32 | # - classpath:sql/department.sql 33 | # - classpath:sql/employee.sql 34 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/mybatis/mapper/EmployeeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | SELECT * FROM employee WHERE id = #{id} 9 | 10 | 11 | 12 | 13 | INSERT INTO employee(lastName, email, gender, d_id) VALUES (#{lastName}, #{email}, #{gender}, #{dId}) 14 | 15 | 16 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/mybatis/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/sql/department.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 本地 5 | Source Server Version : 50528 6 | Source Host : 127.0.0.1:3306 7 | Source Database : restful_crud 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50528 11 | File Encoding : 65001 12 | 13 | Date: 2018-03-05 10:41:40 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS = 0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for department 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `department`; 22 | CREATE TABLE `department` ( 23 | `id` INT(11) NOT NULL AUTO_INCREMENT, 24 | `departmentName` VARCHAR(255) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) 27 | ENGINE = InnoDB 28 | AUTO_INCREMENT = 1 29 | DEFAULT CHARSET = utf8; 30 | 31 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/main/resources/sql/employee.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 本地 5 | Source Server Version : 50528 6 | Source Host : 127.0.0.1:3306 7 | Source Database : restful_crud 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50528 11 | File Encoding : 65001 12 | 13 | Date: 2018-03-05 10:41:58 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS = 0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for employee 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `employee`; 22 | CREATE TABLE `employee` ( 23 | `id` INT(11) NOT NULL AUTO_INCREMENT, 24 | `lastName` VARCHAR(255) DEFAULT NULL, 25 | `email` VARCHAR(255) DEFAULT NULL, 26 | `gender` INT(2) DEFAULT NULL, 27 | `d_id` INT(11) DEFAULT NULL, 28 | PRIMARY KEY (`id`) 29 | ) 30 | ENGINE = InnoDB 31 | AUTO_INCREMENT = 1 32 | DEFAULT CHARSET = utf8; 33 | -------------------------------------------------------------------------------- /spring-boot-06-data-mybatis/src/test/java/com/atguigu/springboot/SpringBoot06DataMybatisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot06DataMybatisApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() {} 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | spring-boot-07 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-07 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/java/com/atguigu/springboot/SpringBoot07Application.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | 7 | @SpringBootApplication 8 | public class SpringBoot07Application { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(SpringBoot07Application.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/java/com/atguigu/springboot/listener/HelloApplicationContextInitializer.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.listener; 2 | 3 | import org.springframework.context.ApplicationContextInitializer; 4 | import org.springframework.context.ConfigurableApplicationContext; 5 | 6 | public class HelloApplicationContextInitializer 7 | implements ApplicationContextInitializer { 8 | @Override 9 | public void initialize(ConfigurableApplicationContext applicationContext) { 10 | System.out.println("ApplicationContextInitializer...initialize..." + applicationContext); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/java/com/atguigu/springboot/listener/HelloApplicationRunner.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.listener; 2 | 3 | import org.springframework.boot.ApplicationArguments; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class HelloApplicationRunner implements ApplicationRunner { 9 | @Override 10 | public void run(ApplicationArguments args) throws Exception { 11 | System.out.println("ApplicationRunner...run...."); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/java/com/atguigu/springboot/listener/HelloCommandLineRunner.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.listener; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.stereotype.Component; 7 | 8 | 9 | @Component 10 | public class HelloCommandLineRunner implements CommandLineRunner { 11 | @Override 12 | public void run(String... args) throws Exception { 13 | System.out.println("CommandLineRunner...run..." + Arrays.asList(args)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/java/com/atguigu/springboot/listener/HelloSpringApplicationRunListener.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.listener; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.SpringApplicationRunListener; 5 | import org.springframework.context.ConfigurableApplicationContext; 6 | import org.springframework.core.env.ConfigurableEnvironment; 7 | 8 | public class HelloSpringApplicationRunListener implements SpringApplicationRunListener { 9 | 10 | //必须有的构造器 11 | public HelloSpringApplicationRunListener(SpringApplication application, String[] args) { 12 | 13 | } 14 | 15 | @Override 16 | public void starting() { 17 | System.out.println("SpringApplicationRunListener...starting..."); 18 | } 19 | 20 | @Override 21 | public void environmentPrepared(ConfigurableEnvironment environment) { 22 | Object o = environment.getSystemProperties().get("os.name"); 23 | System.out.println("SpringApplicationRunListener...environmentPrepared.." + o); 24 | } 25 | 26 | @Override 27 | public void contextPrepared(ConfigurableApplicationContext context) { 28 | System.out.println("SpringApplicationRunListener...contextPrepared..."); 29 | } 30 | 31 | @Override 32 | public void contextLoaded(ConfigurableApplicationContext context) { 33 | System.out.println("SpringApplicationRunListener...contextLoaded..."); 34 | } 35 | 36 | @Override 37 | public void finished(ConfigurableApplicationContext context, Throwable exception) { 38 | System.out.println("SpringApplicationRunListener...finished..."); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.context.ApplicationContextInitializer=\ 2 | com.atguigu.springboot.listener.HelloApplicationContextInitializer 3 | 4 | org.springframework.boot.SpringApplicationRunListener=\ 5 | com.atguigu.springboot.listener.HelloSpringApplicationRunListener -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-07-source-debug/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-07-source-debug/src/test/java/com/atguigu/springboot/SpringBoot07ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot07ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() {} 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-autoconfigurer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu.starter 7 | atguigu-spring-boot-starter-autoconfigurer 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | atguigu-spring-boot-starter-autoconfigurer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-autoconfigurer/src/main/java/com/atguigu/starter/HelloProperties.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.starter; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties(prefix = "atguigu.hello") 6 | public class HelloProperties { 7 | 8 | private String prefix; 9 | private String suffix; 10 | 11 | public String getPrefix() { 12 | return prefix; 13 | } 14 | 15 | public void setPrefix(String prefix) { 16 | this.prefix = prefix; 17 | } 18 | 19 | public String getSuffix() { 20 | return suffix; 21 | } 22 | 23 | public void setSuffix(String suffix) { 24 | this.suffix = suffix; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-autoconfigurer/src/main/java/com/atguigu/starter/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.starter; 2 | 3 | public class HelloService { 4 | 5 | HelloProperties helloProperties; 6 | 7 | public HelloProperties getHelloProperties() { 8 | return helloProperties; 9 | } 10 | 11 | public void setHelloProperties(HelloProperties helloProperties) { 12 | this.helloProperties = helloProperties; 13 | } 14 | 15 | public String sayHellAtguigu(String name) { 16 | return helloProperties.getPrefix() + "-" + name + "-" + helloProperties.getSuffix(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-autoconfigurer/src/main/java/com/atguigu/starter/HelloServiceAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.starter; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | @ConditionalOnWebApplication //web应用才生效 11 | @EnableConfigurationProperties(HelloProperties.class) 12 | public class HelloServiceAutoConfiguration { 13 | 14 | @Autowired 15 | HelloProperties helloProperties; 16 | 17 | @Bean 18 | public HelloService helloService() { 19 | HelloService service = new HelloService(); 20 | service.setHelloProperties(helloProperties); 21 | return service; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-autoconfigurer/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.atguigu.starter.HelloServiceAutoConfiguration -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.atguigu 7 | atguigu-spring-boot-starter-test 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | atguigu-spring-boot-starter-test 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.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-web 31 | 32 | 33 | 34 | 35 | com.atguigu.starter 36 | atguigu-spring-boot-starter 37 | 1.0-SNAPSHOT 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/src/main/java/com/atguigu/springboot/SpringBoot08StarterTestApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBoot08StarterTestApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBoot08StarterTestApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/src/main/java/com/atguigu/springboot/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import com.atguigu.starter.HelloService; 8 | 9 | @RestController 10 | public class HelloController { 11 | 12 | @Autowired 13 | HelloService helloService; 14 | 15 | @GetMapping("/hello") 16 | public String hello() { 17 | return helloService.sayHellAtguigu("haha"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | atguigu.hello.prefix=ATGUIGU 2 | atguigu.hello.suffix=HELLO WORLD -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter-test/src/test/java/com/atguigu/springboot/SpringBoot08StarterTestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.springboot; 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 SpringBoot08StarterTestApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() {} 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-08-customerized-starter/atguigu-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.atguigu.starter 8 | atguigu-spring-boot-starter 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | 15 | 16 | com.atguigu.starter 17 | atguigu-spring-boot-starter-autoconfigurer 18 | 0.0.1-SNAPSHOT 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-cyh-01-mybatis-paginator 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-jdbc 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.mybatis.spring.boot 35 | mybatis-spring-boot-starter 36 | 1.3.1 37 | 38 | 39 | com.github.miemiedev 40 | mybatis-paginator 41 | 1.2.17 42 | 43 | 44 | 45 | mysql 46 | mysql-connector-java 47 | runtime 48 | 49 | 50 | 51 | 52 | 53 | com.alibaba 54 | druid 55 | 1.1.8 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | net.minidev 66 | json-smart 67 | 2.2.1 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-maven-plugin 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/java/com/cyh/EmployeeApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EmployeeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EmployeeApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/java/com/cyh/bean/Employee.java: -------------------------------------------------------------------------------- 1 | package com.cyh.bean; 2 | 3 | public class Employee { 4 | 5 | private Integer id; 6 | private String lastName; 7 | private Integer gender; 8 | private String email; 9 | private Integer dId; 10 | 11 | public void setId(Integer id) { 12 | this.id = id; 13 | } 14 | 15 | public void setLastName(String lastName) { 16 | this.lastName = lastName; 17 | } 18 | 19 | public void setGender(Integer gender) { 20 | this.gender = gender; 21 | } 22 | 23 | public void setEmail(String email) { 24 | this.email = email; 25 | } 26 | 27 | public void setdId(Integer dId) { 28 | this.dId = dId; 29 | } 30 | 31 | public Integer getId() { 32 | return id; 33 | } 34 | 35 | public String getLastName() { 36 | return lastName; 37 | } 38 | 39 | public Integer getGender() { 40 | return gender; 41 | } 42 | 43 | public String getEmail() { 44 | return email; 45 | } 46 | 47 | public Integer getdId() { 48 | return dId; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/java/com/cyh/config/Config.java: -------------------------------------------------------------------------------- 1 | package com.cyh.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.plugin.Interceptor; 6 | import org.apache.ibatis.session.SqlSessionFactory; 7 | import org.mybatis.spring.SqlSessionFactoryBean; 8 | import org.springframework.boot.context.properties.ConfigurationProperties; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.core.io.Resource; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | 14 | import com.alibaba.druid.pool.DruidDataSource; 15 | import com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor; 16 | import com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect; 17 | 18 | @Configuration 19 | public class Config { 20 | 21 | @ConfigurationProperties(prefix = "spring.datasource") 22 | @Bean 23 | public DataSource dataSource() { 24 | return new DruidDataSource(); 25 | } 26 | 27 | /** 28 | * 注意,返回的对象是 SqlSessionFactory 而不是 SqlSessionFactoryBean 29 | * 方法名用 sqlSessionFactory 或者 sqlSessionFactoryBean 都是可以的,甚至是任意名字(如下所示) 30 | * @return SqlSessionFactory 31 | */ 32 | @Bean 33 | public SqlSessionFactory sqlSessionFactory_CYH() { 34 | try { 35 | SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean(); 36 | sessionFactoryBean.setDataSource(dataSource()); 37 | Resource[] resources = 38 | new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/*.xml"); 39 | sessionFactoryBean.setMapperLocations(resources); 40 | /* 注意:没有配置 mybatis-config.xml 文件 */ 41 | 42 | OffsetLimitInterceptor offsetLimitInterceptor = new OffsetLimitInterceptor(); 43 | offsetLimitInterceptor.setDialectClass(MySQLDialect.class.getName()); 44 | // 分页插件 45 | sessionFactoryBean.setPlugins(new Interceptor[] {offsetLimitInterceptor}); 46 | return sessionFactoryBean.getObject(); 47 | } catch (Exception e) { 48 | e.printStackTrace(); 49 | return null; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/java/com/cyh/mapper/EmployeeMapper.java: -------------------------------------------------------------------------------- 1 | package com.cyh.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.cyh.bean.Employee; 9 | import com.github.miemiedev.mybatis.paginator.domain.PageBounds; 10 | 11 | @Mapper 12 | @Component 13 | public interface EmployeeMapper { 14 | 15 | /** 16 | * 根据性别查询员工 17 | * @param gender 18 | * @param pageBounds 19 | * @return 20 | */ 21 | List findByGender(Integer gender, PageBounds pageBounds); 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | username: root 4 | password: root 5 | driver-class-name: com.mysql.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/mybatis 7 | type: com.alibaba.druid.pool.DruidDataSource 8 | 9 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/main/resources/mybatis/mapper/EmployeeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | SELECT * 10 | FROM tbl_employee 11 | WHERE gender = #{gender} 12 | 13 | 14 | -------------------------------------------------------------------------------- /spring-boot-cyh-01-mybatis-paginator/src/test/java/com/cyh/EmployeeTest.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 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 | import com.cyh.bean.Employee; 14 | import com.cyh.mapper.EmployeeMapper; 15 | import com.github.miemiedev.mybatis.paginator.domain.Order; 16 | import com.github.miemiedev.mybatis.paginator.domain.PageBounds; 17 | import com.github.miemiedev.mybatis.paginator.domain.PageList; 18 | 19 | @RunWith(SpringRunner.class) 20 | @SpringBootTest(classes = {EmployeeApplication.class}) 21 | public class EmployeeTest { 22 | 23 | @Autowired 24 | private EmployeeMapper employeeMapper; 25 | 26 | @Test 27 | public void testMybatisPaginator() throws IOException { 28 | int pageNum = 1; 29 | int pageSize = 3; 30 | Order order1 = new Order("last_name", Order.Direction.ASC, null); 31 | Order order2 = new Order("id", Order.Direction.ASC, null); 32 | PageBounds pageBounds = new PageBounds(pageNum, pageSize, order1, order2); 33 | 34 | List resultList = employeeMapper.findByGender(1, pageBounds); 35 | System.out.println(resultList.getClass().getName() + " ,, " + resultList.size()); 36 | Assert.assertTrue(resultList instanceof PageList); 37 | PageList pageList = (PageList) resultList; 38 | System.out.println(pageList.getPaginator()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-cyh-02-aop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-cyh-02-aop 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-aop 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /spring-boot-cyh-02-aop/src/main/java/com/cyh/SpringBootAopApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.ConfigurableApplicationContext; 6 | 7 | import com.cyh.service.MathCalculateService; 8 | 9 | /** 10 | * @author: yanhua.chen 11 | * @date: 2018/11/7 10:04 12 | */ 13 | @SpringBootApplication 14 | public class SpringBootAopApplication { 15 | 16 | public static void main(String[] args) { 17 | ConfigurableApplicationContext context = SpringApplication.run(SpringBootAopApplication.class, args); 18 | context.getBean(MathCalculateService.class).add(1, 2); 19 | context.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-cyh-02-aop/src/main/java/com/cyh/aop/ServiceAop.java: -------------------------------------------------------------------------------- 1 | package com.cyh.aop; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.Before; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author: yanhua.chen 9 | * @date: 2018/11/7 10:08 10 | */ 11 | @Aspect 12 | @Component 13 | public class ServiceAop { 14 | 15 | @Before(value = "execution(public * com.cyh.service..*.*(..))") 16 | public void beforeAdvice() { 17 | System.err.println("beforeAdvice()..."); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-cyh-02-aop/src/main/java/com/cyh/service/MathCalculateService.java: -------------------------------------------------------------------------------- 1 | package com.cyh.service; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * @author: yanhua.chen 7 | * @date: 2018/11/7 10:07 8 | */ 9 | @Component 10 | public class MathCalculateService { 11 | 12 | public void add(int a, int b) { 13 | System.err.println(String.format("The result of %d + %d is %d\n", a, b, a + b)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-cyh-03-data-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-cyh-03-data-redis 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-data-redis 21 | 22 | 23 | 24 | 25 | 26 | 27 | maven-compiler-plugin 28 | 3.5.1 29 | 30 | 1.8 31 | 1.8 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /spring-boot-cyh-03-data-redis/src/main/java/com/cyh/SpringBootRedisApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import java.time.LocalDateTime; 4 | 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 | import org.springframework.data.redis.core.StringRedisTemplate; 10 | import org.springframework.data.redis.core.ValueOperations; 11 | 12 | /** 13 | * @author: yanhua.chen 14 | * @date: 2019/1/10 10:45 15 | */ 16 | @SpringBootApplication 17 | public class SpringBootRedisApplication implements CommandLineRunner { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(SpringBootRedisApplication.class, args); 21 | } 22 | 23 | @Autowired 24 | private StringRedisTemplate stringRedisTemplate; 25 | 26 | @Override 27 | public void run(String... args) { 28 | String key = "redis.sentinel.test"; 29 | ValueOperations ops = stringRedisTemplate.opsForValue(); 30 | if (!stringRedisTemplate.hasKey(key)) { 31 | ops.set(key, "redis.sentinel.test at: " + LocalDateTime.now()); 32 | } 33 | System.err.println("Got value: " + ops.get(key)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-cyh-03-data-redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.redis.sentinel.master=cyh 2 | spring.redis.sentinel.nodes=192.168.171.134:26379 3 | -------------------------------------------------------------------------------- /spring-boot-cyh-03-data-redis/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-cyh-04-webmvc-messageConverter 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 2.9.2 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-logging 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-log4j2 39 | 40 | 41 | 42 | com.fasterxml.jackson.core 43 | jackson-databind 44 | ${jackson.version} 45 | 46 | 47 | com.fasterxml.jackson.core 48 | jackson-core 49 | ${jackson.version} 50 | 51 | 52 | com.fasterxml.jackson.core 53 | jackson-annotations 54 | ${jackson.version} 55 | 56 | 57 | org.projectlombok 58 | lombok 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/java/com/cyh/WebMvcMessageConvertApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author: yanhua.chen 8 | * @date: 2019/5/14 11:44 9 | */ 10 | @SpringBootApplication 11 | public class WebMvcMessageConvertApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(WebMvcMessageConvertApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/java/com/cyh/web/mvc/message/converter/config/DateFormatInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.cyh.web.mvc.message.converter.config; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.web.servlet.HandlerInterceptor; 7 | import org.springframework.web.servlet.ModelAndView; 8 | 9 | /** 10 | * @author: yanhua.chen 11 | * @date: 2019/5/14 16:44 12 | */ 13 | public class DateFormatInterceptor implements HandlerInterceptor { 14 | 15 | 16 | @Override 17 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 18 | throws Exception { 19 | System.err.println("============== preHandle........."); 20 | return true; 21 | } 22 | 23 | @Override 24 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 25 | ModelAndView modelAndView) throws Exception { 26 | 27 | } 28 | 29 | @Override 30 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) 31 | throws Exception { 32 | 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/java/com/cyh/web/mvc/message/converter/config/MessageConvertConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.cyh.web.mvc.message.converter.config; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.autoconfigure.web.HttpMessageConverters; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.http.converter.HttpMessageConverter; 9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 11 | 12 | /** 13 | * 如果有配置文件继承了 DelegatingWebMvcConfiguration 或者 WebMvcConfigurationSupport 14 | * 或者配置文件有 @EnableWebMvc 那么 @EnableAutoConfiguration 中的 WebMvcAutoConfiguration 将不会被自动配置, 15 | * 而是使用 WebMvcConfigurationSupport 的配置 16 | * 17 | * @EnableWebMvc = WebMvcConfigurationSupport 使用 @EnableWebMvc 注解等于扩展 WebMvcConfigurationSupport 但是没有重写任何方法 18 | * 19 | * @author: yanhua.chen 20 | * @date: 2019/5/14 11:45 21 | */ 22 | @Configuration 23 | public class MessageConvertConfiguration extends WebMvcConfigurationSupport { 24 | 25 | @Autowired 26 | private HttpMessageConverters httpMessageConverters; 27 | 28 | /** 29 | * 这里需要这样写,否则配置的 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss 不生效 30 | * * * * * * 不知道还有没有其它办法让 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss 生效 * * * * * 31 | */ 32 | @Override 33 | public void configureMessageConverters(List> converters) { 34 | System.err.println("--> configureMessageConverters"); 35 | super.configureMessageConverters(converters); 36 | converters.addAll(httpMessageConverters.getConverters()); 37 | } 38 | 39 | /** 40 | * 这里有个坑 41 | * 就是如果单独写个配置类去实现 org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter 并重写 42 | * 下面方法的话,其实不会生效! 43 | * 具体原因还不知道,但是感觉是和此处的 extends WebMvcConfigurationSupport 冲突了 44 | * 所以,将下面这个方法重写在这里 45 | * @param registry 46 | */ 47 | @Override 48 | public void addInterceptors(InterceptorRegistry registry) { 49 | System.err.println("--> addInterceptors"); 50 | super.addInterceptors(registry); 51 | registry.addInterceptor(new DateFormatInterceptor()).addPathPatterns("/**"); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/java/com/cyh/web/mvc/message/converter/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cyh.web.mvc.message.converter.controller; 2 | 3 | import org.springframework.web.bind.annotation.PostMapping; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import com.cyh.web.mvc.message.converter.entity.User; 8 | 9 | /** 10 | * @author: yanhua.chen 11 | * @date: 2019/5/14 13:38 12 | */ 13 | @RestController 14 | public class UserController { 15 | 16 | 17 | @PostMapping("/user/add") 18 | public String addUser(@RequestBody User user) { 19 | System.err.println("添加用户,请求参数:" + user); 20 | return user.toString(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/java/com/cyh/web/mvc/message/converter/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.cyh.web.mvc.message.converter.entity; 2 | 3 | import java.util.Date; 4 | 5 | import lombok.Data; 6 | 7 | /** 8 | * @author: yanhua.chen 9 | * @date: 2019/5/14 13:40 10 | */ 11 | @Data 12 | public class User { 13 | 14 | private String name; 15 | 16 | /** 17 | * 如果前端通过String的方式传入并通过框架进行解析成Date的话,String的格式就很重要 18 | */ 19 | private Date birthday; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/spring-boot-cyh-04-webmvc-messageConverter/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-cyh-04-webmvc-messageConverter/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring-boot-cyh-05-swagger-tomcat-bug/cyh.txt: -------------------------------------------------------------------------------- 1 | 阿里问题定位神器 Arthas 的骚操作,定位线上BUG,超给力 2 | 3 | https://mp.weixin.qq.com/s?__biz=MzIwMzY1OTU1NQ==&mid=2247488638&idx=1&sn=fcb143f2a80c779b0e8fbee7719fd54e&chksm=96cd5432a1badd2447c3ecf88f984546cb9faf670aa41d009161eef13cb3314dbee1476afdfa&mpshare=1&scene=1&srcid=0228XEMynARLr5B6BmQwCBXp&sharer_sharetime=1582854268971&sharer_shareid=4750b041e46b941ae37a12db27092f6a#rd 4 | 5 | https://blog.51cto.com/14528283/2466765 6 | 7 | -------------------------------------------------------------------------------- /spring-boot-cyh-05-swagger-tomcat-bug/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-cyh-05-swagger-tomcat-bug 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | 27 | 28 | io.springfox 29 | springfox-swagger2 30 | 2.8.0 31 | 32 | 33 | io.springfox 34 | springfox-swagger-ui 35 | 2.8.0 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | maven-compiler-plugin 48 | 49 | 1.8 50 | 1.8 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /spring-boot-cyh-05-swagger-tomcat-bug/src/main/java/com/cyh/SwaggerTomcatBugApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SwaggerTomcatBugApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SwaggerTomcatBugApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-cyh-05-swagger-tomcat-bug/src/main/java/com/cyh/config/SwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.cyh.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.service.Contact; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | @Configuration 16 | @EnableSwagger2 17 | public class SwaggerConfiguration { 18 | 19 | @Bean 20 | public Docket customDocket() { 21 | return new Docket(DocumentationType.SWAGGER_2).pathMapping("/").apiInfo(apiInfo()).select() 22 | .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build(); 23 | } 24 | 25 | private ApiInfo apiInfo() { 26 | Contact contact = new Contact("用户组", "", ""); 27 | return new ApiInfoBuilder().title("用户API接口").description("用户API接口").contact(contact).version("1.1.0").build(); 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-boot-cyh-05-swagger-tomcat-bug/src/main/java/com/cyh/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cyh.controller; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | 11 | @RestController 12 | @Api(tags = "用户信息控制类") 13 | public class UserController { 14 | 15 | @ApiOperation(value = "新增用户信息", httpMethod = "POST") 16 | @GetMapping("/time") 17 | public String addUser() { 18 | String now = LocalDateTime.now().toString(); 19 | System.out.println(now); 20 | return now; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-sample-aop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 1.5.9.RELEASE 10 | 11 | spring-boot-sample-aop 12 | Spring Boot AOP Sample 13 | Spring Boot AOP Sample 14 | http://projects.spring.io/spring-boot/ 15 | 16 | 17 | Pivotal Software, Inc. 18 | http://www.spring.io 19 | 20 | 21 | 22 | ${basedir}/../.. 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-aop 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /spring-boot-sample-aop/src/main/java/sample/aop/SampleAopApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.aop; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.CommandLineRunner; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | import sample.aop.service.HelloWorldService; 25 | 26 | @SpringBootApplication 27 | public class SampleAopApplication implements CommandLineRunner { 28 | 29 | // Simple example shows how an application can spy on itself with AOP 30 | 31 | @Autowired 32 | private HelloWorldService helloWorldService; 33 | 34 | @Override 35 | public void run(String... args) { 36 | System.out.println(this.helloWorldService.getHelloMessage()); 37 | } 38 | 39 | public static void main(String[] args) { 40 | SpringApplication.run(SampleAopApplication.class, args); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-sample-aop/src/main/java/sample/aop/monitor/ServiceMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.aop.monitor; 18 | 19 | import org.aspectj.lang.JoinPoint; 20 | import org.aspectj.lang.annotation.AfterReturning; 21 | import org.aspectj.lang.annotation.Aspect; 22 | import org.springframework.stereotype.Component; 23 | 24 | @Aspect 25 | @Component 26 | public class ServiceMonitor { 27 | 28 | @AfterReturning("execution(* sample..*Service.*(..))") 29 | public void logServiceAccess(JoinPoint joinPoint) { 30 | System.out.println("Completed: " + joinPoint); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-sample-aop/src/main/java/sample/aop/service/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.aop.service; 18 | 19 | import org.springframework.beans.factory.annotation.Value; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | public class HelloWorldService { 24 | 25 | @Value("${name:World}") 26 | private String name; 27 | 28 | public String getHelloMessage() { 29 | return "Hello " + this.name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-sample-aop/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | name:Phil -------------------------------------------------------------------------------- /spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.aop; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.springframework.boot.test.rule.OutputCapture; 26 | 27 | /** 28 | * Tests for {@link SampleAopApplication}. 29 | * 30 | * @author Dave Syer 31 | * @author Phillip Webb 32 | */ 33 | public class SampleAopApplicationTests { 34 | 35 | @Rule 36 | public OutputCapture outputCapture = new OutputCapture(); 37 | 38 | private String profiles; 39 | 40 | @Before 41 | public void init() { 42 | this.profiles = System.getProperty("spring.profiles.active"); 43 | } 44 | 45 | @After 46 | public void after() { 47 | if (this.profiles != null) { 48 | System.setProperty("spring.profiles.active", this.profiles); 49 | } else { 50 | System.clearProperty("spring.profiles.active"); 51 | } 52 | } 53 | 54 | @Test 55 | public void testDefaultSettings() { 56 | SampleAopApplication.main(new String[0]); 57 | String output = this.outputCapture.toString(); 58 | assertThat(output).contains("Hello Phil"); 59 | } 60 | 61 | @Test 62 | public void testCommandLineOverrides() { 63 | SampleAopApplication.main(new String[] {"--name=Gordon"}); 64 | String output = this.outputCapture.toString(); 65 | assertThat(output).contains("Hello Gordon"); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /spring-boot-sample-data-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 1.5.9.RELEASE 10 | 11 | spring-boot-sample-data-redis 12 | Spring Boot Data Redis Sample 13 | Spring Boot Data Redis Sample 14 | http://projects.spring.io/spring-boot/ 15 | 16 | Pivotal Software, Inc. 17 | http://www.spring.io 18 | 19 | 20 | ${basedir}/../.. 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-redis 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-test 32 | test 33 | 34 | 35 | 36 | 37 | production 38 | 39 | 41 | 42 | commons-pool 43 | commons-pool 44 | pom.lastUpdated 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /spring-boot-sample-data-redis/src/main/java/sample/data/redis/SampleRedisApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.data.redis; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.CommandLineRunner; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | import org.springframework.data.redis.core.StringRedisTemplate; 24 | import org.springframework.data.redis.core.ValueOperations; 25 | 26 | /** 27 | * @author Dave Syer 28 | */ 29 | @SpringBootApplication 30 | public class SampleRedisApplication implements CommandLineRunner { 31 | 32 | @Autowired 33 | private StringRedisTemplate template; 34 | 35 | @Override 36 | public void run(String... args) { 37 | ValueOperations ops = this.template.opsForValue(); 38 | String key = "spring.boot.redis.test"; 39 | if (!this.template.hasKey(key)) { 40 | ops.set(key, "foo"); 41 | } 42 | System.out.println("Found key " + key + ", value=" + ops.get(key)); 43 | } 44 | 45 | public static void main(String[] args) { 46 | // Close the context so it doesn't stay awake listening for redis 47 | SpringApplication.run(SampleRedisApplication.class, args).close(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-sample-data-redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.redis.host=192.168.91.128 2 | spring.redis.port=6379 3 | spring.redis.database=3 -------------------------------------------------------------------------------- /spring-boot-sample-data-redis/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package sample.data.redis; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import org.junit.Rule; 22 | import org.junit.Test; 23 | import org.springframework.boot.test.rule.OutputCapture; 24 | import org.springframework.data.redis.RedisConnectionFailureException; 25 | 26 | /** 27 | * Tests for {@link SampleRedisApplication}. 28 | * 29 | * @author Dave Syer 30 | */ 31 | public class SampleRedisApplicationTests { 32 | 33 | @Rule 34 | public OutputCapture outputCapture = new OutputCapture(); 35 | 36 | @Test 37 | public void testDefaultSettings() { 38 | try { 39 | SampleRedisApplication.main(new String[0]); 40 | } catch (Exception ex) { 41 | if (!redisServerRunning(ex)) { 42 | return; 43 | } 44 | } 45 | String output = this.outputCapture.toString(); 46 | assertThat(output).contains("Found key spring.boot.redis.test"); 47 | } 48 | 49 | private boolean redisServerRunning(Throwable ex) { 50 | System.out.println(ex.getMessage()); 51 | if (ex instanceof RedisConnectionFailureException) { 52 | return false; 53 | } 54 | return ex.getCause() == null || redisServerRunning(ex.getCause()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.atguigu 8 | spring-boot-senior-02-amqp 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.9.RELEASE 15 | 16 | 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-amqp 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-test 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/java/com/atguigu/SpringBootAmqpApplication.java: -------------------------------------------------------------------------------- 1 | package com.atguigu; 2 | 3 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author: CYH 9 | * @date: 2018/11/6 0006 8:14 10 | */ 11 | @SpringBootApplication 12 | @EnableRabbit 13 | public class SpringBootAmqpApplication { 14 | 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(SpringBootAmqpApplication.class, args); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/java/com/atguigu/bean/Book.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.bean; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author: CYH 8 | * @date: 2018/11/6 0006 8:26 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | public class Book { 13 | 14 | private String bookName; 15 | private String author; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/java/com/atguigu/config/MyRabbitMqConfig.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.config; 2 | 3 | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 4 | import org.springframework.amqp.support.converter.MessageConverter; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author: CYH 10 | * @date: 2018/11/6 0006 8:24 11 | */ 12 | @Configuration 13 | public class MyRabbitMqConfig { 14 | 15 | @Bean 16 | public MessageConverter messageConverter() { 17 | return new Jackson2JsonMessageConverter(); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/java/com/atguigu/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.atguigu.service; 2 | 3 | import org.springframework.amqp.core.Message; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.atguigu.bean.Book; 8 | 9 | /** 10 | * @author: CYH 11 | * @date: 2018/11/6 0006 8:31 12 | */ 13 | @Service 14 | public class BookService { 15 | 16 | @RabbitListener(queues = {"atguigu.news"}) 17 | public void receive(Book book) { 18 | System.err.println("RabbitListener received message: " + book); 19 | } 20 | 21 | @RabbitListener(queues = {"atguigu"}) 22 | public void receive02(Message message) { 23 | System.err.println("message.getBody(): " + message.getBody() + ", message.getMessageProperties(): " 24 | + message.getMessageProperties()); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=192.168.91.128 2 | spring.rabbitmq.username=guest 3 | spring.rabbitmq.password=guest 4 | #spring.rabbitmq.virtual-host= -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M %L - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-boot-senior-02-amqp/src/test/java/com/atguigu/SpringBootAmqpApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.atguigu; 2 | 3 | import java.util.Arrays; 4 | import java.util.Map; 5 | import java.util.concurrent.ConcurrentHashMap; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.amqp.core.AmqpAdmin; 10 | import org.springframework.amqp.core.Binding; 11 | import org.springframework.amqp.core.DirectExchange; 12 | import org.springframework.amqp.core.Queue; 13 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | 18 | import com.atguigu.bean.Book; 19 | 20 | /** 21 | * @author: CYH 22 | * @date: 2018/11/6 0006 8:15 23 | */ 24 | @RunWith(SpringRunner.class) 25 | @SpringBootTest 26 | public class SpringBootAmqpApplicationTest { 27 | 28 | @Autowired 29 | private RabbitTemplate rabbitTemplate; 30 | @Autowired 31 | private AmqpAdmin admin; 32 | 33 | 34 | @Test 35 | public void testDirect() { 36 | Map map = new ConcurrentHashMap(); 37 | map.put("msg", "这是第一个消息"); 38 | map.put("name", "CYH"); 39 | map.put("date", "20181106"); 40 | map.put("data", Arrays.asList(34, "Hello", 78.99)); 41 | rabbitTemplate.convertAndSend("exchange.direct", "atguigu.emps", map); 42 | } 43 | 44 | @Test 45 | public void testDirect2() { 46 | Book book = new Book("西游记", "吴承恩"); 47 | rabbitTemplate.convertAndSend("exchange.direct", "gulixueyuan.news", book); 48 | } 49 | 50 | @Test 51 | public void testReceiveAndConvert() { 52 | Object o = rabbitTemplate.receiveAndConvert("gulixueyuan.news"); 53 | System.err.println(o.getClass()); 54 | System.err.println(o); 55 | } 56 | 57 | @Test 58 | public void testFanout() { 59 | Book book = new Book("三国演义", "罗贯中"); 60 | rabbitTemplate.convertAndSend("exchange.fanout", null, book); 61 | } 62 | 63 | @Test 64 | public void testTopic() { 65 | Book book = new Book("红楼梦", "曹雪芹"); 66 | rabbitTemplate.convertAndSend("exchange.topic", "atguigu.#", book); 67 | } 68 | 69 | @Test 70 | public void testTopic2() { 71 | Book book = new Book("红楼梦", "高鄂"); 72 | rabbitTemplate.convertAndSend("exchange.topic", "*.news", book); 73 | } 74 | 75 | @Test 76 | public void createExchange() { 77 | admin.declareExchange(new DirectExchange("admin.exchange")); 78 | } 79 | 80 | @Test 81 | public void createQueue() { 82 | admin.declareQueue(new Queue("admin.queue", true)); 83 | } 84 | 85 | @Test 86 | public void binding() { 87 | admin.declareBinding( 88 | new Binding("admin.queue", Binding.DestinationType.QUEUE, "admin.exchange", "amqp.haha", null)); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.cyh 8 | spring-boot-senior-03-elastic-search 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 15 | 1.5.9.RELEASE 16 | 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-elasticsearch 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/src/main/java/com/cyh/ElasticSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ElasticSearchApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ElasticSearchApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/src/main/java/com/cyh/elastic/entity/Book.java: -------------------------------------------------------------------------------- 1 | package com.cyh.elastic.entity; 2 | 3 | import org.springframework.data.elasticsearch.annotations.Document; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Document(indexName = "cyh_test") 13 | public class Book { 14 | 15 | private Integer id; 16 | private String bookName; 17 | private String author; 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/src/main/java/com/cyh/elastic/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package com.cyh.elastic.repository; 2 | 3 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 4 | import org.springframework.stereotype.Component; 5 | 6 | import com.cyh.elastic.entity.Book; 7 | 8 | @Component 9 | public interface BookRepository extends ElasticsearchRepository { 10 | } 11 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.elasticsearch.cluster-name=elasticsearch 2 | spring.data.elasticsearch.cluster-nodes=192.168.91.131:9300 3 | -------------------------------------------------------------------------------- /spring-boot-senior-03-elastic-search/src/test/java/com/cyh/ElasticSearchTest.java: -------------------------------------------------------------------------------- 1 | package com.cyh; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import com.cyh.elastic.entity.Book; 10 | import com.cyh.elastic.repository.BookRepository; 11 | 12 | @RunWith(SpringRunner.class) 13 | @SpringBootTest 14 | public class ElasticSearchTest { 15 | 16 | @Autowired 17 | private BookRepository bookRepository; 18 | 19 | @Test 20 | public void testPut() { 21 | Book book = new Book(1, "红楼梦", "曹雪芹"); 22 | Book index = bookRepository.index(book); 23 | System.out.println(index); 24 | } 25 | 26 | @Test 27 | public void testGet() { 28 | Book book = bookRepository.findOne(1); 29 | System.out.println(book); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /usingthymeleaf.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyhbyw/springBoot_atguigu/e0e419ee555b1f7ceaf19e52a7bf54098bba29fe/usingthymeleaf.pdf --------------------------------------------------------------------------------
© 2017-2018