├── .gitignore ├── Java课程目录.pdf ├── 【00】demos_01 ├── 09:文件或文件夹的常用操作 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 09:文件或文件夹的常用操作.iml │ └── src │ │ └── OperateFile.java ├── 09:银行系统 │ ├── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── 09:银行系统.iml │ └── src │ │ ├── User.txt │ │ ├── dao │ │ └── AtmDao.java │ │ ├── domain │ │ └── User.java │ │ ├── service │ │ └── AtmService.java │ │ ├── test │ │ └── TestMain.java │ │ └── util │ │ └── FileLoaderAndCommit.java ├── 10:join与synchronized │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 10:join与synchronized.iml │ └── src │ │ ├── TestMain.java │ │ ├── ThreadOne.java │ │ ├── ThreadThree.java │ │ └── ThreadTwo.java ├── 10:哲学家进餐问题 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 10:哲学家进餐问题.iml │ └── src │ │ ├── Chopstick.java │ │ ├── Philosopher.java │ │ └── TestMain.java ├── 10:多线程读取同一文件 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 10:多线程读取同一文件.iml │ └── src │ │ ├── ReadFile.java │ │ └── test.txt ├── 10:火车站售票 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 10:火车站售票.iml │ └── src │ │ ├── System12306.java │ │ ├── TestMain.java │ │ ├── Ticket.java │ │ └── Window.java ├── 10:生产者消费者模型 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 10:生产者消费者模型.iml │ └── src │ │ ├── Consumer.java │ │ ├── Producer.java │ │ ├── TestMain.java │ │ └── WareHouse.java ├── 11:反射和注解 │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 11:反射和注解.iml │ └── src │ │ └── my_annotation │ │ ├── MyAnnotation.java │ │ ├── MySpring.java │ │ ├── Person.java │ │ └── TestMain.java ├── 12:考试系统 │ ├── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 12:考试系统.iml │ └── src │ │ ├── dao │ │ ├── QuestionDao.java │ │ └── UserDao.java │ │ ├── dbfile │ │ ├── Question.txt │ │ └── User.txt │ │ ├── domain │ │ ├── Question.java │ │ └── User.java │ │ ├── img │ │ ├── java.jpg │ │ ├── mysql.jpg │ │ └── tomcat.jpg │ │ ├── service │ │ ├── QuestionService.java │ │ └── UserService.java │ │ ├── test │ │ └── TestMain.java │ │ ├── util │ │ ├── BaseFrame.java │ │ ├── MySpring.java │ │ ├── QuestionFileReader.java │ │ └── UserFileReader.java │ │ └── view │ │ ├── ExamFrame.java │ │ └── LoginFrame.java └── README.md ├── 【00】demos_02 ├── 01:JDBC │ ├── .idea │ │ ├── .gitignore │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── uiDesigner.xml │ ├── 04:JDBC.iml │ ├── lib │ │ └── mysql-connector-java-8.0.20.jar │ └── src │ │ ├── dao │ │ ├── AreaDao.java │ │ ├── CityDao.java │ │ └── CountryDao.java │ │ ├── domain │ │ ├── Area.java │ │ ├── City.java │ │ └── Country.java │ │ ├── service │ │ ├── AreaService.java │ │ ├── CityService.java │ │ └── CountryService.java │ │ └── test │ │ ├── Eight.java │ │ ├── Eleven.java │ │ ├── Five.java │ │ ├── Four.java │ │ ├── Nine.java │ │ ├── One.java │ │ ├── Seven.java │ │ ├── Six.java │ │ ├── Ten.java │ │ ├── Three.java │ │ ├── Twelve.java │ │ └── Two.java ├── 02:银行系统(JDBC) │ ├── .idea │ │ ├── .gitignore │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 02:银行系统(JDBC).iml │ ├── lib │ │ └── mysql-connector-java-8.0.20.jar │ └── src │ │ ├── dao │ │ └── AtmDao.java │ │ ├── domain │ │ └── Atm.java │ │ ├── service │ │ └── AtmService.java │ │ └── test │ │ └── TestMain.java ├── 03:银行系统(JDBC+Swing) │ ├── .idea │ │ ├── .gitignore │ │ ├── dataSources.xml │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── 02:银行系统.iml │ ├── img │ │ └── MySQL.png │ ├── lib │ │ └── mysql-connector-java-8.0.20.jar │ └── src │ │ ├── dao │ │ └── AtmDao.java │ │ ├── domain │ │ └── Atm.java │ │ ├── service │ │ └── AtmService.java │ │ ├── test │ │ └── TestMain.java │ │ ├── util │ │ ├── BaseFrame.java │ │ └── MySpring.java │ │ └── view │ │ ├── AtmFrame.java │ │ ├── LoginFrame.java │ │ └── RegistFrame.java ├── 04:JDBC连接池 + ORM框架 │ ├── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── 04:JDBC连接池 + ORM框架.iml │ ├── lib │ │ └── mysql-connector-java-8.0.20.jar │ └── src │ │ ├── dao │ │ └── StudentDao.java │ │ ├── dbconfig.properties │ │ ├── domain │ │ └── Student.java │ │ ├── orm │ │ ├── Handler.java │ │ ├── RowMapper.java │ │ ├── SQLAndKey.java │ │ ├── SqlSessionFactory.java │ │ └── annotation │ │ │ ├── Delete.java │ │ │ ├── Insert.java │ │ │ ├── Select.java │ │ │ └── Update.java │ │ ├── ormdao │ │ └── StudentDao.java │ │ ├── pool │ │ ├── AbstractConnection.java │ │ ├── ConnectionPool.java │ │ ├── ConnectionPoolBusyException.java │ │ ├── DBConfig.java │ │ └── MyConnection.java │ │ ├── service │ │ └── StudentService.java │ │ └── test │ │ ├── TestJDBC.java │ │ ├── TestOrm.java │ │ └── TestPool.java ├── 04:银行系统(Swing+JDBC连接池+ORM框架) │ ├── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 04:银行系统(Swing+JDBC连接池+ORM框架).iml │ ├── lib │ │ └── mysql-connector-java-8.0.20.jar │ └── src │ │ ├── dao │ │ └── AtmDao.java │ │ ├── dbconfig.properties │ │ ├── domain │ │ └── Atm.java │ │ ├── orm │ │ ├── Handler.java │ │ ├── SQLAndKey.java │ │ ├── SqlSessionFactory.java │ │ └── annotation │ │ │ ├── Delete.java │ │ │ ├── Insert.java │ │ │ ├── Select.java │ │ │ └── Update.java │ │ ├── pool │ │ ├── AbstractConnection.java │ │ ├── ConnectionPool.java │ │ ├── ConnectionPoolBusyException.java │ │ ├── DBConfig.java │ │ └── MyConnection.java │ │ ├── service │ │ └── AtmService.java │ │ ├── test │ │ └── TestMain.java │ │ ├── util │ │ ├── BaseFrame.java │ │ └── MySpring.java │ │ └── view │ │ ├── AtmFrame.java │ │ ├── LoginFrame.java │ │ └── RegistFrame.java └── README.md ├── 【00】demos_03 ├── 01:请求与响应 │ ├── Browser │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ ├── misc.xml │ │ │ ├── modules.xml │ │ │ └── vcs.xml │ │ ├── Browser.iml │ │ └── src │ │ │ ├── Browser.java │ │ │ └── TestMain.java │ └── Server │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ │ ├── Server.iml │ │ └── src │ │ ├── controller │ │ ├── IndexController.java │ │ └── LoginController.java │ │ ├── server.properties │ │ ├── server │ │ ├── HttpServlet.java │ │ ├── HttpServletRequest.java │ │ ├── HttpServletResponse.java │ │ ├── Server.java │ │ ├── ServerFileReader.java │ │ ├── ServerHandler.java │ │ └── ServletController.java │ │ ├── test │ │ └── TestMain.java │ │ ├── view │ │ └── index.view │ │ └── web.properties ├── 02:银行系统(Tomcat+Servlet) │ ├── .idea │ │ ├── .gitignore │ │ ├── artifacts │ │ │ └── 02Tomcat_Servlet_war_exploded.xml │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── 02:银行系统(Tomcat+Servlet).iml │ ├── src │ │ ├── controller │ │ │ ├── DeleteController.java │ │ │ ├── DepositController.java │ │ │ ├── LoginController.java │ │ │ ├── QueryController.java │ │ │ ├── RegisterController.java │ │ │ ├── TransferController.java │ │ │ └── WithdrawController.java │ │ ├── dao │ │ │ └── AtmDao.java │ │ ├── domain │ │ │ └── Atm.java │ │ ├── service │ │ │ └── AtmService.java │ │ └── util │ │ │ └── MySpring.java │ └── web │ │ ├── WEB-INF │ │ ├── lib │ │ │ └── mysql-connector-java-8.0.20.jar │ │ └── web.xml │ │ ├── index.html │ │ ├── login.html │ │ ├── register.html │ │ ├── showBalance.jsp │ │ ├── showDelete.jsp │ │ ├── showDeposit.jsp │ │ ├── showGoodbye.jsp │ │ ├── showTransfer.jsp │ │ ├── showWithdraw.jsp │ │ └── welcome.jsp ├── 03:购物系统(Servlet+JSP) │ ├── .idea │ │ ├── .gitignore │ │ ├── artifacts │ │ │ └── 03Servlet_JSP_war_exploded.xml │ │ ├── encodings.xml │ │ ├── libraries │ │ │ └── mysql_connector_java_8_0_20.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ ├── 03:购物系统(Servlet+JSP).iml │ ├── src │ │ ├── controller │ │ │ ├── CalculatePriceController.java │ │ │ ├── LoginController.java │ │ │ ├── LogoutController.java │ │ │ ├── RegisterController.java │ │ │ ├── SaveCommodityController.java │ │ │ ├── SelectAllKindController.java │ │ │ └── SelectCommodityController.java │ │ ├── dao │ │ │ ├── CommodityDao.java │ │ │ ├── KindDao.java │ │ │ └── UserDao.java │ │ ├── domain │ │ │ ├── Commodity.java │ │ │ ├── Kind.java │ │ │ └── User.java │ │ ├── service │ │ │ ├── CommodityService.java │ │ │ ├── KindService.java │ │ │ └── UserService.java │ │ └── util │ │ │ └── MySpring.java │ └── web │ │ ├── WEB-INF │ │ ├── lib │ │ │ └── mysql-connector-java-8.0.20.jar │ │ └── web.xml │ │ ├── index.jsp │ │ ├── regist.jsp │ │ ├── showAllKind.jsp │ │ ├── showCommodity.jsp │ │ ├── showEndList.jsp │ │ └── welcome.jsp ├── 04:Web框架 │ ├── .idea │ │ ├── .gitignore │ │ ├── artifacts │ │ │ └── 04Web_war_exploded.xml │ │ ├── encodings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ ├── 04:Web框架.iml │ ├── src │ │ ├── ApplicationContext.properties │ │ ├── controller │ │ │ └── AtmController.java │ │ ├── domain │ │ │ └── Person.java │ │ └── mymvc │ │ │ ├── ControllerNotFoundException.java │ │ │ ├── DispatcherServlet.java │ │ │ ├── MethodParamNoAnnoException.java │ │ │ ├── ModelAndView.java │ │ │ ├── Param.java │ │ │ ├── RequestMapper.java │ │ │ └── SessionAttributes.java │ └── web │ │ ├── WEB-INF │ │ └── web.xml │ │ ├── index.jsp │ │ └── welcome.jsp └── README.md └── 【00】demos_04 ├── 01:ssm在线视频学习网站 ├── .idea │ ├── .gitignore │ ├── .name │ ├── 01:ssm在线视频学习网站.iml │ ├── compiler.xml │ ├── dataSources.xml │ ├── encodings.xml │ ├── google-java-format.xml │ ├── inspectionProfiles │ │ └── Project_Default.xml │ ├── jarRepositories.xml │ ├── misc.xml │ ├── saveactions_settings.xml │ ├── smartfox_info.xml │ ├── uiDesigner.xml │ ├── vcs.xml │ └── webContexts.xml ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── zgh │ │ │ │ └── onlinevideo │ │ │ │ ├── controller │ │ │ │ ├── PageController.java │ │ │ │ ├── SearchController.java │ │ │ │ ├── TopicController.java │ │ │ │ ├── UserController.java │ │ │ │ ├── VcodeController.java │ │ │ │ └── admin │ │ │ │ │ └── AdminController.java │ │ │ │ ├── dao │ │ │ │ ├── BannerDao.java │ │ │ │ ├── CourseTopicDao.java │ │ │ │ ├── CourseTypeDao.java │ │ │ │ ├── CourseVideoDao.java │ │ │ │ ├── ToolItemDao.java │ │ │ │ ├── ToolTypeDao.java │ │ │ │ └── UserDao.java │ │ │ │ ├── domain │ │ │ │ ├── Banner.java │ │ │ │ ├── CourseTopic.java │ │ │ │ ├── CourseType.java │ │ │ │ ├── CourseVideo.java │ │ │ │ ├── ToolItem.java │ │ │ │ ├── ToolType.java │ │ │ │ └── User.java │ │ │ │ ├── dto │ │ │ │ ├── LoginToken.java │ │ │ │ └── ResponseResult.java │ │ │ │ ├── exception │ │ │ │ ├── PageException.java │ │ │ │ ├── UserException.java │ │ │ │ └── VideoExceptionResolver.java │ │ │ │ ├── interceptor │ │ │ │ └── AutoLoginInterceptor.java │ │ │ │ ├── service │ │ │ │ ├── BannerService.java │ │ │ │ ├── CourseTopicService.java │ │ │ │ ├── CourseTypeService.java │ │ │ │ ├── CourseVideoService.java │ │ │ │ ├── ToolItemService.java │ │ │ │ ├── ToolTypeService.java │ │ │ │ ├── UserService.java │ │ │ │ └── impl │ │ │ │ │ ├── BannerServiceImpl.java │ │ │ │ │ ├── CourseTopicServiceImpl.java │ │ │ │ │ ├── CourseTypeServiceImpl.java │ │ │ │ │ ├── CourseVideoServiceImpl.java │ │ │ │ │ ├── MailSenderService.java │ │ │ │ │ ├── ToolItemServiceImpl.java │ │ │ │ │ ├── ToolTypeServiceImpl.java │ │ │ │ │ └── UserServiceImpl.java │ │ │ │ └── util │ │ │ │ ├── Constants.java │ │ │ │ └── VideoUtil.java │ │ ├── resources │ │ │ ├── jdbc.properties │ │ │ ├── logback.xml │ │ │ ├── mapper │ │ │ │ ├── bannerMapper.xml │ │ │ │ ├── courseTopicMapper.xml │ │ │ │ ├── courseTypeMapper.xml │ │ │ │ ├── courseVideoMapper.xml │ │ │ │ ├── toolItemMapper.xml │ │ │ │ ├── toolTypeMapper.xml │ │ │ │ └── userMapper.xml │ │ │ ├── mybatis-config.xml │ │ │ └── spring │ │ │ │ ├── spring-dao.xml │ │ │ │ ├── spring-mail.xml │ │ │ │ └── spring-web.xml │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── jsp │ │ │ │ ├── admin_main.jsp │ │ │ │ ├── admin_user_update.jsp │ │ │ │ ├── common │ │ │ │ │ ├── footer.jsp │ │ │ │ │ └── header.jsp │ │ │ │ ├── course_list.jsp │ │ │ │ ├── course_video.jsp │ │ │ │ ├── error.jsp │ │ │ │ ├── index.jsp │ │ │ │ ├── search.jsp │ │ │ │ ├── tool.jsp │ │ │ │ └── vip.jsp │ │ │ └── web.xml │ │ │ └── static │ │ │ ├── css │ │ │ ├── bootstrap-grid.min.css │ │ │ ├── bootstrap-reboot.min.css │ │ │ ├── bootstrap.min.css │ │ │ ├── font-awesome.min.css │ │ │ ├── jquery-confirm.min.css │ │ │ └── video.css │ │ │ ├── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ └── fontawesome-webfont.woff2 │ │ │ ├── imgs │ │ │ ├── bootstrap-solid.svg │ │ │ ├── card-item.png │ │ │ ├── hicon.jpg │ │ │ └── index_banner.jpg │ │ │ └── js │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── bootstrap.min.js │ │ │ ├── jquery-3.3.1.min.js │ │ │ ├── jquery-confirm.min.js │ │ │ └── popper.min.js │ └── test │ │ └── java │ │ ├── dao │ │ └── DaoTest.java │ │ └── service │ │ └── ServiceTest.java └── ssm.iml ├── 02:springboot-epidemic ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── graph.json ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── zgh │ │ │ │ ├── SpringbootEpidemicApplication.java │ │ │ │ ├── bean │ │ │ │ ├── DataBean.java │ │ │ │ ├── GraphBarBean.java │ │ │ │ ├── GraphBean.java │ │ │ │ └── MapBean.java │ │ │ │ ├── config │ │ │ │ ├── MyConfig.java │ │ │ │ └── MyLocalResolver.java │ │ │ │ ├── controller │ │ │ │ ├── DataController.java │ │ │ │ └── GraphController.java │ │ │ │ ├── handler │ │ │ │ ├── DataHandler.java │ │ │ │ ├── GraphHandler.java │ │ │ │ └── JsoupHandler.java │ │ │ │ ├── mail │ │ │ │ └── MailComponent.java │ │ │ │ ├── mapper │ │ │ │ ├── DataMapper.java │ │ │ │ └── GraphMapper.java │ │ │ │ ├── service │ │ │ │ ├── DataService.java │ │ │ │ ├── DataServiceImpl.java │ │ │ │ ├── GraphService.java │ │ │ │ └── GraphServiceImpl.java │ │ │ │ └── util │ │ │ │ ├── HttpClientUtil.java │ │ │ │ ├── HttpConnUtil.java │ │ │ │ ├── MailUtil.java │ │ │ │ └── PathUtil.java │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── banner.txt │ │ │ ├── i18n │ │ │ ├── list.properties │ │ │ ├── list_en_US.properties │ │ │ └── list_zh_CN.properties │ │ │ ├── static │ │ │ ├── bootstrap.css │ │ │ └── echarts │ │ │ │ ├── china.js │ │ │ │ └── echarts.min.js │ │ │ └── templates │ │ │ ├── graph.html │ │ │ ├── graphBar.html │ │ │ ├── list.html │ │ │ └── map.html │ └── test │ │ └── java │ │ └── com │ │ └── zgh │ │ └── EpidemicApplicationTests.java ├── tmp.html └── tmp.json ├── README.md └── images ├── image-20201119211503524.png └── image-20210101122150218.png /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | target 3 | 4 | 【01】JavaSE 5 | 【02】MySQL 6 | 【03】网络协议 7 | 【04】jQuery 8 | 【05】J2EE 9 | 【06】MyBatis 10 | 【07】Spring 11 | 【08】SpringMVC 12 | 【09】SpringBoot 13 | 14 | 【20】Maven 15 | 【21】Git+svn 16 | 17 | 【30】Java公开课 18 | 【31】拓展部分知识点 19 | 【32】Java算法 -------------------------------------------------------------------------------- /Java课程目录.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/Java课程目录.pdf -------------------------------------------------------------------------------- /【00】demos_01/09:文件或文件夹的常用操作/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/09:文件或文件夹的常用操作/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/09:文件或文件夹的常用操作/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/09:文件或文件夹的常用操作/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/09:文件或文件夹的常用操作/09:文件或文件夹的常用操作.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/09:银行系统.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/src/User.txt: -------------------------------------------------------------------------------- 1 | lisi-444-400.0 2 | zhangsan-333-301.0 3 | wangwu-555-500.0 4 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/src/dao/AtmDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import domain.User; 4 | import util.FileLoaderAndCommit; 5 | 6 | import java.util.HashMap; 7 | 8 | public class AtmDao { 9 | 10 | private FileLoaderAndCommit flac = new FileLoaderAndCommit("src\\User.txt"); 11 | 12 | //获取缓存 13 | private HashMap userBox = flac.loadFile(); 14 | 15 | //查询一行记录 16 | public User selectOne(String name){ 17 | return userBox.get(name); 18 | } 19 | 20 | //更新一行记录 21 | public void update(User user){ 22 | userBox.put(user.getAname(),user); 23 | flac.commit(userBox); 24 | } 25 | 26 | public void insert(User user){ 27 | userBox.put(user.getAname(),user); 28 | flac.commit(userBox); 29 | } 30 | 31 | //删除一行记录 32 | public void delete(String name){ 33 | userBox.remove(name); 34 | flac.commit(userBox); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /【00】demos_01/09:银行系统/src/domain/User.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class User { 4 | 5 | //只是为了记录数据库中的一行信息 账号 密码 余额 6 | private String aname; 7 | private String apassword; 8 | private Float abalance; 9 | 10 | public User(){} 11 | 12 | public User(String aname, String apassword, Float abalance) { 13 | this.aname = aname; 14 | this.apassword = apassword; 15 | this.abalance = abalance; 16 | } 17 | 18 | public String getAname() { 19 | return aname; 20 | } 21 | 22 | public void setAname(String aname) { 23 | this.aname = aname; 24 | } 25 | 26 | public String getApassword() { 27 | return apassword; 28 | } 29 | 30 | public void setApassword(String apassword) { 31 | this.apassword = apassword; 32 | } 33 | 34 | public Float getAbalance() { 35 | return abalance; 36 | } 37 | 38 | public void setAbalance(Float abalance) { 39 | this.abalance = abalance; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/10:join与synchronized.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/src/TestMain.java: -------------------------------------------------------------------------------- 1 | public class TestMain { 2 | 3 | public static void main(String[] args){ 4 | ThreadOne one = new ThreadOne(); 5 | one.start(); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/src/ThreadOne.java: -------------------------------------------------------------------------------- 1 | public class ThreadOne extends Thread { 2 | 3 | public void run(){ 4 | System.out.println("thread-one start"); 5 | ThreadTwo two = new ThreadTwo(); 6 | two.start(); 7 | try { 8 | two.join(2000);//线程2加入线程1里面 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | System.out.println("thread-one end"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/src/ThreadThree.java: -------------------------------------------------------------------------------- 1 | public class ThreadThree extends Thread{ 2 | 3 | private ThreadTwo two; 4 | public ThreadThree(ThreadTwo two){ 5 | this.two = two; 6 | } 7 | 8 | public void run(){ 9 | //在two执行的过程中 one等待的过程中 three将two对象锁定 10 | System.out.println("thread-three start"); 11 | synchronized(two){ 12 | System.out.println("two is locked"); 13 | try { 14 | Thread.sleep(10000); 15 | } catch (InterruptedException e) { 16 | e.printStackTrace(); 17 | } 18 | System.out.println("two is free"); 19 | } 20 | System.out.println("thread-three end"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /【00】demos_01/10:join与synchronized/src/ThreadTwo.java: -------------------------------------------------------------------------------- 1 | public class ThreadTwo extends Thread { 2 | 3 | public void run(){ 4 | System.out.println("thread-two start"); 5 | ThreadThree three = new ThreadThree(this); 6 | three.start(); 7 | try { 8 | Thread.sleep(5000); 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | System.out.println("thread-two end"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/10:哲学家进餐问题.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/src/Chopstick.java: -------------------------------------------------------------------------------- 1 | //筷子 2 | public class Chopstick { 3 | 4 | private int num; 5 | 6 | public Chopstick(int num){ 7 | this.num = num; 8 | } 9 | 10 | public int getNum(){ 11 | return this.num; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/src/Philosopher.java: -------------------------------------------------------------------------------- 1 | //哲学家 2 | public class Philosopher extends Thread{ 3 | 4 | private String pname;//哲学家的名字 5 | private Chopstick left;//左手的筷子 6 | private Chopstick right;//右手的筷子 7 | private long time; 8 | 9 | public Philosopher(String pname,Chopstick left,Chopstick right,long time){ 10 | this.pname = pname; 11 | this.left = left; 12 | this.right = right; 13 | this.time = time; 14 | } 15 | 16 | public void run(){ 17 | try { 18 | Thread.sleep(time); 19 | } catch (InterruptedException e) { 20 | e.printStackTrace(); 21 | } 22 | synchronized (left) { 23 | System.out.println(this.pname + "拿起了左手边的" + this.left.getNum() + "筷子"); 24 | synchronized (right){ 25 | System.out.println(this.pname + "拿起了右手边的" + this.right.getNum() + "筷子"); 26 | System.out.println(this.pname + "开始狼吞虎咽的吃起来啦"); 27 | } 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /【00】demos_01/10:哲学家进餐问题/src/TestMain.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 避免死锁的方法: 3 | * - 礼让----产生时间差()使用这个方法 4 | * - 不要产生共用的问题 5 | */ 6 | public class TestMain { 7 | 8 | public static void main(String[] args){ 9 | //四根筷子 10 | Chopstick c1 = new Chopstick(1); 11 | Chopstick c2 = new Chopstick(2); 12 | Chopstick c3 = new Chopstick(3); 13 | Chopstick c4 = new Chopstick(4); 14 | 15 | //四位哲学家 16 | // 哲学家p1、p3坐在对桌, 可以同时拿起两双筷子 17 | // 哲学家p2、p4坐在对桌, 同理 18 | Philosopher p1 = new Philosopher("哲学家a",c1,c2,0); 19 | Philosopher p2 = new Philosopher("哲学家b",c2,c3,1000); 20 | Philosopher p3 = new Philosopher("哲学家c",c3,c4,0); 21 | Philosopher p4 = new Philosopher("哲学家d",c4,c1,1000); 22 | 23 | p1.start(); 24 | p2.start(); 25 | p3.start(); 26 | p4.start(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/10:多线程读取同一文件.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/src/ReadFile.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | 5 | public class ReadFile extends Thread{ 6 | private long step; 7 | private long num; 8 | 9 | public ReadFile(long step,long num){ 10 | this.step = step; 11 | this.num = num; 12 | } 13 | 14 | @Override 15 | public void run() { 16 | File f = new File("src\\test.txt"); 17 | FileInputStream fis = null; 18 | try { 19 | fis = new FileInputStream(f); 20 | fis.skip(step); 21 | while(num != 0){ 22 | System.out.println(this.getName() + "读取:" + (char)fis.read()); 23 | num--; 24 | } 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | ReadFile rf1 = new ReadFile(0,10); 32 | ReadFile rf2 = new ReadFile(10,10); 33 | ReadFile rf3 = new ReadFile(20,6); 34 | rf1.start(); 35 | rf2.start(); 36 | rf3.start(); 37 | } 38 | } -------------------------------------------------------------------------------- /【00】demos_01/10:多线程读取同一文件/src/test.txt: -------------------------------------------------------------------------------- 1 | abcdefghijklmnopqrstuvwxyz -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/10:火车站售票.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/src/System12306.java: -------------------------------------------------------------------------------- 1 | import java.util.Vector; 2 | 3 | //12306售票系统 4 | public class System12306 { 5 | 6 | //单例模式(饿汉式) 7 | private System12306(){} 8 | private static System12306 sys = new System12306(); 9 | public static System12306 getInstance(){ 10 | return sys; 11 | } 12 | 13 | //Vector或者Stack 线程安全 14 | private Vector tickets = new Vector<>(); 15 | 16 | //当前系统创建后给tickets集合赋值 17 | { 18 | for(int i = 10; i < 100; i++){ 19 | tickets.add(new Ticket("北京"+i,"深圳"+i,(i%5+5)*25F));//价格随机 20 | } 21 | } 22 | 23 | //获取一张火车票 24 | public Ticket getTicket(){ 25 | try { 26 | return tickets.remove(0); 27 | }catch (Exception e){ 28 | return null;//无票 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/src/TestMain.java: -------------------------------------------------------------------------------- 1 | public class TestMain { 2 | 3 | public static void main(String[] args){ 4 | Window w1 = new Window("广州南站"); 5 | Window w2 = new Window("广州西站"); 6 | Window w3 = new Window("广州北站"); 7 | w1.start(); 8 | w2.start(); 9 | w3.start(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/src/Ticket.java: -------------------------------------------------------------------------------- 1 | //车票 2 | public class Ticket { 3 | 4 | private String start;//起始站名 5 | private String end;//终点站名 6 | private Float price;//票价 7 | 8 | public Ticket(){} 9 | public Ticket(String start, String end, Float price){ 10 | this.start = start; 11 | this.end = end; 12 | this.price = price; 13 | } 14 | 15 | @Override 16 | public String toString(){ 17 | StringBuilder builder = new StringBuilder("[ "); 18 | builder.append(this.start); 19 | builder.append(" --> "); 20 | builder.append(this.end); 21 | builder.append(" : "); 22 | builder.append(this.price); 23 | builder.append(" ]"); 24 | return builder.toString(); 25 | } 26 | 27 | public String getStart() { 28 | return start; 29 | } 30 | public void setStart(String start) { 31 | this.start = start; 32 | } 33 | public String getEnd() { 34 | return end; 35 | } 36 | public void setEnd(String end) { 37 | this.end = end; 38 | } 39 | public Float getPrice() { 40 | return price; 41 | } 42 | public void setPrice(Float price) { 43 | this.price = price; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /【00】demos_01/10:火车站售票/src/Window.java: -------------------------------------------------------------------------------- 1 | //窗口售票 2 | public class Window extends Thread { 3 | 4 | private String windowName;//窗口的名字 5 | public Window(String windowName){ 6 | this.windowName = windowName; 7 | } 8 | 9 | public void run(){ 10 | this.sellTicket(); 11 | } 12 | 13 | public void sellTicket(){ 14 | System12306 sys = System12306.getInstance(); 15 | while(true){ 16 | Ticket ticket = sys.getTicket(); 17 | if (ticket == null) { 18 | System.out.println("对不起" + windowName + "窗口车票已售完"); 19 | break; 20 | } 21 | System.out.println("从" + windowName + "售出:" + ticket); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/10:生产者消费者模型.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/src/Consumer.java: -------------------------------------------------------------------------------- 1 | //消费者 2 | public class Consumer extends Thread { 3 | 4 | //一直从仓库里面拿东西 5 | @Override 6 | public void run() { 7 | while(true){ 8 | WareHouse.getInstance().get(); 9 | System.out.println("Customer拿走了一件东东"); 10 | try { 11 | Thread.sleep(300); 12 | } catch (InterruptedException e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/src/Producer.java: -------------------------------------------------------------------------------- 1 | //生产者 2 | public class Producer extends Thread { 3 | 4 | //一直向仓库中添加元素 5 | @Override 6 | public void run() { 7 | while(true){ 8 | WareHouse.getInstance().add(); 9 | System.out.println("Producer存入了一件货物"); 10 | try { 11 | Thread.sleep(200); 12 | } catch (InterruptedException e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/src/TestMain.java: -------------------------------------------------------------------------------- 1 | public class TestMain { 2 | public static void main(String[] args) { 3 | Producer producer = new Producer();//一个生产者 4 | //设置线程的优先级,让生产者先干活 5 | //参数:优先级别1-10 6 | // 数字越高,优先级越高,更加容易获得cpu分配的时间碎片 7 | producer.setPriority(10); 8 | 9 | Consumer customer1 = new Consumer();//两个消费者 10 | Consumer customer2 = new Consumer(); 11 | producer.start(); 12 | customer1.start(); 13 | customer2.start(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_01/10:生产者消费者模型/src/WareHouse.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | //仓库 4 | public class WareHouse { 5 | 6 | private WareHouse(){} 7 | private static WareHouse warehouse = new WareHouse(); 8 | public static WareHouse getInstance(){ 9 | return warehouse; 10 | } 11 | 12 | private ArrayList list = new ArrayList<>(); 13 | 14 | //向集合中添加元素 15 | public synchronized void add(){ 16 | if(list.size() < 20){ 17 | list.add("X"); 18 | }else{ 19 | try { 20 | notifyAll();//唤醒其余线程 21 | wait();//访问仓库的线程进入等待 22 | } catch (InterruptedException e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | 28 | //向集合中取元素 29 | public synchronized void get(){ 30 | if(list.size() > 0){ 31 | list.remove(0); 32 | }else{ 33 | try { 34 | notifyAll();//唤醒其余线程 35 | wait();//访问仓库的线程进入等待 36 | } catch (InterruptedException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/11:反射和注解.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/src/my_annotation/MyAnnotation.java: -------------------------------------------------------------------------------- 1 | package my_annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | import static java.lang.annotation.ElementType.*; 7 | @Target({FIELD, METHOD, CONSTRUCTOR}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | public @interface MyAnnotation { 10 | String[] value(); 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/src/my_annotation/Person.java: -------------------------------------------------------------------------------- 1 | package my_annotation; 2 | 3 | public class Person { 4 | 5 | private String name; 6 | private Integer age; 7 | private String sex; 8 | 9 | @MyAnnotation({"zgh","18","男"}) 10 | public Person(){} 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | public Integer getAge() { 19 | return age; 20 | } 21 | public void setAge(Integer age) { 22 | this.age = age; 23 | } 24 | public String getSex() { 25 | return sex; 26 | } 27 | public void setSex(String sex) { 28 | this.sex = sex; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /【00】demos_01/11:反射和注解/src/my_annotation/TestMain.java: -------------------------------------------------------------------------------- 1 | package my_annotation; 2 | 3 | public class TestMain { 4 | public static void main(String[] args) { 5 | Person p = MySpring.getBean("my_annotation.Person"); 6 | System.out.println(p.getName() + "--" + p.getAge() + "--" + p.getSex()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/12:考试系统.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/dao/QuestionDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import domain.Question; 4 | import util.QuestionFileReader; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashSet; 8 | import java.util.Random; 9 | 10 | public class QuestionDao { 11 | 12 | //负责读文件 随机生成一套试卷 题库13道题目 生成试卷是5道 13 | //参数: 试卷题目数 14 | //返回值:ArrayList 15 | public ArrayList getPaper(int count){ 16 | //卷子 17 | HashSet paper = new HashSet<>(); 18 | //题库 19 | ArrayList questionBank = new ArrayList<>(QuestionFileReader.getQuestion()); 20 | while(paper.size() != count){ 21 | int index = new Random().nextInt(questionBank.size());//[0, 13) 22 | paper.add(questionBank.get(index)); 23 | } 24 | return new ArrayList<>(paper); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import domain.User; 4 | import util.UserFileReader; 5 | 6 | //持久层:数据的持久化 7 | //只负责数据的读、写,不负责处理逻辑 8 | //本代码仅仅包含了I/O(学习了数据库后,这个层次的内部代码都是JDBC) 9 | public class UserDao { 10 | 11 | //缓存---虚拟机(内存中)---存储文件中的所有信息 12 | 13 | //查询一行记录 14 | public User selectOne(String account){ 15 | return UserFileReader.getUser(account); 16 | } 17 | 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/dbfile/Question.txt: -------------------------------------------------------------------------------- 1 | 以下哪个是Java的基本数据类型?
A.String
B.Integer
C.boolean
D.Math#C 2 | 以下哪个是Java的引用数据类型?
A.String
B.int
C.boolean
D.char#A 3 | 以下哪不是Object类中的方法?
A.equals
B.hashCode
C.toString
D.compareTo#D 4 | 以下哪个不是String类中的方法?
A.charAt
B.reverse
C.replace
D.indexOf#B 5 | 以下哪个是Java中非法标识符?
A.variable
B.variable2
C.%variable
D._variable#C 6 | 以下哪个选项是用于编译Java文件的?
A.javac
B.java
C.path
D.classPath#A 7 | 经过编译后形成的文件后缀名?
A. .obj
B. .exe
C. .class
D. .java#C 8 | 未编译之前的源文件后缀名?
A. .obj
B. .exe
C. .class
D. .java#D 9 | 下面哪个写法声明数组正确?
A.int[] a = new int[10];
B.float f = new float[10];
C.char d[] = new char('d');
D.byte[10] b = new byte[];#A 10 | 下面哪个选项是key-value形式?
A.ArrayList
B.HashMap
C.LinkedList
D.Vector#B 11 | 右图是以下哪个语言的Logo?
A.C
B.Java
C.PHP
D.VB#B#java.jpg 12 | 右图是以下哪个数据库的Logo?
A.MySQL
B.Oracle
C.SqlServer
D.DB2#A#mysql.jpg 13 | 右图是以下哪个服务器的Logo?
A.JBoss
B.Oracle
C.Jetty
D.Tomcat#D#tomcat.jpg -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/dbfile/User.txt: -------------------------------------------------------------------------------- 1 | zhangsan-333 2 | lisi-444 3 | wangwu-555 -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/domain/User.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | //domain:实体对象 4 | //存储文件中的一行记录 5 | // 文件名-----------类名 6 | // 文件一行的记录-----类的对象 7 | // 文件一行中的值-----对象的属性对应 8 | public class User { 9 | 10 | private String account;//属性用来存储账号 11 | private String password;//属性用来存储密码 12 | 13 | public User(){} 14 | 15 | public User(String account, String password) { 16 | this.account = account; 17 | this.password = password; 18 | } 19 | 20 | public String getAccount() { 21 | return account; 22 | } 23 | 24 | public void setAccount(String account) { 25 | this.account = account; 26 | } 27 | 28 | public String getPassword() { 29 | return password; 30 | } 31 | 32 | public void setPassword(String password) { 33 | this.password = password; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/img/java.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_01/12:考试系统/src/img/java.jpg -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/img/mysql.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_01/12:考试系统/src/img/mysql.jpg -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/img/tomcat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_01/12:考试系统/src/img/tomcat.jpg -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/service/QuestionService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.QuestionDao; 4 | import domain.Question; 5 | import util.MySpring; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class QuestionService { 10 | 11 | QuestionDao dao = MySpring.getBean("dao.QuestionDao"); 12 | 13 | //获取试卷 14 | public ArrayList getPaper(int count){ 15 | return dao.getPaper(count); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/service/UserService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.UserDao; 4 | import domain.User; 5 | import util.MySpring; 6 | 7 | //Service业务层 8 | //负责处理读到的数据, 负责处理业务逻辑产生的新数据 9 | public class UserService { 10 | 11 | private UserDao dao = MySpring.getBean("dao.UserDao"); 12 | 13 | //登录 14 | public String login(String account, String password){ 15 | User user = dao.selectOne(account); 16 | String result = "登录成功"; 17 | if(user != null && user.getPassword().equals(password)){ 18 | 19 | }else{ 20 | result = "用户名或密码错误"; 21 | } 22 | return result; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/test/TestMain.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import view.LoginFrame; 4 | 5 | public class TestMain { 6 | public static void main(String[] args) { 7 | LoginFrame.getLoginFrame(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/util/BaseFrame.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import javax.swing.*; 4 | 5 | public abstract class BaseFrame extends JFrame { 6 | //模板模式 7 | //设计一个规则 任何窗口想要画出来 执行流程固定 8 | 9 | public BaseFrame(){} 10 | public BaseFrame(String title){ 11 | super(title); 12 | } 13 | 14 | protected void init(){ 15 | this.setFontAndSoOn(); 16 | this.addElement(); 17 | this.addListener(); 18 | this.setFrameSelf(); 19 | } 20 | 21 | //1.设置 字体 颜色 背景 布局等等 22 | protected abstract void setFontAndSoOn(); 23 | //2.将属性添加到窗体里 24 | protected abstract void addElement(); 25 | //3.添加事件监听 26 | protected abstract void addListener(); 27 | //4.设置窗体自身 28 | protected abstract void setFrameSelf(); 29 | } 30 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/util/MySpring.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.HashMap; 4 | 5 | public class MySpring { 6 | 7 | public static HashMap beanBox = new HashMap<>(); 8 | 9 | public static T getBean(String className){//类全名 10 | T obj = (T)beanBox.get(className); 11 | try { 12 | if(obj == null){ 13 | Class c = Class.forName(className); 14 | obj = (T) c.getDeclaredConstructor().newInstance(); 15 | beanBox.put(className,obj); 16 | } 17 | } catch (Exception e) { 18 | e.printStackTrace(); 19 | } 20 | return obj; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /【00】demos_01/12:考试系统/src/util/UserFileReader.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import domain.User; 4 | import java.io.BufferedReader; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.HashMap; 8 | 9 | //类的目的是为了增加一个缓存机制 10 | //程序启动的时候将User.txt文件中的所有信息 一次性读出来 11 | //以后做查询直接读取缓存中的数据 提高读取的性能 12 | public class UserFileReader { 13 | 14 | //缓存 15 | private static HashMap userBox = new HashMap<>(); 16 | 17 | //从缓存中获取用户信息 18 | public static User getUser(String account){ 19 | return userBox.get(account); 20 | } 21 | 22 | //在当前类加载的时候先执行 23 | static { 24 | BufferedReader br = null; 25 | try { 26 | br = new BufferedReader(new FileReader("src\\dbfile\\User.txt")); 27 | String value = br.readLine(); 28 | while (value != null){ 29 | String[] userValue = value.split("-"); 30 | User user = new User(userValue[0],userValue[1]); 31 | userBox.put(user.getAccount(),user); 32 | value = br.readLine(); 33 | } 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } finally { 37 | try { 38 | if(br != null){ 39 | br.close(); 40 | } 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/04:JDBC.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/01:JDBC/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/domain/Area.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Area { 4 | 5 | private Integer aid; 6 | private String aname; 7 | private Country country;//外键----关联Country国家表格的对象 8 | 9 | public Area() { 10 | } 11 | 12 | public Area(Integer aid, String aname, Country country) { 13 | this.aid = aid; 14 | this.aname = aname; 15 | this.country = country; 16 | } 17 | 18 | public Integer getAid() { 19 | return aid; 20 | } 21 | 22 | public void setAid(Integer aid) { 23 | this.aid = aid; 24 | } 25 | 26 | public String getAname() { 27 | return aname; 28 | } 29 | 30 | public void setAname(String aname) { 31 | this.aname = aname; 32 | } 33 | 34 | public Country getCountry() { 35 | return country; 36 | } 37 | 38 | public void setCountry(Country country) { 39 | this.country = country; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/domain/City.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class City { 4 | 5 | private Integer cityid; 6 | private String cityname; 7 | private Integer citysize; 8 | private Area area;//外键----关联Area地区表格的对象 9 | 10 | public City() { 11 | } 12 | 13 | public City(Integer cityid, String cityname, Integer citysize, Area area) { 14 | this.cityid = cityid; 15 | this.cityname = cityname; 16 | this.citysize = citysize; 17 | this.area = area; 18 | } 19 | 20 | public Integer getCityid() { 21 | return cityid; 22 | } 23 | 24 | public void setCityid(Integer cityid) { 25 | this.cityid = cityid; 26 | } 27 | 28 | public String getCityname() { 29 | return cityname; 30 | } 31 | 32 | public void setCityname(String cityname) { 33 | this.cityname = cityname; 34 | } 35 | 36 | public Integer getCitysize() { 37 | return citysize; 38 | } 39 | 40 | public void setCitysize(Integer citysize) { 41 | this.citysize = citysize; 42 | } 43 | 44 | public Area getArea() { 45 | return area; 46 | } 47 | 48 | public void setArea(Area area) { 49 | this.area = area; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/domain/Country.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Country { 4 | 5 | private Integer cid; 6 | private String cname; 7 | 8 | public Country() { 9 | } 10 | 11 | public Country(Integer cid, String cname) { 12 | this.cid = cid; 13 | this.cname = cname; 14 | } 15 | 16 | public Integer getCid() { 17 | return cid; 18 | } 19 | 20 | public void setCid(Integer cid) { 21 | this.cid = cid; 22 | } 23 | 24 | public String getCname() { 25 | return cname; 26 | } 27 | 28 | public void setCname(String cname) { 29 | this.cname = cname; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/service/AreaService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.AreaDao; 4 | import domain.Area; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | public class AreaService { 10 | 11 | AreaDao dao = new AreaDao(); 12 | 13 | public ArrayList select1(int begin, int end){ 14 | return dao.select1(begin, end); 15 | } 16 | 17 | public ArrayList> select3(){ 18 | return dao.select3(); 19 | } 20 | 21 | public ArrayList> select5(){ 22 | return dao.select5(); 23 | } 24 | 25 | public ArrayList> select10(){ 26 | return dao.select10(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/service/CityService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.CityDao; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class CityService { 8 | 9 | CityDao dao = new CityDao(); 10 | 11 | public ArrayList select6(String countryName){ 12 | return dao.select6(countryName); 13 | } 14 | 15 | public ArrayList select12(String cityName){ 16 | return dao.select12(cityName); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/service/CountryService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.CountryDao; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class CountryService { 9 | 10 | CountryDao dao = new CountryDao(); 11 | 12 | public ArrayList> select2(){ 13 | return dao.select2(); 14 | } 15 | 16 | public ArrayList select4(String cityName){ 17 | return dao.select4(cityName); 18 | } 19 | 20 | public String select7(){ 21 | return dao.select7(); 22 | } 23 | 24 | public ArrayList> select8(){ 25 | return dao.select8(); 26 | } 27 | 28 | public ArrayList select9(int size){ 29 | return dao.select9(size); 30 | } 31 | 32 | public ArrayList select11(int size){ 33 | return dao.select11(size); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Eight.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class Eight { 9 | public static void main(String[] args) { 10 | CountryService service = new CountryService(); 11 | ArrayList> list = service.select8(); 12 | for(HashMap map:list){ 13 | System.out.println(map.get("cname") + "----" + map.get("sum")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Eleven.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class Eleven { 8 | public static void main(String[] args) { 9 | CountryService service = new CountryService(); 10 | ArrayList list = service.select11(5000); 11 | for (String value:list){ 12 | System.out.println(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Five.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.AreaService; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class Five { 9 | public static void main(String[] args) { 10 | AreaService service = new AreaService(); 11 | ArrayList> list = service.select5(); 12 | for(HashMap map:list){ 13 | System.out.println(map.get("aname") + "----" + map.get("sum")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Four.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class Four { 8 | public static void main(String[] args) { 9 | CountryService service = new CountryService(); 10 | ArrayList list = service.select4("哈尔滨"); 11 | for (String value:list){ 12 | System.out.println(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Nine.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class Nine { 8 | public static void main(String[] args) { 9 | CountryService service = new CountryService(); 10 | ArrayList list = service.select9(1500); 11 | for (String value:list){ 12 | System.out.println(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/One.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.AreaService; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class One { 8 | public static void main(String[] args) { 9 | AreaService service = new AreaService(); 10 | ArrayList list = service.select1(1000, 2000); 11 | for (String value:list){ 12 | System.out.println(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Seven.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | public class Seven { 6 | public static void main(String[] args) { 7 | CountryService service = new CountryService(); 8 | String value = service.select7(); 9 | System.out.println(value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Six.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.AreaService; 4 | import service.CityService; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class Six { 9 | public static void main(String[] args) { 10 | CityService service = new CityService(); 11 | ArrayList list = service.select6("美国"); 12 | for (String value:list){ 13 | System.out.println(value); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Ten.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.AreaService; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class Ten { 9 | public static void main(String[] args) { 10 | AreaService service = new AreaService(); 11 | ArrayList> list = service.select10(); 12 | for(HashMap map:list){ 13 | System.out.println(map.get("aname") + "----" + map.get("sum")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Three.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.AreaService; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class Three { 9 | public static void main(String[] args) { 10 | AreaService service = new AreaService(); 11 | ArrayList> list = service.select3(); 12 | for(HashMap map:list){ 13 | System.out.println(map.get("aname") + "----" + map.get("avg")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Twelve.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CityService; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class Twelve { 8 | public static void main(String[] args) { 9 | CityService service = new CityService(); 10 | ArrayList list = service.select12("杭州"); 11 | for(String value:list){ 12 | System.out.println(value); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_02/01:JDBC/src/test/Two.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import service.CountryService; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | public class Two { 9 | public static void main(String[] args) { 10 | CountryService service = new CountryService(); 11 | ArrayList> list = service.select2(); 12 | for (HashMap map:list){ 13 | System.out.println(map.get("cname") + "----" + map.get("citycount")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/02:银行系统(JDBC).iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/02:银行系统(JDBC)/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_02/02:银行系统(JDBC)/src/domain/Atm.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Atm { 4 | //domain实体 只是为了存储表格中的数据 5 | //类 表 6 | //对象 行 7 | //属性 列 8 | //类型 类型 9 | 10 | private String aname; 11 | private String apassword; 12 | private Float abalance; 13 | 14 | public Atm() {} 15 | 16 | public Atm(String aname, String apassword, Float abalance) { 17 | this.aname = aname; 18 | this.apassword = apassword; 19 | this.abalance = abalance; 20 | } 21 | 22 | public String getAname() { 23 | return aname; 24 | } 25 | public void setAname(String aname) { 26 | this.aname = aname; 27 | } 28 | public String getApassword() { 29 | return apassword; 30 | } 31 | public void setApassword(String apassword) { 32 | this.apassword = apassword; 33 | } 34 | public Float getAbalance() { 35 | return abalance; 36 | } 37 | public void setAbalance(Float abalance) { 38 | this.abalance = abalance; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306/atm?serverTimezone=CST 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/02:银行系统.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/img/MySQL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/03:银行系统(JDBC+Swing)/img/MySQL.png -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/03:银行系统(JDBC+Swing)/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/src/domain/Atm.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Atm { 4 | //实体对象 每一个Atm类的对象存储 Atm表格中一行记录 5 | //有可能当前记录中含有null值 6 | 7 | private String aname; 8 | private String apassword; 9 | private Float abalance; 10 | 11 | public Atm() { 12 | } 13 | 14 | public Atm(String aname, String apassword, Float abalance) { 15 | this.aname = aname; 16 | this.apassword = apassword; 17 | this.abalance = abalance; 18 | } 19 | 20 | public String getAname() { 21 | return aname; 22 | } 23 | 24 | public void setAname(String aname) { 25 | this.aname = aname; 26 | } 27 | 28 | public String getApassword() { 29 | return apassword; 30 | } 31 | 32 | public void setApassword(String apassword) { 33 | this.apassword = apassword; 34 | } 35 | 36 | public Float getAbalance() { 37 | return abalance; 38 | } 39 | 40 | public void setAbalance(Float abalance) { 41 | this.abalance = abalance; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/src/test/TestMain.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import view.LoginFrame; 4 | 5 | public class TestMain { 6 | 7 | public static void main(String[] args){ 8 | LoginFrame.getLoginFrame(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/src/util/BaseFrame.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | public abstract class BaseFrame extends JFrame { 7 | //模板模式 8 | 9 | public BaseFrame(){} 10 | public BaseFrame(String title){ 11 | super(title); 12 | } 13 | 14 | //设计一个具体方法 规定加载窗体时的执行顺序 15 | protected void init(){ 16 | this.setFontAndSoOn(); 17 | this.addElements(); 18 | this.addListener(); 19 | this.setFrameSelf(); 20 | } 21 | 22 | //设计一个通用的画图方法 给我图片的路径及宽高 23 | protected ImageIcon drawImage(String path,int width,int height){ 24 | //通过给定的路径创建一个icon对象 25 | ImageIcon imageIcon = new ImageIcon(path); 26 | //设置icon对象内的image对象信息 27 | imageIcon.setImage(imageIcon.getImage().getScaledInstance(width,height, Image.SCALE_DEFAULT)); 28 | //将icon对象返回 29 | return imageIcon; 30 | } 31 | 32 | //1.用来设置 字体 颜色 背景 布局管理 等等 33 | protected abstract void setFontAndSoOn(); 34 | //2.用来添加所有的组件 35 | protected abstract void addElements(); 36 | //3.添加事件监听器 37 | protected abstract void addListener(); 38 | //4.设置窗体自身的属性 39 | protected abstract void setFrameSelf(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /【00】demos_02/03:银行系统(JDBC+Swing)/src/util/MySpring.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.HashMap; 4 | 5 | //目的是为了管理对象的产生 6 | //对象的控制权交给当前类来负责 IOC控制反转 7 | //生命周期托管的方式实现对对象的单例管理 8 | public class MySpring { 9 | 10 | //属性 为了存储所有被管理的对象 11 | private static HashMap beanBox = new HashMap<>(); 12 | 13 | //设计一个方法 获取任何一个类的对象(类含有无参数构造方法) 14 | // 参数String 类全名 返回值(某一个类的对象) 泛型 15 | public static T getBean(String className){ 16 | T obj = null; 17 | try { 18 | //1.直接从beanBox集合中获取 19 | obj = (T)beanBox.get(className); 20 | //2.如果obj是null 证明之前没有创建过对象 21 | if(obj == null){ 22 | //3.通过类名字获取Class 23 | Class clazz = Class.forName(className); 24 | //4.通过反射创建一个对象 25 | obj = (T) clazz.getDeclaredConstructor().newInstance(); 26 | //5.将新的对象存入集合 27 | beanBox.put(className,obj); 28 | } 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return obj; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/04:JDBC连接池 + ORM框架.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/04:JDBC连接池 + ORM框架/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/dbconfig.properties: -------------------------------------------------------------------------------- 1 | driver=com.mysql.cj.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/study?serverTimezone=CST 3 | user=root 4 | password=root 5 | minPoolSize=5 6 | maxPoolSize=10 7 | waitTime=5 -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/domain/Student.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | import java.sql.Date; 4 | 5 | public class Student { 6 | 7 | private Integer id; 8 | private String name; 9 | private String sex; 10 | private Integer birth; 11 | private Date ctime; 12 | 13 | public Student() { 14 | } 15 | 16 | public Student(Integer id, String name, String sex, Integer birth, Date ctime) { 17 | this.id = id; 18 | this.name = name; 19 | this.sex = sex; 20 | this.birth = birth; 21 | this.ctime = ctime; 22 | } 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getSex() { 41 | return sex; 42 | } 43 | 44 | public void setSex(String sex) { 45 | this.sex = sex; 46 | } 47 | 48 | public Integer getBirth() { 49 | return birth; 50 | } 51 | 52 | public void setBirth(Integer birth) { 53 | this.birth = birth; 54 | } 55 | 56 | public Date getCtime() { 57 | return ctime; 58 | } 59 | 60 | public void setCtime(Date ctime) { 61 | this.ctime = ctime; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/RowMapper.java: -------------------------------------------------------------------------------- 1 | package orm; 2 | 3 | import java.sql.ResultSet; 4 | 5 | //方案一[模拟SpringJDBC] 6 | public interface RowMapper { 7 | 8 | //策略模式 9 | //为单条查询定义规则, 将查询完毕的结果集转变为domain对象 10 | 11 | public Object mapperRow(ResultSet rs); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/SQLAndKey.java: -------------------------------------------------------------------------------- 1 | package orm; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //方案二[模拟MyBatis] 7 | public class SQLAndKey { 8 | 9 | //存储解析"特殊SQL"后的信息 10 | private List keyList = new ArrayList<>(); 11 | private StringBuilder sql = new StringBuilder(); 12 | 13 | public SQLAndKey(ArrayList keyList, StringBuilder sql) { 14 | this.keyList = keyList; 15 | this.sql = sql; 16 | } 17 | 18 | public List getKeyList() { 19 | return keyList; 20 | } 21 | 22 | public String getSql() { 23 | return sql.toString(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/annotation/Delete.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Delete { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/annotation/Insert.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Insert { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/annotation/Select.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Select { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/orm/annotation/Update.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Update { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/ormdao/StudentDao.java: -------------------------------------------------------------------------------- 1 | package ormdao; 2 | 3 | import domain.Student; 4 | import orm.annotation.Delete; 5 | import orm.annotation.Insert; 6 | import orm.annotation.Select; 7 | import orm.annotation.Update; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | //方案二[模拟MyBatis] 13 | //使用注解与动态代理模式, 使dao层变成接口 14 | public interface StudentDao { 15 | 16 | @Insert("insert into student values(#{id},#{name},#{sex},#{birth},#{ctime});") 17 | public int insert(Student student); 18 | 19 | @Insert("insert into student values(#{id},#{name},#{sex},#{birth},#{ctime});") 20 | public int insert(Map map); 21 | 22 | @Delete("delete from student where id = #{id};") 23 | public int delete(int id); 24 | 25 | @Update("update student set name=#{name},sex=#{sex},birth=#{birth},ctime=#{ctime} where id=#{id};") 26 | public int update(Student student); 27 | 28 | @Select("select * from student where id = #{id}") 29 | public Student selectOne(int id); 30 | 31 | @Select("select * from student") 32 | public List selectList(); 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/pool/ConnectionPoolBusyException.java: -------------------------------------------------------------------------------- 1 | package pool; 2 | 3 | public class ConnectionPoolBusyException extends RuntimeException{ 4 | 5 | public ConnectionPoolBusyException(){} 6 | 7 | public ConnectionPoolBusyException(String message){ 8 | super(message); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/pool/DBConfig.java: -------------------------------------------------------------------------------- 1 | package pool; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Enumeration; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Properties; 9 | 10 | /** 11 | * 读取 dbconfig.properties 配置文件 12 | * 项目启动时, 读取一遍即可 13 | * 使用缓存 14 | */ 15 | public class DBConfig { 16 | 17 | //缓存 18 | private static Map map = new HashMap<>(); 19 | 20 | //类加载时, 读取文件内容存入缓存 21 | static { 22 | try { 23 | Properties pro = new Properties();//本质上是一个集合, 读取文件数据像IO 24 | InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("dbconfig.properties"); 25 | pro.load(in); 26 | Enumeration en = pro.propertyNames(); 27 | while (en.hasMoreElements()){ 28 | String key = (String) en.nextElement(); 29 | String value = pro.getProperty(key); 30 | map.put(key,value); 31 | } 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | public static String getStringValue(String key){ 38 | return map.get(key); 39 | } 40 | 41 | public static Integer getIntegerValue(String key){ 42 | return Integer.parseInt(map.get(key)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import domain.Student; 4 | import orm.SqlSessionFactory; 5 | import ormdao.StudentDao; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class StudentService { 11 | 12 | private StudentService(){}; 13 | private static StudentService servide; 14 | public static StudentService getInstance(){ 15 | if (servide == null){ 16 | servide = new StudentService(); 17 | } 18 | return servide; 19 | } 20 | 21 | private StudentDao dao = SqlSessionFactory.getInstance().getMapper(StudentDao.class);//代理对象 22 | 23 | public int update(Student student) { 24 | return dao.update(student); 25 | } 26 | // 27 | // public int update(Map map) { 28 | // return dao.update(map); 29 | // } 30 | // 31 | public int delete(int id) { 32 | return dao.delete(id); 33 | } 34 | 35 | public long insert(Student student) { 36 | return dao.insert(student); 37 | } 38 | 39 | public long insert(Map map) { 40 | return dao.insert(map); 41 | } 42 | 43 | public Student selectOne(int id){ 44 | return dao.selectOne(id); 45 | } 46 | 47 | public List selectList(){ 48 | return dao.selectList(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /【00】demos_02/04:JDBC连接池 + ORM框架/src/test/TestJDBC.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | 8 | @SuppressWarnings("all") 9 | public class TestJDBC { 10 | 11 | public static void main(String[] args) { 12 | //============ 以下纯粹的JDBC操作的效率 ============ 13 | 14 | try { 15 | long t1 = System.currentTimeMillis(); 16 | 17 | //1.获取连接 18 | Class.forName("com.mysql.cj.jdbc.Driver"); 19 | Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/study?serverTimezone=CST","root","root"); 20 | 21 | long t2 = System.currentTimeMillis(); 22 | 23 | //2.创建状态参数 24 | PreparedStatement pstat = conn.prepareStatement("select * from student"); 25 | //3.执行就可以啦 26 | ResultSet rs = pstat.executeQuery(); 27 | while(rs.next()){ 28 | System.out.println(rs.getString("name") + " - " + rs.getString("sex")); 29 | } 30 | 31 | long t3 = System.currentTimeMillis(); 32 | 33 | System.out.println(t2 - t1);//580 34 | System.out.println(t3 - t2);//48 35 | 36 | rs.close(); 37 | pstat.close(); 38 | conn.close(); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/04:银行系统(Swing+JDBC连接池+ORM框架).iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/dao/AtmDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import domain.Atm; 4 | import orm.annotation.Delete; 5 | import orm.annotation.Insert; 6 | import orm.annotation.Select; 7 | import orm.annotation.Update; 8 | 9 | public interface AtmDao { 10 | 11 | @Insert("INSERT INTO ATM VALUES(#{aname},#{apassword},#{abalance});") 12 | public int insert(Atm atm); 13 | 14 | @Delete("delete from atm where aname = #{aname};") 15 | public int delete(String name); 16 | 17 | @Update("update atm set apassword=#{apassword},abalance=#{abalance} where aname=#{aname};") 18 | public int update(Atm atm); 19 | 20 | @Select("select * from atm where aname = #{aname}") 21 | public Atm selectOne(String aname); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/dbconfig.properties: -------------------------------------------------------------------------------- 1 | driver=com.mysql.cj.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/atm?serverTimezone=CST 3 | user=root 4 | password=root 5 | minPoolSize=5 6 | maxPoolSize=10 7 | waitTime=5 -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/domain/Atm.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Atm { 4 | //实体对象 每一个Atm类的对象存储 Atm表格中一行记录 5 | //有可能当前记录中含有null值 6 | 7 | private String aname; 8 | private String apassword; 9 | private Float abalance; 10 | 11 | public Atm() { 12 | } 13 | 14 | public Atm(String aname, String apassword, Float abalance) { 15 | this.aname = aname; 16 | this.apassword = apassword; 17 | this.abalance = abalance; 18 | } 19 | 20 | public String getAname() { 21 | return aname; 22 | } 23 | 24 | public void setAname(String aname) { 25 | this.aname = aname; 26 | } 27 | 28 | public String getApassword() { 29 | return apassword; 30 | } 31 | 32 | public void setApassword(String apassword) { 33 | this.apassword = apassword; 34 | } 35 | 36 | public Float getAbalance() { 37 | return abalance; 38 | } 39 | 40 | public void setAbalance(Float abalance) { 41 | this.abalance = abalance; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/orm/SQLAndKey.java: -------------------------------------------------------------------------------- 1 | package orm; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | //方案二[模拟MyBatis] 7 | public class SQLAndKey { 8 | 9 | //存储解析"特殊SQL"后的信息 10 | private List keyList = new ArrayList<>(); 11 | private StringBuilder sql = new StringBuilder(); 12 | 13 | public SQLAndKey(ArrayList keyList, StringBuilder sql) { 14 | this.keyList = keyList; 15 | this.sql = sql; 16 | } 17 | 18 | public List getKeyList() { 19 | return keyList; 20 | } 21 | 22 | public String getSql() { 23 | return sql.toString(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/orm/annotation/Delete.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Delete { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/orm/annotation/Insert.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Insert { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/orm/annotation/Select.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Select { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/orm/annotation/Update.java: -------------------------------------------------------------------------------- 1 | package orm.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Update { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/pool/ConnectionPoolBusyException.java: -------------------------------------------------------------------------------- 1 | package pool; 2 | 3 | public class ConnectionPoolBusyException extends RuntimeException{ 4 | 5 | public ConnectionPoolBusyException(){} 6 | 7 | public ConnectionPoolBusyException(String message){ 8 | super(message); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/pool/DBConfig.java: -------------------------------------------------------------------------------- 1 | package pool; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Enumeration; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.Properties; 9 | 10 | /** 11 | * 读取 dbconfig.properties 配置文件 12 | * 项目启动时, 读取一遍即可 13 | * 使用缓存 14 | */ 15 | public class DBConfig { 16 | 17 | //缓存 18 | private static Map map = new HashMap<>(); 19 | 20 | //类加载时, 读取文件内容存入缓存 21 | static { 22 | try { 23 | Properties pro = new Properties();//本质上是一个集合, 读取文件数据像IO 24 | InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("dbconfig.properties"); 25 | pro.load(in); 26 | Enumeration en = pro.propertyNames(); 27 | while (en.hasMoreElements()){ 28 | String key = (String) en.nextElement(); 29 | String value = pro.getProperty(key); 30 | map.put(key,value); 31 | } 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | public static String getStringValue(String key){ 38 | return map.get(key); 39 | } 40 | 41 | public static Integer getIntegerValue(String key){ 42 | return Integer.parseInt(map.get(key)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/test/TestMain.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import view.LoginFrame; 4 | 5 | public class TestMain { 6 | 7 | public static void main(String[] args){ 8 | LoginFrame.getLoginFrame(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/util/BaseFrame.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | public abstract class BaseFrame extends JFrame { 7 | //模板模式 8 | 9 | public BaseFrame(){} 10 | public BaseFrame(String title){ 11 | super(title); 12 | } 13 | 14 | //设计一个具体方法 规定加载窗体时的执行顺序 15 | protected void init(){ 16 | this.setFontAndSoOn(); 17 | this.addElements(); 18 | this.addListener(); 19 | this.setFrameSelf(); 20 | } 21 | 22 | //设计一个通用的画图方法 给我图片的路径及宽高 23 | protected ImageIcon drawImage(String path,int width,int height){ 24 | //通过给定的路径创建一个icon对象 25 | ImageIcon imageIcon = new ImageIcon(path); 26 | //设置icon对象内的image对象信息 27 | imageIcon.setImage(imageIcon.getImage().getScaledInstance(width,height, Image.SCALE_DEFAULT)); 28 | //将icon对象返回 29 | return imageIcon; 30 | } 31 | 32 | //1.用来设置 字体 颜色 背景 布局管理 等等 33 | protected abstract void setFontAndSoOn(); 34 | //2.用来添加所有的组件 35 | protected abstract void addElements(); 36 | //3.添加事件监听器 37 | protected abstract void addListener(); 38 | //4.设置窗体自身的属性 39 | protected abstract void setFrameSelf(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /【00】demos_02/04:银行系统(Swing+JDBC连接池+ORM框架)/src/util/MySpring.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.HashMap; 4 | 5 | //目的是为了管理对象的产生 6 | //对象的控制权交给当前类来负责 IOC控制反转 7 | //生命周期托管的方式实现对对象的单例管理 8 | public class MySpring { 9 | 10 | //属性 为了存储所有被管理的对象 11 | private static HashMap beanBox = new HashMap<>(); 12 | 13 | //设计一个方法 获取任何一个类的对象(类含有无参数构造方法) 14 | // 参数String 类全名 返回值(某一个类的对象) 泛型 15 | public static T getBean(String className){ 16 | T obj = null; 17 | try { 18 | //1.直接从beanBox集合中获取 19 | obj = (T)beanBox.get(className); 20 | //2.如果obj是null 证明之前没有创建过对象 21 | if(obj == null){ 22 | //3.通过类名字获取Class 23 | Class clazz = Class.forName(className); 24 | //4.通过反射创建一个对象 25 | obj = (T) clazz.getDeclaredConstructor().newInstance(); 26 | //5.将新的对象存入集合 27 | beanBox.put(className,obj); 28 | } 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return obj; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/Browser.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Browser/src/TestMain.java: -------------------------------------------------------------------------------- 1 | public class TestMain { 2 | public static void main(String[] args) { 3 | new Browser().openBrowser(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/Server.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import server.HttpServlet; 4 | import server.HttpServletRequest; 5 | import server.HttpServletResponse; 6 | 7 | public class IndexController extends HttpServlet { 8 | 9 | public void service(HttpServletRequest request, HttpServletResponse response){ 10 | //1.获取请求发送过来携带的参数 11 | //2.找到某一个业务层的方法做事 12 | //3.将最终业务层执行完毕的结果,交还给服务器,让服务器写回给浏览器 13 | 14 | response.sendRedirect("index.view"); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import server.HttpServlet; 4 | import server.HttpServletRequest; 5 | import server.HttpServletResponse; 6 | 7 | public class LoginController extends HttpServlet { 8 | 9 | @Override 10 | public void service(HttpServletRequest request, HttpServletResponse response) { 11 | String name = request.getParameter("name"); 12 | String password = request.getParameter("password"); 13 | 14 | System.out.println(name + "---" + password); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server.properties: -------------------------------------------------------------------------------- 1 | port=8888 -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server/HttpServlet.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | //出现的目的是为了定义一个规则 4 | // 方法名字必须统一,service,服务器找寻的时候就方便了 5 | // 方法参数必须统一,request,response 6 | public abstract class HttpServlet { 7 | 8 | public abstract void service(HttpServletRequest request,HttpServletResponse response); 9 | 10 | } -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server/HttpServletRequest.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.util.HashMap; 4 | 5 | public class HttpServletRequest { 6 | 7 | private String content; 8 | private HashMap paramsMap; 9 | 10 | public HttpServletRequest(){} 11 | public HttpServletRequest(String content, HashMap paramsMap) { 12 | this.content = content; 13 | this.paramsMap = paramsMap; 14 | } 15 | 16 | public String getParameter(String key){ 17 | return this.paramsMap.get(key); 18 | } 19 | 20 | public String getContent() { 21 | return content; 22 | } 23 | 24 | public void setContent(String content) { 25 | this.content = content; 26 | } 27 | 28 | public void setParamsMap(HashMap paramsMap) { 29 | this.paramsMap = paramsMap; 30 | } 31 | } -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server/HttpServletResponse.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | 7 | //自己创建的一个对象 8 | //存储响应信息 9 | public class HttpServletResponse { 10 | 11 | private StringBuilder responseContent = new StringBuilder(); 12 | 13 | //直接添加相应信息 14 | public void write(String str){ 15 | this.responseContent.append(str); 16 | } 17 | 18 | //读取文件(文件内容是响应信息) 19 | public void sendRedirect(String path){ 20 | try { 21 | File file = new File("src//view//" + path); 22 | BufferedReader reader = new BufferedReader(new FileReader(file)); 23 | String value = reader.readLine(); 24 | while(value != null){ 25 | this.responseContent.append(value); 26 | value = reader.readLine(); 27 | } 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | public String getResponseContent(){ 34 | return this.responseContent.toString(); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server/Server.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.io.IOException; 4 | import java.net.ServerSocket; 5 | import java.net.Socket; 6 | 7 | public class Server { 8 | 9 | public void startServer(){ 10 | System.out.println("====启动服务器===="); 11 | try { 12 | //获取配置文件server.properties中的port 13 | int port = Integer.parseInt(ServerFileReader.getValue("port")); 14 | ServerSocket server = new ServerSocket(port); 15 | while(true){ 16 | Socket socket = server.accept(); 17 | new ServerHandler(socket).start(); 18 | } 19 | 20 | } catch (IOException e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/server/ServerFileReader.java: -------------------------------------------------------------------------------- 1 | package server; 2 | 3 | import java.io.FileReader; 4 | import java.io.IOException; 5 | import java.util.Enumeration; 6 | import java.util.HashMap; 7 | import java.util.Properties; 8 | 9 | //类的目的是在服务器启动的时候 10 | //读取server.properties的配置文件----port 11 | public class ServerFileReader { 12 | 13 | private static HashMap map = new HashMap<>(); 14 | 15 | static{ 16 | try { 17 | Properties pro = new Properties(); 18 | pro.load(new FileReader("src//server.properties")); 19 | Enumeration en = pro.propertyNames(); 20 | while(en.hasMoreElements()){ 21 | String key = (String)en.nextElement(); 22 | String value = pro.getProperty(key); 23 | map.put(key,value); 24 | } 25 | } catch (IOException e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | 30 | public static String getValue(String key){ 31 | return map.get(key); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/test/TestMain.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import server.Server; 4 | 5 | public class TestMain { 6 | public static void main(String[] args) { 7 | new Server().startServer(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/view/index.view: -------------------------------------------------------------------------------- 1 | ***********************
2 | ********银行系统********
3 | ***********************
4 |
5 | 请输入账号
6 | 请输入密码
-------------------------------------------------------------------------------- /【00】demos_03/01:请求与响应/Server/src/web.properties: -------------------------------------------------------------------------------- 1 | index=controller.IndexController 2 | login=controller.LoginController -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/artifacts/02Tomcat_Servlet_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/02Tomcat_Servlet_war_exploded 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/02:银行系统(Tomcat+Servlet).iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/controller/DeleteController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import service.AtmService; 4 | import util.MySpring; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | 14 | public class DeleteController extends HttpServlet { 15 | 16 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 17 | 18 | request.setCharacterEncoding("UTF-8"); 19 | response.setCharacterEncoding("UTF-8"); 20 | 21 | String aname = (String) request.getSession().getAttribute("aname"); 22 | 23 | AtmService service = MySpring.getBean("service.AtmService"); 24 | service.deleteAccount(aname); 25 | //System.out.println("删除账号: " + aname); 26 | 27 | //回到首页 28 | RequestDispatcher rd = request.getRequestDispatcher("showGoodbye.jsp");//告知转发路径 29 | rd.forward(request, response);//转发给服务器 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/controller/DepositController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import service.AtmService; 4 | import util.MySpring; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | 14 | public class DepositController extends HttpServlet { 15 | 16 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 17 | 18 | request.setCharacterEncoding("UTF-8"); 19 | response.setCharacterEncoding("UTF-8"); 20 | 21 | String aname = (String) request.getSession().getAttribute("aname"); 22 | String depositBalance = request.getParameter("depositBalance"); 23 | //System.out.println("接收到了名字和存款金额:" + aname + "--" + depositBalance); 24 | 25 | //调用业务层的方法负责存钱 26 | AtmService service = MySpring.getBean("service.AtmService"); 27 | service.deposit(aname, Float.parseFloat(depositBalance)); 28 | 29 | //欢迎界面 30 | RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");//告知转发路径 31 | rd.forward(request, response);//转发给服务器 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/controller/QueryController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import service.AtmService; 4 | import util.MySpring; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.io.PrintWriter; 12 | 13 | public class QueryController extends HttpServlet { 14 | 15 | private AtmService service = MySpring.getBean("service.AtmService"); 16 | 17 | public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ 18 | 19 | request.setCharacterEncoding("UTF-8"); 20 | response.setCharacterEncoding("UTF-8"); 21 | 22 | String aname = (String) request.getSession().getAttribute("aname"); 23 | Float abalance = service.inquire(aname); 24 | //System.out.println(aname + "账号的余额为:" + abalance); 25 | 26 | request.setAttribute("abalance", abalance);//需要将 abalance 传给JSP文件 27 | request.getRequestDispatcher("showBalance.jsp").forward(request, response); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/controller/WithdrawController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import service.AtmService; 4 | import util.MySpring; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | 14 | public class WithdrawController extends HttpServlet { 15 | 16 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 17 | 18 | request.setCharacterEncoding("UTF-8"); 19 | response.setCharacterEncoding("UTF-8"); 20 | 21 | String aname = (String) request.getSession().getAttribute("aname"); 22 | String withdrawBalance = request.getParameter("withdrawBalance"); 23 | //System.out.println("接收到了名字和取款金额:" + aname + "--" + withdrawBalance); 24 | 25 | //调用业务层的方法负责存钱 26 | AtmService service = MySpring.getBean("service.AtmService"); 27 | service.withdraw(aname, Float.parseFloat(withdrawBalance)); 28 | 29 | //欢迎界面 30 | RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");//告知转发路径 31 | rd.forward(request, response);//转发给服务器 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/domain/Atm.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Atm { 4 | 5 | private String aname; 6 | private String apassword; 7 | private Float abalance; 8 | 9 | public Atm() {} 10 | 11 | public Atm(String aname, String apassword, Float abalance) { 12 | this.aname = aname; 13 | this.apassword = apassword; 14 | this.abalance = abalance; 15 | } 16 | 17 | public String getAname() { 18 | return aname; 19 | } 20 | public void setAname(String aname) { 21 | this.aname = aname; 22 | } 23 | public String getApassword() { 24 | return apassword; 25 | } 26 | public void setApassword(String apassword) { 27 | this.apassword = apassword; 28 | } 29 | public Float getAbalance() { 30 | return abalance; 31 | } 32 | public void setAbalance(Float abalance) { 33 | this.abalance = abalance; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/src/util/MySpring.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.HashMap; 4 | 5 | //目的是为了管理对象的产生 6 | //对象的控制权交给当前类来负责 IOC控制反转 7 | //生命周期托管的方式实现对对象的单例管理 8 | public class MySpring { 9 | 10 | //属性 为了存储所有被管理的对象 11 | private static HashMap beanBox = new HashMap<>(); 12 | 13 | //设计一个方法 获取任何一个类的对象(类含有无参数构造方法) 14 | // 参数String 类全名 返回值(某一个类的对象) 泛型 15 | public static T getBean(String className){ 16 | T obj = null; 17 | try { 18 | //1.直接从beanBox集合中获取 19 | obj = (T)beanBox.get(className); 20 | //2.如果obj是null 证明之前没有创建过对象 21 | if(obj == null){ 22 | //3.通过类名字获取Class 23 | Class clazz = Class.forName(className); 24 | //4.通过反射创建一个对象 25 | obj = (T) clazz.getDeclaredConstructor().newInstance(); 26 | //5.将新的对象存入集合 27 | beanBox.put(className,obj); 28 | } 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return obj; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/WEB-INF/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_03/02:银行系统(Tomcat+Servlet)/web/WEB-INF/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 已有帐户,点击登录

8 | 点击注册 9 | 10 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Login 6 | 7 | 8 | 9 | 请输入账号:
10 | 请输入密码:
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Register 6 | 7 | 8 |
9 | 请输入账号:
10 | 请输入密码:
11 | 请输入余额:
12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showBalance.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 13 | 14 | 15 | <% 16 | String aname = (String) session.getAttribute("aname"); 17 | Float abalance = (Float)request.getAttribute("abalance"); 18 | %> 19 | 尊敬的 <%=aname%> 用户,您的可用余额为: <%=abalance%>
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showDelete.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | showDelete 5 | 6 | 7 | 8 |
9 | 你确定要离我而去了吗?
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showDeposit.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | showDeposit 5 | 6 | 7 | 8 |
9 | 请输入存款金额:
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showGoodbye.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | showGoodbye 5 | 6 | 7 | 8 | <% 9 | String aname = (String) session.getAttribute("aname"); 10 | %> 11 | 12 | <%=aname%> 愿你我日后有缘再会.
13 | 首页 14 | 15 | <% 16 | session.removeAttribute("aname"); 17 | %> 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showTransfer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | showTransfer 5 | 6 | 7 | 8 |
9 | 请输入存款金额:
10 | 请输入转账用户名:
11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/showWithdraw.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | showWithdraw 5 | 6 | 7 | 8 |
9 | 请输入存款金额:
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /【00】demos_03/02:银行系统(Tomcat+Servlet)/web/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | Welcome 5 | 6 | 7 | 8 | <% 9 | String aname = (String) session.getAttribute("aname"); 10 | %> 11 | 12 | ****************************
13 | 欢迎 <%=aname%> 进入ATM系统
14 | ****************************
15 | 请输入操作选项
16 | 查询
17 | 存款
18 | 取款
19 | 转账
20 | 注销 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/artifacts/03Servlet_JSP_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/03Servlet_JSP_war_exploded 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/libraries/mysql_connector_java_8_0_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/03:购物系统(Servlet+JSP).iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import service.UserService; 4 | import util.MySpring; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | public class LoginController extends HttpServlet { 13 | 14 | private UserService service = MySpring.getBean("service.UserService"); 15 | 16 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 17 | 18 | //1.处理字符集 19 | request.setCharacterEncoding("UTF-8"); 20 | //2.接受请求发送过来的参数 21 | String uname = request.getParameter("uname"); 22 | String upassword = request.getParameter("upassword"); 23 | //3.调用业务层的方法执行操作 24 | String result = service.login(uname, upassword); 25 | //4.根据结果转发 26 | if(result.equals("登录成功")){ 27 | request.getSession().setAttribute("uname", uname); 28 | request.getRequestDispatcher("welcome.jsp").forward(request, response); 29 | }else{ 30 | request.setAttribute("result", result); 31 | request.getRequestDispatcher("index.jsp").forward(request, response); 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/controller/LogoutController.java: -------------------------------------------------------------------------------- 1 | package controller; 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 javax.servlet.http.HttpSession; 8 | import java.io.IOException; 9 | 10 | public class LogoutController extends HttpServlet { 11 | 12 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 13 | HttpSession session = request.getSession(); 14 | session.removeAttribute("uname"); 15 | session.removeAttribute("shoppingCar"); 16 | request.getRequestDispatcher("index.jsp").forward(request, response); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/controller/SelectAllKindController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import domain.Kind; 4 | import service.KindService; 5 | import util.MySpring; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | 14 | public class SelectAllKindController extends HttpServlet { 15 | 16 | private KindService service = MySpring.getBean("service.KindService"); 17 | 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 19 | //处理字符集 20 | //接受请求参数 21 | //调用一个业务层的方法去查询 22 | ArrayList kindList = service.selectAllKind(); 23 | //将查询到的结果带走 24 | request.setAttribute("kindList", kindList); 25 | //转发给JSP做拼接响应 26 | request.getRequestDispatcher("showAllKind.jsp").forward(request, response); 27 | } 28 | 29 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 30 | this.doGet(req, resp); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/controller/SelectCommodityController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import domain.Commodity; 4 | import service.CommodityService; 5 | import util.MySpring; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | 14 | public class SelectCommodityController extends HttpServlet { 15 | 16 | private CommodityService service = MySpring.getBean("service.CommodityService"); 17 | 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 19 | //1.处理字符集 kid 20 | //2.接收请求传递过来的参数 kid 21 | String kid = request.getParameter("kid"); 22 | //3.调用业务层的方法负责查询 23 | ArrayList commodityList = service.selectCommodityById(Integer.parseInt(kid)); 24 | //4.将查询完毕的商品集合带走 25 | request.setAttribute("commodityList", commodityList); 26 | //5.转发给一个JSP做最终响应拼接 27 | request.getRequestDispatcher("showCommodity.jsp").forward(request, response); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/domain/Kind.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Kind { 4 | 5 | private Integer kid; 6 | private String kname; 7 | 8 | public Kind() {} 9 | public Kind(Integer kid, String kname) { 10 | this.kid = kid; 11 | this.kname = kname; 12 | } 13 | 14 | public Integer getKid() { 15 | return kid; 16 | } 17 | public void setKid(Integer kid) { 18 | this.kid = kid; 19 | } 20 | public String getKname() { 21 | return kname; 22 | } 23 | public void setKname(String kname) { 24 | this.kname = kname; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/domain/User.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class User { 4 | 5 | private String uname; 6 | private String upassword; 7 | private Float ubalance; 8 | 9 | public User(){} 10 | 11 | public User(String uname, String upassword, Float ubalance) { 12 | this.uname = uname; 13 | this.upassword = upassword; 14 | this.ubalance = ubalance; 15 | } 16 | 17 | public String getUname() { 18 | return uname; 19 | } 20 | public void setUname(String uname) { 21 | this.uname = uname; 22 | } 23 | public String getUpassword() { 24 | return upassword; 25 | } 26 | public void setUpassword(String upassword) { 27 | this.upassword = upassword; 28 | } 29 | public Float getUbalance() { 30 | return ubalance; 31 | } 32 | public void setUbalance(Float ubalance) { 33 | this.ubalance = ubalance; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/service/CommodityService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.CommodityDao; 4 | import domain.Commodity; 5 | import util.MySpring; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class CommodityService { 10 | 11 | private CommodityDao dao = MySpring.getBean("dao.CommodityDao"); 12 | 13 | //根据种类编号kid 查询对应的所有具体商品 14 | public ArrayList selectCommodityById(int kid){ 15 | return dao.selectCommodityByKid(kid); 16 | } 17 | 18 | //根据商品的cid 查询对应的一条商品记录 19 | public Commodity selectOne(int cid){ 20 | return dao.selectOne(cid); 21 | } 22 | 23 | //修改一条记录 商品库存的改变 24 | public int updateCommodityCount(int cid, int ccount) { 25 | Commodity commodity = dao.selectOne(cid); 26 | commodity.setCcount(ccount); 27 | return dao.update(commodity); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/service/KindService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.KindDao; 4 | import domain.Kind; 5 | import util.MySpring; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class KindService { 10 | 11 | private KindDao dao = MySpring.getBean("dao.KindDao"); 12 | 13 | //业务方法 查询所有种类 返回ArrayList 14 | public ArrayList selectAllKind(){ 15 | return dao.selectAllKind(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/service/UserService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import dao.UserDao; 4 | import domain.User; 5 | import util.MySpring; 6 | 7 | public class UserService { 8 | 9 | private UserDao dao = MySpring.getBean("dao.UserDao"); 10 | 11 | //登录 12 | public String login(String uname,String upassword){ 13 | //查询真实的数据 14 | User user = dao.selectOne(uname); 15 | if (user != null && user.getUpassword().equals(upassword)) { 16 | return "登录成功"; 17 | } 18 | return "账号或密码错误"; 19 | } 20 | 21 | //注册 22 | public int regist(String uname, String upassword, Float ubalance){ 23 | if (dao.selectOne(uname) != null){ //用户名已存在 24 | return 2; 25 | } 26 | return dao.insert(new User(uname, upassword, ubalance)); 27 | } 28 | 29 | //查询用户余额 30 | public float selectBalance(String uname){ 31 | return dao.selectOne(uname).getUbalance(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/src/util/MySpring.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.util.HashMap; 4 | 5 | public class MySpring { 6 | 7 | private static HashMap beanMap = new HashMap<>(); 8 | 9 | public static synchronized T getBean(String className){ 10 | T obj = (T)beanMap.get(className); 11 | if(obj == null){ 12 | try { 13 | Class clazz = Class.forName(className); 14 | obj = (T)clazz.getDeclaredConstructor().newInstance(); 15 | beanMap.put(className,obj); 16 | } catch (Exception e) { 17 | e.printStackTrace(); 18 | } 19 | } 20 | return obj; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/WEB-INF/lib/mysql-connector-java-8.0.20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_03/03:购物系统(Servlet+JSP)/web/WEB-INF/lib/mysql-connector-java-8.0.20.jar -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 12 | 13 | 14 | 15 | ${requestScope.result} 16 | 17 |
18 | 账号:
19 | 密码:
20 |
21 | 22 |      23 | 24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/regist.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | Regist 5 | 13 | 14 | 15 | 16 | ${requestScope.result} 17 | 18 |
19 | 账号:
20 | 密码:
21 | 余额:
22 |
23 | 24 |      25 | 26 |
27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/showAllKind.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 23 | 24 | 25 | 26 | 登录用户: ${sessionScope.uname},     27 |

28 | 29 | 假的购物系统有商品种类如下,请下拉选择
30 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/showEndList.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 10 | 18 | 19 | 20 | 21 | 登录用户: ${sessionScope.uname},     22 |

23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
商品名称商品单价商品数量
${map.key.cname}${map.key.cprice}${map.value}
总计: ${requestScope.sumPrice} ${requestScope.result}
39 | 40 | ${sessionScope.remove("shoppingCar")} 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /【00】demos_03/03:购物系统(Servlet+JSP)/web/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 12 | 13 | 14 | 15 | 登录用户: ${sessionScope.uname},     16 |

17 | 18 | 欢迎进入假的购物系统,想买东西么?
19 | 如果想买,请继续点击 进入 购物系统 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/artifacts/04Web_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/04Web_war_exploded 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/04:Web框架.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/ApplicationContext.properties: -------------------------------------------------------------------------------- 1 | scanPackage=controller -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/controller/AtmController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import domain.Person; 4 | import mymvc.ModelAndView; 5 | import mymvc.RequestMapper; 6 | import mymvc.SessionAttributes; 7 | 8 | /** 9 | * 1.没有继承关系 降低类和类之间的耦合关系 10 | * 2.底层还保留了原有Controller的管理机制 (单例 懒加载) 11 | * 3.没有方法重写 方法名字随意 少了很多约束 使用更加灵活 12 | * 4.有了最终的转发或重定向 只使用一个简单的String作为返回值 13 | * 5.减少了方法的参数使用 request response 14 | * 6.方法的异常没有啦 15 | * 7.创建一个容器 ModelAndView 实现存值 16 | */ 17 | 18 | @RequestMapper("AtmController.do") 19 | @SessionAttributes("person") 20 | public class AtmController { 21 | 22 | //参数前注解值 == 请求携带的参数(如果有) 23 | public ModelAndView login(Person person) { 24 | 25 | //想要带走数据 26 | //还需要框架帮忙进行请求转发、重定向 27 | 28 | ModelAndView mv = new ModelAndView(); 29 | mv.setAttribute("person", person); 30 | mv.setViewName("redirect:welcome.jsp"); 31 | 32 | return mv; 33 | 34 | //处理转发与重定向 35 | //1.直接给予响应 response.getWriter().write("") 36 | // 返回值类型为void,或者返回“”、“null” 37 | //2.请求转发 => 交给框架 38 | // 直接返回 “资源名” 39 | //3.请求重定向 => 交给框架 40 | // 返回 “redirect:资源名” 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/domain/Person.java: -------------------------------------------------------------------------------- 1 | package domain; 2 | 3 | public class Person { 4 | 5 | private String name; 6 | private Integer pass; 7 | 8 | @Override 9 | public String toString() { 10 | return "Person{" + 11 | "name='" + name + '\'' + 12 | ", pass=" + pass + 13 | '}'; 14 | } 15 | 16 | public Person() { 17 | } 18 | 19 | public Person(String name, Integer pass) { 20 | this.name = name; 21 | this.pass = pass; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Integer getPass() { 33 | return pass; 34 | } 35 | 36 | public void setPass(Integer pass) { 37 | this.pass = pass; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/ControllerNotFoundException.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | public class ControllerNotFoundException extends RuntimeException { 4 | 5 | public ControllerNotFoundException(){ 6 | 7 | } 8 | 9 | public ControllerNotFoundException(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/MethodParamNoAnnoException.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | public class MethodParamNoAnnoException extends RuntimeException { 4 | 5 | public MethodParamNoAnnoException(){} 6 | 7 | public MethodParamNoAnnoException(String mess){ 8 | super(mess); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/ModelAndView.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * 存储Controller类想要带走的信息、请求转发或重定向信息 7 | */ 8 | public class ModelAndView { 9 | 10 | private String viewName;//路径资源名 11 | private HashMap attributeMap = new HashMap<>();//包装 request.setAttribute() 12 | 13 | //用户设置请求转发、重定向的路径资源名 14 | public void setViewName(String path) { 15 | viewName = path; 16 | } 17 | 18 | //用户存值 19 | public void setAttribute(String key, Object obj) { 20 | attributeMap.put(key, obj); 21 | } 22 | 23 | 24 | //框架获取请求转发、重定向路径资源名 25 | String getViewName() { 26 | return viewName; 27 | } 28 | 29 | //框架取值 30 | Object getAttribute(String key) { 31 | return attributeMap.get(key); 32 | } 33 | 34 | //框架获取集合 35 | HashMap getAttributeMap() { 36 | return attributeMap; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/Param.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.PARAMETER) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Param { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/RequestMapper.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface RequestMapper { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/src/mymvc/SessionAttributes.java: -------------------------------------------------------------------------------- 1 | package mymvc; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * session 使用频率远远小于 request 10 | * 所以使用注解存储 Controller 类要带走的 Session 值 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface SessionAttributes { 15 | 16 | String[] value(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/web/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | mymvc 10 | mymvc.DispatcherServlet 11 | 12 | 13 | mymvc 14 | *.do 15 | 16 | 17 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/web/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 测试1(Atm登录功能)
6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_03/04:Web框架/web/welcome.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | Title 4 | 5 | 6 | this is welcome page 7 | 8 | 9 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | 8 | target 9 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/.name: -------------------------------------------------------------------------------- 1 | ssm -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/01:ssm在线视频学习网站.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306/ssm4 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/google-java-format.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/saveactions_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/smartfox_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/.idea/webContexts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/controller/SearchController.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.controller; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.zgh.onlinevideo.domain.CourseTopic; 6 | import com.zgh.onlinevideo.service.CourseTopicService; 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.RequestMapping; 11 | 12 | @Controller 13 | public class SearchController { 14 | 15 | @Autowired 16 | CourseTopicService courseTopicService; 17 | 18 | @RequestMapping("/search") 19 | public String searchPage(Model model, String searchkey, Integer pageNum) { 20 | model.addAttribute("focusIndex", 2); //头页面聚焦 21 | 22 | if (pageNum == null || pageNum <= 1) { 23 | pageNum = 1; 24 | } 25 | 26 | // 课程主题(全部) 排列显示 27 | PageHelper.startPage(pageNum, 4); 28 | PageInfo searchTopicList = courseTopicService.searchTopicByTitle(searchkey); 29 | model.addAttribute("searchTopicList", searchTopicList); 30 | 31 | return "search"; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/BannerDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.Banner; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | @Repository 9 | public interface BannerDao { 10 | 11 | int insertBanner(Banner banner); 12 | 13 | List findBannerAll(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/CourseTopicDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.CourseTopic; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.HashMap; 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface CourseTopicDao { 11 | 12 | int insertCourseTopic(CourseTopic courseTopic); 13 | 14 | List findCourseTopicByCondition(HashMap map); 15 | 16 | List findCourseTopicByIds(List ids); 17 | 18 | int updateCourseTopic(HashMap map); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/CourseTypeDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.CourseType; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | @Repository 9 | public interface CourseTypeDao { 10 | 11 | int insertCourseType(CourseType courseType); 12 | 13 | List findCourseTypeAll(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/CourseVideoDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.CourseVideo; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.HashMap; 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface CourseVideoDao { 11 | 12 | int insertCourseVideo(CourseVideo courseVideo); 13 | 14 | List findCourseVideoByCondition(HashMap map); 15 | 16 | CourseVideo findCourseVideoByIds(List ids); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/ToolItemDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.ToolItem; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.HashMap; 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface ToolItemDao { 11 | 12 | int insertToolItem(ToolItem toolItem); 13 | 14 | List findToolItemByCondition(HashMap map); 15 | 16 | List findToolItemAll(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/ToolTypeDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.ToolType; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | @Repository 9 | public interface ToolTypeDao { 10 | 11 | int insertToolType(ToolType toolType); 12 | 13 | List findToolTypeAll(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dao; 2 | 3 | import com.zgh.onlinevideo.domain.User; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.HashMap; 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface UserDao { 11 | 12 | int insertUser(User user); 13 | 14 | User findUserByCondition(HashMap map); 15 | 16 | List findUserAll(); 17 | 18 | int updateUser(User user); 19 | 20 | User findUserByIds(List ids); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/dto/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.dto; 2 | 3 | /** 4 | * 页面返回的数据类型 5 | */ 6 | public class ResponseResult { 7 | 8 | // 响应码 9 | private int rcode; 10 | 11 | // 数据 12 | private T data; 13 | 14 | // 消息提示 15 | private String message; 16 | 17 | public ResponseResult() { 18 | } 19 | 20 | public ResponseResult(int rcode, T data, String message) { 21 | this.rcode = rcode; 22 | this.data = data; 23 | this.message = message; 24 | } 25 | 26 | public ResponseResult(int rcode, String message) { 27 | this.rcode = rcode; 28 | this.message = message; 29 | } 30 | 31 | public int getRcode() { 32 | return rcode; 33 | } 34 | 35 | public void setRcode(int rcode) { 36 | this.rcode = rcode; 37 | } 38 | 39 | public T getData() { 40 | return data; 41 | } 42 | 43 | public void setData(T data) { 44 | this.data = data; 45 | } 46 | 47 | public String getMessage() { 48 | return message; 49 | } 50 | 51 | public void setMessage(String message) { 52 | this.message = message; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/exception/PageException.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.exception; 2 | 3 | public class PageException extends RuntimeException { 4 | 5 | public PageException() { 6 | } 7 | 8 | public PageException(String message) { 9 | super(message); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/exception/UserException.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.exception; 2 | 3 | public class UserException extends RuntimeException { 4 | 5 | public UserException() { 6 | } 7 | 8 | public UserException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/exception/VideoExceptionResolver.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.exception; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.servlet.HandlerExceptionResolver; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * 在线视频 服务器统一异常处理 12 | */ 13 | @Component 14 | public class VideoExceptionResolver implements HandlerExceptionResolver { 15 | 16 | @Override 17 | public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) { 18 | 19 | ModelAndView mv = new ModelAndView(); 20 | 21 | mv.setViewName("error"); 22 | 23 | if (e instanceof UserException) { 24 | mv.addObject("flag", "用户逻辑错误"); 25 | } else if (e instanceof PageException) { 26 | mv.addObject("flag", "页面逻辑错误"); 27 | } 28 | mv.addObject("message", e.getMessage()); 29 | 30 | return mv; 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/interceptor/AutoLoginInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.interceptor; 2 | 3 | import com.zgh.onlinevideo.util.Constants; 4 | import com.zgh.onlinevideo.util.VideoUtil; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | 7 | import javax.servlet.ServletContext; 8 | import javax.servlet.http.Cookie; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | 13 | public class AutoLoginInterceptor implements HandlerInterceptor { 14 | 15 | @Override 16 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 17 | 18 | HttpSession session = request.getSession(true); 19 | Cookie[] cookies = request.getCookies(); 20 | ServletContext application = request.getServletContext(); 21 | 22 | boolean valid = VideoUtil.checkLoginToken(cookies, application); 23 | 24 | if (valid) { 25 | // token有效 恢复登录状态 26 | session.setAttribute(Constants.LOGIN_USER, VideoUtil.getUserByApplication(cookies, application)); 27 | } 28 | 29 | // 请求通过 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/BannerService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | 4 | import com.zgh.onlinevideo.domain.Banner; 5 | 6 | import java.util.List; 7 | 8 | public interface BannerService { 9 | 10 | List getIndexBanner(); 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/CourseTopicService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | 4 | import com.github.pagehelper.PageInfo; 5 | import com.zgh.onlinevideo.domain.CourseTopic; 6 | 7 | public interface CourseTopicService { 8 | 9 | PageInfo getIndexCourseTopic(int typeId); 10 | 11 | // 最新的那些课程主题 12 | PageInfo getIndexNewestTopic(); 13 | 14 | CourseTopic getCourseTopic(int topicId); 15 | 16 | // 课程专题浏览数+1 17 | void viewsAdd(int courseTopicId, int views); 18 | 19 | // 搜索课程专题 20 | PageInfo searchTopicByTitle(String title); 21 | } 22 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/CourseTypeService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | import com.zgh.onlinevideo.domain.CourseType; 4 | 5 | import java.util.List; 6 | 7 | public interface CourseTypeService { 8 | 9 | int insertCourseType(CourseType courseType); 10 | 11 | List getCourseTypeAll(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/CourseVideoService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | import com.zgh.onlinevideo.domain.CourseVideo; 4 | 5 | import java.util.List; 6 | 7 | public interface CourseVideoService { 8 | 9 | List getCourseVideoAll(int topicId); 10 | 11 | CourseVideo getCourseVideo(int vid); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/ToolItemService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.zgh.onlinevideo.domain.ToolItem; 5 | 6 | public interface ToolItemService { 7 | 8 | PageInfo getToolItem(int typeId); 9 | 10 | PageInfo getToolItemAll(); 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/ToolTypeService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | import com.zgh.onlinevideo.domain.ToolType; 4 | 5 | import java.util.List; 6 | 7 | public interface ToolTypeService { 8 | 9 | List getToolTypeAll(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.zgh.onlinevideo.domain.User; 5 | 6 | public interface UserService { 7 | 8 | User login(User user); 9 | 10 | int regist(User user); 11 | 12 | User existEmail(String email); 13 | 14 | PageInfo getUserList(); 15 | 16 | int delete(Integer uid); 17 | 18 | User getUser(int uid); 19 | 20 | int updateUser(User user); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/impl/BannerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service.impl; 2 | 3 | import com.zgh.onlinevideo.dao.BannerDao; 4 | import com.zgh.onlinevideo.domain.Banner; 5 | import com.zgh.onlinevideo.service.BannerService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class BannerServiceImpl implements BannerService { 13 | 14 | 15 | @Autowired 16 | BannerDao bannerDao; 17 | 18 | @Override 19 | public List getIndexBanner() { 20 | return bannerDao.findBannerAll(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/impl/CourseTypeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service.impl; 2 | 3 | import com.zgh.onlinevideo.dao.CourseTypeDao; 4 | import com.zgh.onlinevideo.domain.CourseType; 5 | import com.zgh.onlinevideo.service.CourseTypeService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class CourseTypeServiceImpl implements CourseTypeService { 13 | 14 | @Autowired 15 | CourseTypeDao courseTypeDao; 16 | 17 | public int insertCourseType(CourseType courseType) { 18 | return courseTypeDao.insertCourseType(courseType); 19 | } 20 | 21 | @Override 22 | public List getCourseTypeAll() { 23 | return courseTypeDao.findCourseTypeAll(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/impl/CourseVideoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service.impl; 2 | 3 | import com.zgh.onlinevideo.dao.CourseVideoDao; 4 | import com.zgh.onlinevideo.domain.CourseVideo; 5 | import com.zgh.onlinevideo.service.CourseVideoService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.ArrayList; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | 13 | @Service 14 | public class CourseVideoServiceImpl implements CourseVideoService { 15 | 16 | @Autowired 17 | CourseVideoDao courseVideoDao; 18 | 19 | @Override 20 | public List getCourseVideoAll(int courseTopicId) { 21 | 22 | HashMap map = new HashMap<>(); 23 | 24 | map.put("courseTopicId", courseTopicId); 25 | map.put("flag", 1); 26 | 27 | return courseVideoDao.findCourseVideoByCondition(map); 28 | } 29 | 30 | @Override 31 | public CourseVideo getCourseVideo(int vid) { 32 | 33 | List ids = new ArrayList(); 34 | ids.add(vid); 35 | return courseVideoDao.findCourseVideoByIds(ids); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/impl/ToolItemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service.impl; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.zgh.onlinevideo.dao.ToolItemDao; 5 | import com.zgh.onlinevideo.domain.ToolItem; 6 | import com.zgh.onlinevideo.service.ToolItemService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | 13 | @Service 14 | public class ToolItemServiceImpl implements ToolItemService { 15 | 16 | @Autowired 17 | ToolItemDao toolItemDao; 18 | 19 | @Override 20 | public PageInfo getToolItem(int toolTypeId) { 21 | 22 | HashMap map = new HashMap<>(); 23 | // 类型ID 24 | map.put("toolTypeId", toolTypeId); 25 | 26 | List list = toolItemDao.findToolItemByCondition(map); 27 | 28 | PageInfo pageInfo = new PageInfo<>(list, 4); 29 | 30 | return pageInfo; 31 | } 32 | 33 | @Override 34 | public PageInfo getToolItemAll() { 35 | HashMap map = new HashMap<>(); 36 | 37 | List list = toolItemDao.findToolItemAll(); 38 | 39 | PageInfo pageInfo = new PageInfo<>(list, 4); 40 | 41 | return pageInfo; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/service/impl/ToolTypeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.service.impl; 2 | 3 | import com.zgh.onlinevideo.dao.ToolTypeDao; 4 | import com.zgh.onlinevideo.domain.ToolType; 5 | import com.zgh.onlinevideo.service.ToolTypeService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class ToolTypeServiceImpl implements ToolTypeService { 13 | 14 | @Autowired 15 | ToolTypeDao toolTypeDao; 16 | 17 | @Override 18 | public List getToolTypeAll() { 19 | return toolTypeDao.findToolTypeAll(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/java/com/zgh/onlinevideo/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.zgh.onlinevideo.util; 2 | 3 | public class Constants { 4 | 5 | // 自动登录 6 | public static final String AUTO_LOGIN_TOKEN = "auto_login_token"; 7 | 8 | // SESION 登录 User 9 | public static final String LOGIN_USER = "login_user"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | #数据库 2 | jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://localhost:3306/ssm4?useUnicode=true&characterEncoding=UTF-8&useSSL=false 4 | jdbc.username=root 5 | jdbc.password=root 6 | 7 | 8 | #别名方式,扩展插件,监控统计用的filter:stat,日志用的filter:log4j,防御sql注入的filter:wall 9 | jdbc.filters=stat 10 | #最大连接数 11 | jdbc.maxActive=300 12 | #初始化连接数 13 | jdbc.initialSize=2 14 | #获取连接最大等待时间 15 | jdbc.maxWait=60000 16 | #最小连接数 17 | jdbc.minIdle=1 18 | #检测连接有效性的时间间隔 19 | jdbc.timeBetweenEvictionRunsMillis=60000 20 | #连接保持空闲而不被驱逐的最长时间 21 | jdbc.minEvictableIdleTimeMillis=300000 22 | #连接有效性,检测sql 23 | jdbc.validationQuery=SELECT 'x' 24 | #定时检测空闲连接有效性 25 | jdbc.testWhileIdle=true 26 | #检测获取的连接的有效性 27 | jdbc.testOnBorrow=false 28 | #检测要归还的连接的有效性 29 | jdbc.testOnReturn=false 30 | #是否缓存preparedStatement,即PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。 31 | jdbc.poolPreparedStatements=false 32 | jdbc.maxPoolPreparedStatementPerConnectionSize=50 -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/resources/spring/spring-mail.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/WEB-INF/jsp/common/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/WEB-INF/jsp/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | error 5 | 6 | 7 |

${message}

8 | 9 | 10 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/css/video.css: -------------------------------------------------------------------------------- 1 | /*card选项卡选中状态样式*/ 2 | .select-shadow:hover { 3 | -webkit-box-shadow: 2px 2px 8px 1px rgba(20, 20, 20, 0.15); 4 | -moz-box-shadow: 2px 2px 8px 1px rgba(20, 20, 20, 0.15); 5 | box-shadow: 2px 2px 8px 1px rgba(20, 20, 20, 0.15); 6 | cursor: pointer; 7 | color: red; 8 | } 9 | 10 | /*底部背景样式*/ 11 | .video-footer { 12 | background-color: #f3f5f7; 13 | box-shadow:0px 0px 1px 1px #ccc; 14 | } 15 | 16 | /*底部文字样式*/ 17 | .video-footer a { 18 | margin: 0 10px; 19 | font-size: 14px; 20 | color: #99a1a6; 21 | text-decoration: none; 22 | } -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/bootstrap-solid.svg: -------------------------------------------------------------------------------- 1 | 2 | Bootstrap 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/card-item.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/card-item.png -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/hicon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/hicon.jpg -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/index_banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/01:ssm在线视频学习网站/src/main/webapp/static/imgs/index_banner.jpg -------------------------------------------------------------------------------- /【00】demos_04/01:ssm在线视频学习网站/ssm.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/.gitignore: -------------------------------------------------------------------------------- 1 | ### test ### 2 | TestMain.java 3 | 4 | target/ 5 | !.mvn/wrapper/maven-wrapper.jar 6 | !**/src/main/**/target/ 7 | !**/src/test/**/target/ 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/02:springboot-epidemic/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/SpringbootEpidemicApplication.java: -------------------------------------------------------------------------------- 1 | package com.zgh; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | @SpringBootApplication 9 | @MapperScan("com.zgh.mapper") 10 | @EnableScheduling 11 | public class SpringbootEpidemicApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringbootEpidemicApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/bean/DataBean.java: -------------------------------------------------------------------------------- 1 | package com.zgh.bean; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @TableName("illness") 14 | public class DataBean implements Serializable { 15 | 16 | private Long id; 17 | 18 | private String name; 19 | 20 | private int nowConfirm; 21 | 22 | private int confirm; 23 | 24 | private int dead; 25 | 26 | private int heal; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/bean/GraphBarBean.java: -------------------------------------------------------------------------------- 1 | package com.zgh.bean; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GraphBarBean implements Comparable{ 11 | 12 | private String name; 13 | 14 | private int fromAbroad; 15 | 16 | @Override 17 | public int compareTo(GraphBarBean o) { 18 | return o.getFromAbroad() - this.getFromAbroad(); //递减 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/bean/GraphBean.java: -------------------------------------------------------------------------------- 1 | package com.zgh.bean; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @TableName("graph") 14 | public class GraphBean implements Serializable { 15 | 16 | private Long id; 17 | 18 | private String date; 19 | 20 | private int confirm; 21 | 22 | private int heal; 23 | 24 | private int dead; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/bean/MapBean.java: -------------------------------------------------------------------------------- 1 | package com.zgh.bean; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class MapBean { 11 | 12 | private String name; 13 | 14 | private int value; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/config/MyConfig.java: -------------------------------------------------------------------------------- 1 | package com.zgh.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.LocaleResolver; 6 | 7 | @Configuration 8 | public class MyConfig { 9 | 10 | @Bean 11 | public LocaleResolver localeResolver() { 12 | return new MyLocalResolver(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/config/MyLocalResolver.java: -------------------------------------------------------------------------------- 1 | package com.zgh.config; 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 | public class MyLocalResolver implements LocaleResolver { 11 | 12 | @Override 13 | public Locale resolveLocale(HttpServletRequest httpServletRequest) { 14 | 15 | String lan = httpServletRequest.getParameter("lan"); 16 | Locale locale = Locale.getDefault(); 17 | if (!StringUtils.isEmpty(lan)) { 18 | String[] split = lan.split("_"); 19 | locale = new Locale(split[0], split[1]); 20 | } 21 | 22 | return locale; 23 | } 24 | 25 | @Override 26 | public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) { 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/controller/DataController.java: -------------------------------------------------------------------------------- 1 | package com.zgh.controller; 2 | 3 | import com.zgh.bean.DataBean; 4 | import com.zgh.service.DataService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | 10 | import java.util.List; 11 | 12 | @Controller 13 | public class DataController { 14 | 15 | @Autowired 16 | DataService dataService; 17 | 18 | @GetMapping("/") 19 | public String list(Model model) { 20 | 21 | List dataList = dataService.list(); // mybatis-plus 查询全表数据 22 | model.addAttribute("dataList", dataList); 23 | return "list"; 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/mail/MailComponent.java: -------------------------------------------------------------------------------- 1 | package com.zgh.mail; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.mail.SimpleMailMessage; 5 | import org.springframework.mail.javamail.JavaMailSender; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class MailComponent { 10 | 11 | @Autowired 12 | private JavaMailSender sender; 13 | 14 | public void send() { 15 | 16 | System.out.println("spring-boot 发送邮件"); 17 | 18 | SimpleMailMessage message = new SimpleMailMessage(); 19 | 20 | message.setSubject("a email come from spring-boot"); 21 | message.setText("talk nonsense"); 22 | 23 | message.setTo("847818218@qq.com"); 24 | message.setFrom("847818218@qq.com"); 25 | 26 | sender.send(message); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/mapper/DataMapper.java: -------------------------------------------------------------------------------- 1 | package com.zgh.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zgh.bean.DataBean; 5 | 6 | public interface DataMapper extends BaseMapper { 7 | } 8 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/mapper/GraphMapper.java: -------------------------------------------------------------------------------- 1 | package com.zgh.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zgh.bean.GraphBean; 5 | 6 | public interface GraphMapper extends BaseMapper { 7 | } 8 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/service/DataService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zgh.bean.DataBean; 5 | 6 | public interface DataService extends IService { 7 | } 8 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/service/DataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zgh.bean.DataBean; 5 | import com.zgh.mapper.DataMapper; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class DataServiceImpl extends ServiceImpl implements DataService{ 10 | 11 | } 12 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/service/GraphService.java: -------------------------------------------------------------------------------- 1 | package com.zgh.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zgh.bean.GraphBean; 5 | 6 | public interface GraphService extends IService { 7 | } 8 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/service/GraphServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zgh.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zgh.bean.GraphBean; 5 | import com.zgh.mapper.GraphMapper; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class GraphServiceImpl extends ServiceImpl implements GraphService{ 10 | } 11 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/java/com/zgh/util/PathUtil.java: -------------------------------------------------------------------------------- 1 | package com.zgh.util; 2 | 3 | import java.io.File; 4 | 5 | public class PathUtil { 6 | 7 | public static void main(String[] args) { 8 | 9 | // 类加载路径的不同使用方式 10 | System.out.println(ClassLoader.getSystemResource("")); 11 | 12 | System.out.println(Thread.currentThread().getContextClassLoader().getResource("")); 13 | 14 | System.out.println(PathUtil.class.getResource("/")); 15 | 16 | System.out.println(PathUtil.class.getResource("")); 17 | 18 | System.out.println("======================="); 19 | 20 | // 当前项目根路径 21 | String path = System.getProperty("user.dir"); 22 | System.out.println(path); 23 | 24 | System.out.println(new File("").getAbsolutePath()); 25 | 26 | // 当前所在磁盘 27 | System.out.println(new File("/").getAbsolutePath()); 28 | 29 | 30 | // '/' 代表根目录 './' 代表当前目录 '../' 代表上级目录 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 设置 MySQL 数据源 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/epidemic?serverTimezone=UTC 5 | username: root 6 | password: root 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | 9 | # 设置国际化 10 | messages: 11 | basename: i18n.list 12 | 13 | # 发送邮件 14 | mail: 15 | host: smtp.qq.com 16 | username: 847818218@qq.com 17 | password: tbolyqdizctwbaij 18 | propertie.mail.smtp.ssl.enable: true 19 | 20 | 21 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | .__ .__ .__ .__ 2 | | |__ ____ | | | | ____ ________ ____ | |__ 3 | | | \_/ __ \| | | | / _ \ \___ / / ___\| | \ 4 | | Y \ ___/| |_| |_( <_> ) / / / /_/ > Y \ 5 | |___| /\___ >____/____/\____/ /_____ \\___ /|___| / 6 | \/ \/ \/_____/ \/ -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/i18n/list.properties: -------------------------------------------------------------------------------- 1 | list.title = 疫情 2 | list.h2 = 疫情 3 | list.table.name1 = 地区 4 | list.table.name2 = 现有确诊 5 | list.table.name3 = 累计确诊 6 | list.table.name4 = 治愈 7 | list.table.name5 = 死亡 8 | 9 | list.changelan.zh = 中文 10 | list.changeLan.en = English 11 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/i18n/list_en_US.properties: -------------------------------------------------------------------------------- 1 | list.title = epidemic 2 | list.h2 = epidemic 3 | list.table.name1 = area 4 | list.table.name2 = now_confirm 5 | list.table.name3 = confirm 6 | list.table.name4 = heal 7 | list.table.name5 = dead 8 | list.changelan.zh=Chinese 9 | list.changeLan.en=英语 -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/i18n/list_zh_CN.properties: -------------------------------------------------------------------------------- 1 | list.title = 疫情 2 | list.h2 = 疫情 3 | list.table.name1 = 地区 4 | list.table.name2 = 现有确诊 5 | list.table.name3 = 累计确诊 6 | list.table.name4 = 治愈 7 | list.table.name5 = 死亡 8 | list.changelan.zh=中文 9 | list.changeLan.en=English -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/main/resources/templates/graphBar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | epidemic 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /【00】demos_04/02:springboot-epidemic/src/test/java/com/zgh/EpidemicApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.zgh; 2 | 3 | import com.zgh.mail.MailComponent; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class EpidemicApplicationTests { 10 | 11 | @Autowired 12 | MailComponent mail; 13 | 14 | @Test 15 | void contextLoads() { 16 | 17 | mail.send(); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /【00】demos_04/images/image-20201119211503524.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/images/image-20201119211503524.png -------------------------------------------------------------------------------- /【00】demos_04/images/image-20210101122150218.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aixida/Java/9ebab61b0998b00e357968f7ee1e283e6e18fd30/【00】demos_04/images/image-20210101122150218.png --------------------------------------------------------------------------------