├── 第三章 └── demo_03 │ ├── .classpath │ ├── .project │ ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name │ ├── WebContent │ └── META-INF │ │ └── MANIFEST.MF │ ├── lib │ ├── catalina.jar │ ├── mina-core-2.0.7.jar │ ├── netty-all-5.0.0.Alpha1.jar │ ├── servlet-api.jar │ ├── slf4j-api-1.6.6.jar │ └── slf4j-nop-1.6.1.jar │ └── src │ └── com │ └── hjc │ └── demo │ ├── aio │ ├── AioClient.java │ └── AioServer.java │ ├── bio │ ├── BioClient.java │ └── BioDemo.java │ ├── http │ ├── HttpClient.java │ ├── HttpMethod.java │ └── HttpServer.java │ ├── mina │ ├── MinaClient.java │ ├── MinaClientHandler.java │ ├── MinaServer.java │ └── MinaServerHandler.java │ ├── netty │ ├── NettyClient.java │ ├── NettyClientHandler.java │ ├── NettyServer.java │ └── NettyServerHandler.java │ ├── nio │ ├── NioClient.java │ └── NioServer.java │ ├── socket │ ├── TCPSocketClient.java │ ├── TCPSocketServer.java │ ├── UDPSocketClient.java │ └── UDPSocketServer.java │ └── websocket │ ├── WebSocketServer.java │ └── websocketclient.html ├── 第九章 ├── herol │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── hjc │ │ │ │ ├── herol │ │ │ │ ├── core │ │ │ │ │ ├── CoreServlet.java │ │ │ │ │ ├── GameInit.java │ │ │ │ │ ├── GameServer.java │ │ │ │ │ └── Router.java │ │ │ │ ├── exception │ │ │ │ │ └── BaseException.java │ │ │ │ ├── manager │ │ │ │ │ ├── event │ │ │ │ │ │ ├── ED.java │ │ │ │ │ │ ├── Event.java │ │ │ │ │ │ ├── EventMgr.java │ │ │ │ │ │ └── EventProc.java │ │ │ │ │ ├── fight │ │ │ │ │ │ └── FightMgr.java │ │ │ │ │ ├── hero │ │ │ │ │ │ ├── HeroInfo.java │ │ │ │ │ │ ├── HeroMgr.java │ │ │ │ │ │ └── HeroRpc.java │ │ │ │ │ ├── player │ │ │ │ │ │ ├── Player.java │ │ │ │ │ │ └── PlayerMgr.java │ │ │ │ │ └── treasure │ │ │ │ │ │ ├── TreasureInfo.java │ │ │ │ │ │ └── TreasureMgr.java │ │ │ │ ├── net │ │ │ │ │ ├── ProtoIds.java │ │ │ │ │ ├── ProtoMessage.java │ │ │ │ │ ├── ResultCode.java │ │ │ │ │ ├── http │ │ │ │ │ │ ├── HttpInHandler.java │ │ │ │ │ │ ├── HttpInHandlerImp.java │ │ │ │ │ │ ├── HttpOutHandler.java │ │ │ │ │ │ ├── HttpOutHandlerImp.java │ │ │ │ │ │ ├── HttpServer.java │ │ │ │ │ │ ├── SessionKey.java │ │ │ │ │ │ └── SessionMgr.java │ │ │ │ │ ├── message │ │ │ │ │ │ ├── BaseReq.java │ │ │ │ │ │ ├── BaseResp.java │ │ │ │ │ │ ├── LoginReq.java │ │ │ │ │ │ ├── LoginResp.java │ │ │ │ │ │ └── TestReq.java │ │ │ │ │ └── socket │ │ │ │ │ │ ├── ChannelAttKey.java │ │ │ │ │ │ ├── ChannelMgr.java │ │ │ │ │ │ ├── ChannelUser.java │ │ │ │ │ │ ├── SocketHandler.java │ │ │ │ │ │ ├── SocketHandlerImp.java │ │ │ │ │ │ └── SocketServer.java │ │ │ │ ├── notification │ │ │ │ │ ├── NotifyController.java │ │ │ │ │ ├── ServerNotify.java │ │ │ │ │ └── message │ │ │ │ │ │ ├── ServerReq.java │ │ │ │ │ │ └── ServerResp.java │ │ │ │ ├── task │ │ │ │ │ ├── DailyTaskService.java │ │ │ │ │ ├── ExecutorPool.java │ │ │ │ │ └── TaskService.java │ │ │ │ ├── template │ │ │ │ │ ├── Hero.java │ │ │ │ │ └── Treasure.java │ │ │ │ └── util │ │ │ │ │ ├── AppContext.java │ │ │ │ │ ├── ApplicationProperties.java │ │ │ │ │ ├── BiaoQingDeal.java │ │ │ │ │ ├── CalendarUtil.java │ │ │ │ │ ├── CatchMessageFromHtml.java │ │ │ │ │ ├── Config.java │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── DESedeCoder.java │ │ │ │ │ ├── DateFormat.java │ │ │ │ │ ├── DateFormatUtil.java │ │ │ │ │ ├── DateUtil.java │ │ │ │ │ ├── DesUtil.java │ │ │ │ │ ├── ExceWriteInter.java │ │ │ │ │ ├── ExcelOutUtil.java │ │ │ │ │ ├── ExcelReadUtil.java │ │ │ │ │ ├── ExcelWriteUtil2007.java │ │ │ │ │ ├── ExportUtil.java │ │ │ │ │ ├── FileUtls.java │ │ │ │ │ ├── HMACSHA1.java │ │ │ │ │ ├── HttpClient.java │ │ │ │ │ ├── HttpClientForBind.java │ │ │ │ │ ├── IOUtil.java │ │ │ │ │ ├── JsonUtil.java │ │ │ │ │ ├── JsonUtils.java │ │ │ │ │ ├── Paging.java │ │ │ │ │ ├── PatternMatcher.java │ │ │ │ │ ├── ReadExcelUtile.java │ │ │ │ │ ├── SendXml.java │ │ │ │ │ ├── ServletPathMatcher.java │ │ │ │ │ ├── StringUtil.java │ │ │ │ │ ├── StringUtils.java │ │ │ │ │ ├── ThreadViewer.java │ │ │ │ │ ├── WorkbookFactory.java │ │ │ │ │ ├── cache │ │ │ │ │ ├── CacheKeys.java │ │ │ │ │ ├── MC.java │ │ │ │ │ ├── MCSupport.java │ │ │ │ │ └── SerializeUtil.java │ │ │ │ │ ├── context │ │ │ │ │ ├── ContextInterceptor.java │ │ │ │ │ └── SpringInit.java │ │ │ │ │ ├── csv │ │ │ │ │ ├── CsvDataLoader.java │ │ │ │ │ ├── CsvParser.java │ │ │ │ │ └── TempletService.java │ │ │ │ │ ├── encrypt │ │ │ │ │ ├── Base64.java │ │ │ │ │ ├── Coder.java │ │ │ │ │ ├── Md5Coder.java │ │ │ │ │ ├── PBECoder.java │ │ │ │ │ └── XXTeaCoder.java │ │ │ │ │ ├── hibernate │ │ │ │ │ ├── HibernateUtil.java │ │ │ │ │ └── TableIDCreator.java │ │ │ │ │ ├── memcached │ │ │ │ │ └── MemcachedCRUD.java │ │ │ │ │ ├── mongo │ │ │ │ │ ├── DBObjectUtil.java │ │ │ │ │ ├── MainTest.java │ │ │ │ │ ├── MongoCollections.java │ │ │ │ │ ├── MongoUtil.java │ │ │ │ │ ├── MorphiaUtil.java │ │ │ │ │ ├── SubBean.java │ │ │ │ │ ├── TableIDCreator.java │ │ │ │ │ └── TestBean.java │ │ │ │ │ ├── page │ │ │ │ │ ├── DB2Dialect.java │ │ │ │ │ ├── Dialect.java │ │ │ │ │ ├── Mysql5Dialect.java │ │ │ │ │ ├── OracleDialect.java │ │ │ │ │ ├── Page.java │ │ │ │ │ ├── PageContext.java │ │ │ │ │ ├── PageList.java │ │ │ │ │ └── ReflectHelper.java │ │ │ │ │ ├── redis │ │ │ │ │ └── Redis.java │ │ │ │ │ ├── sensitive │ │ │ │ │ └── SensitiveFilter.java │ │ │ │ │ └── xml │ │ │ │ │ ├── XmlDataLoader.java │ │ │ │ │ └── XmlParser.java │ │ │ │ └── pay │ │ │ │ └── client │ │ │ │ └── pay │ │ │ │ ├── IPay.java │ │ │ │ └── Pay.java │ │ ├── resources │ │ │ ├── applicationContext.xml │ │ │ ├── csv │ │ │ │ ├── Hero.csv │ │ │ │ └── Treasure.csv │ │ │ ├── dataConfig.xml │ │ │ ├── datasource.properties │ │ │ ├── log4j.properties │ │ │ ├── net.properties │ │ │ ├── server.properties │ │ │ ├── spring-cache │ │ │ │ ├── applicationContext-memcached.xml │ │ │ │ └── memcached.properties │ │ │ ├── spring-conf │ │ │ │ └── applicationContext.xml │ │ │ ├── spring-email │ │ │ │ └── applicationContext-email.xml │ │ │ ├── spring-mongodb │ │ │ │ ├── applicationContext-mongodb.xml │ │ │ │ ├── mongo operate.txt │ │ │ │ └── mongodb.properties │ │ │ ├── spring-redis │ │ │ │ ├── applicationContext-redis.xml │ │ │ │ └── redis.properties │ │ │ ├── spring-servlet │ │ │ │ └── servlet-context.xml │ │ │ └── syspara.xml │ │ └── webapp │ │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ │ ├── WEB-INF │ │ │ ├── Spring MVC Dispatcher Servlet-servlet.xml │ │ │ └── web.xml │ │ │ ├── css │ │ │ ├── WdatePicker.css │ │ │ ├── admin │ │ │ │ ├── User_Login.css │ │ │ │ ├── admin.css │ │ │ │ ├── login.css │ │ │ │ ├── reset_pc.css │ │ │ │ └── style.css │ │ │ ├── comm.css │ │ │ ├── common.css │ │ │ ├── default.css │ │ │ ├── font-awesome.min.css │ │ │ ├── fonts │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── icomoon.eot │ │ │ │ ├── icomoon.svg │ │ │ │ ├── icomoon.ttf │ │ │ │ └── icomoon.woff │ │ │ ├── layout.css │ │ │ ├── page.css │ │ │ ├── scroll.css │ │ │ ├── signrule.css │ │ │ ├── style.css │ │ │ ├── stylewh.css │ │ │ ├── tablestyle.css │ │ │ ├── tip.css │ │ │ └── tips.css │ │ │ ├── js │ │ │ ├── My97DatePicker.htm │ │ │ ├── WdatePicker.js │ │ │ ├── activity │ │ │ │ ├── activity.js │ │ │ │ └── award.js │ │ │ ├── admin │ │ │ │ ├── login.js │ │ │ │ ├── menu.js │ │ │ │ └── page.js │ │ │ ├── ajaxfileupload.js │ │ │ ├── calendar.js │ │ │ ├── config.js │ │ │ ├── global.js │ │ │ ├── jquery-1.9.1.min.js │ │ │ └── jquery.pagination.js │ │ │ └── uploadify │ │ │ ├── jquery.uploadify.js │ │ │ ├── jquery.uploadify.min.js │ │ │ ├── uploadify-cancel.png │ │ │ ├── uploadify.css │ │ │ └── uploadify.swf │ │ └── test │ │ └── java │ │ ├── httptest │ │ ├── HttpClientHandler.java │ │ └── HttpClientTest.java │ │ ├── mongo │ │ └── MorphiaTest.java │ │ ├── nettytest │ │ ├── HttpInHandler.java │ │ └── NettyClient.java │ │ └── sockettest │ │ └── SocketTest.java ├── herolclient │ ├── .classpath │ ├── .project │ ├── libs │ │ ├── fastjson-1.1.36.jar │ │ ├── netty-all-5.0.0.Alpha1.jar │ │ └── slf4j-api-1.7.2.jar │ └── src │ │ └── com │ │ └── hjc │ │ ├── herolclient │ │ ├── ChooseServer.java │ │ ├── Logical.java │ │ ├── Login.java │ │ └── Pvp.java │ │ ├── net │ │ ├── LogicProtoIds.java │ │ ├── NettyClient.java │ │ ├── ProtoMessage.java │ │ ├── PvpProtoIds.java │ │ ├── ResultCode.java │ │ └── SocketInHandler.java │ │ └── util │ │ └── HttpClient.java ├── herolpvp │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── hjc │ │ │ │ └── herolpvp │ │ │ │ ├── core │ │ │ │ ├── CoreServlet.java │ │ │ │ ├── GameInit.java │ │ │ │ ├── GameServer.java │ │ │ │ └── Router.java │ │ │ │ ├── exception │ │ │ │ └── BaseException.java │ │ │ │ ├── manager │ │ │ │ ├── event │ │ │ │ │ ├── ED.java │ │ │ │ │ ├── Event.java │ │ │ │ │ ├── EventMgr.java │ │ │ │ │ └── EventProc.java │ │ │ │ └── fight │ │ │ │ │ └── FightMgr.java │ │ │ │ ├── net │ │ │ │ ├── ProtoIds.java │ │ │ │ ├── ProtoMessage.java │ │ │ │ ├── ResultCode.java │ │ │ │ ├── http │ │ │ │ │ ├── HttpInHandler.java │ │ │ │ │ ├── HttpInHandlerImp.java │ │ │ │ │ ├── HttpOutHandler.java │ │ │ │ │ ├── HttpOutHandlerImp.java │ │ │ │ │ ├── HttpServer.java │ │ │ │ │ ├── SessionKey.java │ │ │ │ │ └── SessionMgr.java │ │ │ │ └── socket │ │ │ │ │ ├── ChannelAttKey.java │ │ │ │ │ ├── ChannelMgr.java │ │ │ │ │ ├── ChannelUser.java │ │ │ │ │ ├── SocketHandler.java │ │ │ │ │ ├── SocketHandlerImp.java │ │ │ │ │ └── SocketServer.java │ │ │ │ ├── task │ │ │ │ ├── DailyTaskService.java │ │ │ │ ├── ExecutorPool.java │ │ │ │ └── TaskService.java │ │ │ │ └── util │ │ │ │ ├── AppContext.java │ │ │ │ ├── ApplicationProperties.java │ │ │ │ ├── Config.java │ │ │ │ ├── Constants.java │ │ │ │ ├── DESedeCoder.java │ │ │ │ ├── DateFormat.java │ │ │ │ ├── DateFormatUtil.java │ │ │ │ ├── DateUtil.java │ │ │ │ ├── DesUtil.java │ │ │ │ ├── FileUtls.java │ │ │ │ ├── HMACSHA1.java │ │ │ │ ├── HttpClient.java │ │ │ │ ├── HttpClientForBind.java │ │ │ │ ├── IOUtil.java │ │ │ │ ├── JsonUtil.java │ │ │ │ ├── JsonUtils.java │ │ │ │ ├── Paging.java │ │ │ │ ├── PatternMatcher.java │ │ │ │ ├── SendXml.java │ │ │ │ ├── ServletPathMatcher.java │ │ │ │ ├── StringUtil.java │ │ │ │ ├── StringUtils.java │ │ │ │ ├── ThreadViewer.java │ │ │ │ ├── WorkbookFactory.java │ │ │ │ ├── cache │ │ │ │ ├── CacheKeys.java │ │ │ │ ├── MC.java │ │ │ │ ├── MCSupport.java │ │ │ │ └── SerializeUtil.java │ │ │ │ ├── context │ │ │ │ ├── ContextInterceptor.java │ │ │ │ └── SpringInit.java │ │ │ │ ├── csv │ │ │ │ ├── CsvDataLoader.java │ │ │ │ ├── CsvParser.java │ │ │ │ └── TempletService.java │ │ │ │ ├── encrypt │ │ │ │ ├── Base64.java │ │ │ │ ├── Coder.java │ │ │ │ ├── Md5Coder.java │ │ │ │ ├── PBECoder.java │ │ │ │ └── XXTeaCoder.java │ │ │ │ ├── hibernate │ │ │ │ ├── HibernateUtil.java │ │ │ │ └── TableIDCreator.java │ │ │ │ ├── memcached │ │ │ │ └── MemcachedCRUD.java │ │ │ │ ├── mongo │ │ │ │ ├── DBObjectUtil.java │ │ │ │ ├── MainTest.java │ │ │ │ ├── MongoCollections.java │ │ │ │ ├── MongoUtil.java │ │ │ │ ├── SubBean.java │ │ │ │ ├── TableIDCreator.java │ │ │ │ └── TestBean.java │ │ │ │ ├── page │ │ │ │ ├── DB2Dialect.java │ │ │ │ ├── Dialect.java │ │ │ │ ├── Mysql5Dialect.java │ │ │ │ ├── OracleDialect.java │ │ │ │ ├── Page.java │ │ │ │ ├── PageContext.java │ │ │ │ ├── PageList.java │ │ │ │ └── ReflectHelper.java │ │ │ │ ├── redis │ │ │ │ └── Redis.java │ │ │ │ ├── sensitive │ │ │ │ └── SensitiveFilter.java │ │ │ │ └── xml │ │ │ │ ├── XmlDataLoader.java │ │ │ │ └── XmlParser.java │ │ ├── resources │ │ │ ├── applicationContext.xml │ │ │ ├── dataConfig.xml │ │ │ ├── datasource.properties │ │ │ ├── log4j.properties │ │ │ ├── net.properties │ │ │ ├── server.properties │ │ │ ├── spring-conf │ │ │ │ └── applicationContext.xml │ │ │ ├── spring-mongodb │ │ │ │ ├── applicationContext-mongodb.xml │ │ │ │ ├── mongo operate.txt │ │ │ │ └── mongodb.properties │ │ │ ├── spring-servlet │ │ │ │ └── servlet-context.xml │ │ │ └── syspara.xml │ │ └── webapp │ │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ │ ├── WEB-INF │ │ │ ├── Spring MVC Dispatcher Servlet-servlet.xml │ │ │ ├── views │ │ │ │ ├── activity │ │ │ │ │ ├── award.jsp │ │ │ │ │ ├── awardlist.jsp │ │ │ │ │ └── query.jsp │ │ │ │ ├── admin │ │ │ │ │ ├── bottom.jsp │ │ │ │ │ ├── content.jsp │ │ │ │ │ ├── index.jsp │ │ │ │ │ ├── left.jsp │ │ │ │ │ ├── login.jsp │ │ │ │ │ └── top.jsp │ │ │ │ └── common │ │ │ │ │ ├── 403.jsp │ │ │ │ │ ├── 404.jsp │ │ │ │ │ ├── 405.jsp │ │ │ │ │ ├── 500.jsp │ │ │ │ │ ├── end.jsp │ │ │ │ │ ├── err.jsp │ │ │ │ │ ├── error.jsp │ │ │ │ │ └── upload_error.jsp │ │ │ └── web.xml │ │ │ ├── css │ │ │ ├── WdatePicker.css │ │ │ ├── admin │ │ │ │ ├── User_Login.css │ │ │ │ ├── admin.css │ │ │ │ ├── login.css │ │ │ │ ├── reset_pc.css │ │ │ │ └── style.css │ │ │ ├── comm.css │ │ │ ├── common.css │ │ │ ├── default.css │ │ │ ├── font-awesome.min.css │ │ │ ├── fonts │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── icomoon.eot │ │ │ │ ├── icomoon.svg │ │ │ │ ├── icomoon.ttf │ │ │ │ └── icomoon.woff │ │ │ ├── layout.css │ │ │ ├── page.css │ │ │ ├── scroll.css │ │ │ ├── signrule.css │ │ │ ├── style.css │ │ │ ├── stylewh.css │ │ │ ├── tablestyle.css │ │ │ ├── tip.css │ │ │ └── tips.css │ │ │ ├── js │ │ │ ├── My97DatePicker.htm │ │ │ ├── WdatePicker.js │ │ │ ├── activity │ │ │ │ ├── activity.js │ │ │ │ └── award.js │ │ │ ├── admin │ │ │ │ ├── login.js │ │ │ │ ├── menu.js │ │ │ │ └── page.js │ │ │ ├── ajaxfileupload.js │ │ │ ├── calendar.js │ │ │ ├── config.js │ │ │ ├── global.js │ │ │ ├── jquery-1.9.1.min.js │ │ │ └── jquery.pagination.js │ │ │ └── uploadify │ │ │ ├── jquery.uploadify.js │ │ │ ├── jquery.uploadify.min.js │ │ │ ├── uploadify-cancel.png │ │ │ ├── uploadify.css │ │ │ └── uploadify.swf │ │ └── test │ │ └── java │ │ ├── httptest │ │ ├── HttpClientHandler.java │ │ └── HttpClientTest.java │ │ ├── nettytest │ │ ├── HttpInHandler.java │ │ ├── NettyClient.java │ │ └── SocketInHandler.java │ │ ├── pvpclient │ │ ├── Logical.java │ │ ├── Login.java │ │ └── Pvp.java │ │ └── sockettest │ │ └── SocketTest.java └── herolrouter │ ├── .classpath │ ├── .project │ ├── lib │ └── signature.jar │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── hjc │ │ └── herolrouter │ │ ├── client │ │ ├── RouteController.java │ │ ├── message │ │ │ ├── LoginReq.java │ │ │ ├── LoginResp.java │ │ │ └── PayReq.java │ │ ├── model │ │ │ └── Account.java │ │ ├── pay │ │ │ ├── Pay.java │ │ │ └── PayController.java │ │ ├── rpc │ │ │ ├── TestService.java │ │ │ └── TestServiceImply.java │ │ └── service │ │ │ └── AccountService.java │ │ ├── core │ │ ├── CoreServlet.java │ │ ├── GameInit.java │ │ └── TaskService.java │ │ ├── message │ │ ├── GetServersReq.java │ │ ├── GetServersResp.java │ │ ├── ServerReq.java │ │ └── ServerResp.java │ │ ├── server │ │ ├── NotifyController.java │ │ ├── NotifyService.java │ │ ├── ServerConfig.java │ │ ├── ServerController.java │ │ ├── ServerRpc.java │ │ └── ServerService.java │ │ └── util │ │ ├── AppContext.java │ │ ├── ApplicationProperties.java │ │ ├── Config.java │ │ ├── Constants.java │ │ ├── DESedeCoder.java │ │ ├── DateFormat.java │ │ ├── DesUtil.java │ │ ├── ExcelOutUtil.java │ │ ├── ExcelReadUtil.java │ │ ├── FileUtls.java │ │ ├── HttpClient.java │ │ ├── JsonUtil.java │ │ ├── JsonUtils.java │ │ ├── Paging.java │ │ ├── PatternMatcher.java │ │ ├── ReadExcelUtile.java │ │ ├── ServletPathMatcher.java │ │ ├── StringUtil.java │ │ ├── StringUtils.java │ │ ├── WorkbookFactory.java │ │ ├── cache │ │ ├── CacheKeys.java │ │ ├── MC.java │ │ ├── MCSupport.java │ │ └── SerializeUtil.java │ │ ├── context │ │ ├── ContextInterceptor.java │ │ └── SpringInit.java │ │ ├── encrypt │ │ ├── Coder.java │ │ ├── Md5Coder.java │ │ └── PBECoder.java │ │ ├── exception │ │ └── BaseException.java │ │ ├── hibernate │ │ ├── HibernateUtil.java │ │ └── TableIDCreator.java │ │ ├── memcached │ │ └── MemcachedCRUD.java │ │ ├── redis │ │ └── Redis.java │ │ └── sensitive │ │ └── SensitiveFilter.java │ ├── resources │ ├── applicationContext.xml │ ├── datasource.properties │ ├── log4j.properties │ ├── server.properties │ ├── spring-cache │ │ ├── applicationContext-memcached.xml │ │ └── memcached.properties │ ├── spring-conf │ │ └── applicationContext.xml │ ├── spring-cxf │ │ ├── cxf-client.xml │ │ └── cxf-servlet.xml │ ├── spring-redis │ │ ├── applicationContext-redis.xml │ │ └── redis.properties │ ├── spring-servlet │ │ └── servlet-context.xml │ └── syspara.xml │ └── webapp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── Spring MVC Dispatcher Servlet-servlet.xml │ ├── views │ │ ├── accountmgr │ │ │ ├── accountChart.jsp │ │ │ └── accountlist.jsp │ │ ├── admin │ │ │ ├── bottom.jsp │ │ │ ├── content.jsp │ │ │ ├── index.jsp │ │ │ ├── left.jsp │ │ │ ├── login.jsp │ │ │ └── top.jsp │ │ ├── common │ │ │ ├── 403.jsp │ │ │ ├── 404.jsp │ │ │ ├── 405.jsp │ │ │ ├── 500.jsp │ │ │ ├── end.jsp │ │ │ ├── err.jsp │ │ │ ├── error.jsp │ │ │ └── upload_error.jsp │ │ ├── log │ │ │ └── logConfig.jsp │ │ ├── paymgr │ │ │ ├── addPay.jsp │ │ │ ├── payChart.jsp │ │ │ ├── payConfig.jsp │ │ │ └── paylist.jsp │ │ ├── server │ │ │ ├── addserver.jsp │ │ │ └── serverlist.jsp │ │ └── sn │ │ │ └── snlist.jsp │ └── web.xml │ ├── css │ ├── WdatePicker.css │ ├── admin │ │ ├── admin.css │ │ ├── login.css │ │ └── style.css │ ├── bootstrap.min.css │ ├── comm.css │ ├── common.css │ ├── default.css │ ├── font-awesome.min.css │ ├── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.svg │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ ├── icomoon.eot │ │ ├── icomoon.svg │ │ ├── icomoon.ttf │ │ └── icomoon.woff │ ├── index.css │ ├── layout.css │ ├── page.css │ ├── scroll.css │ ├── signrule.css │ ├── style.css │ ├── stylewh.css │ ├── tablestyle.css │ ├── tip.css │ └── tips.css │ ├── js │ ├── admin │ │ ├── login.js │ │ └── menu.js │ ├── bootstrap.min.js │ ├── docs.min.js │ ├── echarts.js │ ├── echarts.min.js │ ├── jquery-1.9.1.min.js │ ├── jquery.js │ ├── paymgr │ │ └── payChart.js │ └── server │ │ └── server.js │ └── uploadify │ ├── jquery.uploadify.js │ ├── jquery.uploadify.min.js │ ├── uploadify-cancel.png │ ├── uploadify.css │ └── uploadify.swf ├── 第五章 └── demo_05 │ ├── .classpath │ ├── .project │ ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name │ ├── WebContent │ └── META-INF │ │ └── MANIFEST.MF │ ├── lib │ ├── antlr-2.7.7.jar │ ├── catalina.jar │ ├── commons-beanutils-1.8.3.jar │ ├── commons-lang3-3.1.jar │ ├── commons-logging-1.1.1.jar │ ├── commons-pool-1.6.jar │ ├── commons-pool2-2.2.jar │ ├── dom4j-1.6.1.jar │ ├── fastjson-1.1.36.jar │ ├── hibernate-commons-annotations-4.0.5.Final.jar │ ├── hibernate-core-4.3.10.Final.jar │ ├── hibernate-jpa-2.1-api-1.0.0.Final.jar │ ├── jandex-1.1.0.Final.jar │ ├── javassist-3.18.1-GA.jar │ ├── jboss-logging-3.1.3.GA.jar │ ├── jboss-logging-annotations-1.2.0.Beta1.jar │ ├── jboss-transaction-api_1.2_spec-1.0.0.Final.jar │ ├── jedis-2.8.1.jar │ ├── memcached-2.5.3.jar │ ├── mongo-java-driver-2.11.2.jar │ ├── morphia-0.102.jar │ ├── mysql-connector-java-5.1.22.jar │ ├── servlet-api.jar │ ├── slf4j-api-1.7.2.jar │ ├── spring-data-redis-1.7.1.RELEASE.jar │ └── tomcat-coyote.jar │ └── src │ ├── com │ └── hjc │ │ └── demo │ │ ├── DemoBean.java │ │ ├── hibernate │ │ ├── DemoBean.hbm.xml │ │ └── HibernateDemo.java │ │ ├── jdbc │ │ └── JDBCDemo.java │ │ ├── memcache │ │ ├── MemcacheClientDemo.java │ │ └── MemcachedCRUD.java │ │ ├── mongo │ │ ├── DBObjectUtil.java │ │ ├── MongoAPIDemo.java │ │ ├── MongoCollections.java │ │ ├── MongoUtil.java │ │ ├── SubBean.java │ │ └── TestBean.java │ │ └── redis │ │ ├── Redis.java │ │ └── RedisDemo.java │ ├── hibernate.cfg.xml │ └── log4j.properties ├── 第六章 ├── demo_06 │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── .jsdtscope │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ ├── org.eclipse.wst.jsdt.ui.superType.container │ │ └── org.eclipse.wst.jsdt.ui.superType.name │ ├── README │ ├── WebContent │ │ └── META-INF │ │ │ └── MANIFEST.MF │ ├── lib │ │ ├── catalina.jar │ │ ├── commons-beanutils-1.8.3.jar │ │ ├── commons-collections-3.2.1.jar │ │ ├── commons-logging-1.1.1.jar │ │ ├── fastjson-1.1.36.jar │ │ ├── quartz-1.5.2.jar │ │ ├── quartz-2.2.3.jar │ │ ├── quartz-jobs-2.2.3.jar │ │ ├── servlet-api.jar │ │ └── tomcat-coyote.jar │ └── src │ │ └── com │ │ └── hjc │ │ ├── demo │ │ ├── core │ │ │ ├── GameInit.java │ │ │ └── Router.java │ │ ├── manager │ │ │ ├── event │ │ │ │ ├── ED.java │ │ │ │ ├── Event.java │ │ │ │ ├── EventMgr.java │ │ │ │ └── EventProc.java │ │ │ ├── module1 │ │ │ │ └── Demo1Mgr.java │ │ │ ├── module2 │ │ │ │ └── Demo2Mgr.java │ │ │ ├── module3 │ │ │ │ └── Demo3Mgr.java │ │ │ ├── module4 │ │ │ │ └── Demo4Mgr.java │ │ │ ├── module5 │ │ │ │ └── Demo5Mgr.java │ │ │ ├── module6 │ │ │ │ └── Demo6Mgr.java │ │ │ ├── module7 │ │ │ │ └── Demo7Mgr.java │ │ │ ├── module8 │ │ │ │ ├── Demo8Mgr.java │ │ │ │ └── DemoBean.java │ │ │ └── module9 │ │ │ │ └── Demo9Mgr.java │ │ ├── net │ │ │ ├── NetFramework.java │ │ │ ├── NetHandler.java │ │ │ ├── NetHandlerImpl.java │ │ │ ├── NetModule.java │ │ │ ├── ProtoIds.java │ │ │ ├── ProtoMessage.java │ │ │ ├── ResultCode.java │ │ │ ├── net.properties │ │ │ └── rpc │ │ │ │ └── README.txt │ │ ├── task │ │ │ ├── JobMgr.java │ │ │ ├── QuartzManager.java │ │ │ └── TestJob.java │ │ ├── template │ │ │ └── DataLoader.java │ │ └── util │ │ │ ├── CacheUtil.java │ │ │ ├── DBUtil.java │ │ │ └── ExecutorPool.java │ │ └── test │ │ └── Demo.java ├── jsonrpc_server │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── .settings │ │ ├── .jsdtscope │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ ├── org.eclipse.wst.jsdt.ui.superType.container │ │ ├── org.eclipse.wst.jsdt.ui.superType.name │ │ └── org.eclipse.wst.validation.prefs │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── hjc │ │ │ ├── demo │ │ │ ├── DemoBean.java │ │ │ ├── DemoService.java │ │ │ ├── DemoServiceImply.java │ │ │ ├── HttpHandler.java │ │ │ ├── HttpHandlerImp.java │ │ │ ├── HttpServer.java │ │ │ └── RpcServer.java │ │ │ └── test │ │ │ └── JsonRpcTest.java │ │ └── webapp │ │ ├── WEB-INF │ │ └── web.xml │ │ └── index.jsp └── motandemo │ ├── .classpath │ ├── .gitignore │ ├── .project │ ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── hjc │ │ └── motan │ │ ├── DemoBean.java │ │ ├── client │ │ └── Client.java │ │ └── server │ │ ├── FooService.java │ │ └── FooServiceImpl.java │ ├── resources │ ├── motan_client.xml │ └── motan_server.xml │ └── webapp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ └── web.xml │ └── index.jsp └── 第四章 └── demo_04 ├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent └── META-INF │ └── MANIFEST.MF ├── lib ├── commons-beanutils-1.8.3.jar ├── commons-collections-3.2.1.jar ├── commons-lang-2.5.jar ├── commons-logging-1.1.1.jar ├── dom4j-1.6.1.jar ├── ezmorph-1.0.6.jar ├── fastjson-1.1.36.jar ├── gson-2.2.4.jar ├── jackson-all-1.9.0.jar ├── jdom-1.1.jar ├── json-lib-2.4-jdk15.jar ├── protobuf-java-2.5.0.jar └── slf4j-api-1.7.7.jar ├── src-gen └── DemoProto.java └── src └── com └── hjc └── demo ├── json ├── FastjsonDemo.java ├── GsonDemo.java ├── JacksonDemo.java ├── JsonObject.java ├── JsonSubObject.java └── JsonlibDemo.java ├── pb ├── DemoProto.java ├── PbDemo.java └── demo.proto └── xml ├── Dom4jDemo.java ├── DomDemo.java ├── JDomDemo.java ├── RootElement.java ├── SaxDemo.java ├── SubElement.java └── XmlJDKDemo.java /第三章/demo_03/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | demo_03 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.wst.common.project.facet.core.nature 33 | org.eclipse.jdt.core.javanature 34 | org.eclipse.wst.jsdt.core.jsNature 35 | 36 | 37 | -------------------------------------------------------------------------------- /第三章/demo_03/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第三章/demo_03/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /第三章/demo_03/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /第三章/demo_03/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第三章/demo_03/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第三章/demo_03/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第三章/demo_03/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第三章/demo_03/lib/catalina.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/catalina.jar -------------------------------------------------------------------------------- /第三章/demo_03/lib/mina-core-2.0.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/mina-core-2.0.7.jar -------------------------------------------------------------------------------- /第三章/demo_03/lib/netty-all-5.0.0.Alpha1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/netty-all-5.0.0.Alpha1.jar -------------------------------------------------------------------------------- /第三章/demo_03/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/servlet-api.jar -------------------------------------------------------------------------------- /第三章/demo_03/lib/slf4j-api-1.6.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/slf4j-api-1.6.6.jar -------------------------------------------------------------------------------- /第三章/demo_03/lib/slf4j-nop-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第三章/demo_03/lib/slf4j-nop-1.6.1.jar -------------------------------------------------------------------------------- /第三章/demo_03/src/com/hjc/demo/aio/AioClient.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.aio; 2 | 3 | 4 | public class AioClient {} 5 | -------------------------------------------------------------------------------- /第三章/demo_03/src/com/hjc/demo/websocket/websocketclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebSocket客户端 6 | 7 | 8 |
9 | 11 |
12 |
13 | 34 | 35 | -------------------------------------------------------------------------------- /第九章/herol/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/core/CoreServlet.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.core; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.ServletRequest; 7 | import javax.servlet.ServletResponse; 8 | import javax.servlet.http.HttpServlet; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | public class CoreServlet extends HttpServlet { 14 | private static final long serialVersionUID = -2082543656440562457L; 15 | public static final Logger logger = LoggerFactory 16 | .getLogger(CoreServlet.class); 17 | 18 | @Override 19 | public void service(ServletRequest req, ServletResponse res) 20 | throws ServletException, IOException { 21 | logger.info("servlet service"); 22 | } 23 | 24 | @Override 25 | public void destroy() { 26 | logger.info("CoreServelet destroy"); 27 | GameInit.shutdown();// 通知服务器关服 28 | } 29 | 30 | @Override 31 | public void init() throws ServletException { 32 | logger.info("CoreServelet init"); 33 | GameInit.init();// 初始化游戏服务器 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/core/GameServer.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.core; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.hjc.herol.net.http.HttpServer; 7 | import com.hjc.herol.net.socket.SocketServer; 8 | 9 | public class GameServer { 10 | private static final Logger logger = LoggerFactory 11 | .getLogger(GameServer.class); 12 | public static volatile boolean shutdown = false; 13 | private static GameServer server; 14 | 15 | private GameServer() { 16 | } 17 | 18 | public static GameServer getInstance() { 19 | if (null == server) { 20 | server = new GameServer(); 21 | } 22 | return server; 23 | } 24 | 25 | /** 26 | * @Title: startServer 27 | * @Description: 开启服务器 28 | * @throws 29 | */ 30 | public void startServer() { 31 | // SocketServer.getInstance().start(); 32 | HttpServer.getInstance().start(); 33 | shutdown = false; 34 | } 35 | 36 | /** 37 | * @Title: shutServer 38 | * @Description: 关闭服务器 39 | * @throws 40 | */ 41 | public void shutServer() { 42 | // SocketServer.getInstance().shut(); 43 | HttpServer.getInstance().shut(); 44 | shutdown = true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/manager/event/ED.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.manager.event; 2 | 3 | /** 4 | * Event Id Definition 5 | * 6 | * @author 何金成 7 | * 8 | */ 9 | public class ED { 10 | public static final int ADD_ITEM = 10001; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/manager/event/Event.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.manager.event; 2 | 3 | /** 4 | * @author 康建虎 5 | * 6 | */ 7 | public class Event { 8 | public int id; 9 | public Object param; 10 | } 11 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/manager/event/EventProc.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.manager.event; 2 | 3 | /** 4 | * 事件处理器。 5 | * 6 | * @author 何金成 7 | * 8 | */ 9 | public abstract class EventProc { 10 | public boolean disable; 11 | 12 | public EventProc() { 13 | doReg(); 14 | } 15 | 16 | public abstract void proc(Event param); 17 | 18 | protected abstract void doReg(); 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/manager/hero/HeroInfo.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.manager.hero; 2 | 3 | public class HeroInfo { 4 | private int heroId; 5 | private int level;// 卡牌等级 6 | private int fightGroup;// 出战卡组 0-未出战,1-1卡组,2-2卡组,3-3卡组 7 | private int groupPosition;// 卡组位置 8 | private int count; 9 | 10 | public int getLevel() { 11 | return level; 12 | } 13 | 14 | public void setLevel(int level) { 15 | this.level = level; 16 | } 17 | 18 | public int getFightGroup() { 19 | return fightGroup; 20 | } 21 | 22 | public void setFightGroup(int fightGroup) { 23 | this.fightGroup = fightGroup; 24 | } 25 | 26 | public int getHeroId() { 27 | return heroId; 28 | } 29 | 30 | public void setHeroId(int heroId) { 31 | this.heroId = heroId; 32 | } 33 | 34 | public int getGroupPosition() { 35 | return groupPosition; 36 | } 37 | 38 | public void setGroupPosition(int groupPosition) { 39 | this.groupPosition = groupPosition; 40 | } 41 | 42 | public int getCount() { 43 | return count; 44 | } 45 | 46 | public void setCount(int count) { 47 | this.count = count; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/manager/treasure/TreasureInfo.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.manager.treasure; 2 | 3 | public class TreasureInfo { 4 | private int id; 5 | private int type; 6 | 7 | public int getId() { 8 | return id; 9 | } 10 | 11 | public void setId(int id) { 12 | this.id = id; 13 | } 14 | 15 | public int getType() { 16 | return type; 17 | } 18 | 19 | public void setType(int type) { 20 | this.type = type; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net; 2 | 3 | public class ResultCode { 4 | public static final int SUCCESS = 100;// 成功 5 | public static final int COMMON_ERR = 101;// 默认错误 6 | public static final int DB_ERR = 102;// 数据库错误 7 | public static final int PARAM_ERR = 103;// 参数错误 8 | public static final int COIN_ERR = 104;// 金币不足 9 | public static final int YUANBAO_ERR = 105;// 元宝不足 10 | public static final int JIANGHUN_ERR = 106;// 将魂不足 11 | public static final int JUN_GONG_ERR = 107;// 军功不足 12 | public static final int IRON_ERR = 108;// 精铁不足 13 | public static final int FOOD_ERR = 109;// 粮食不足 14 | public static final int VIP_ERR = 110;// vip不足 15 | public static final int HCZS_ERR = 111;// 强征次数不足 16 | public static final int CANGKU_COIN_ERR = 112;// 仓库银两已满 17 | public static final int CANGKU_FOOD_ERR = 113;// 仓库粮食已满 18 | public static final int SERVER_ERR = 500;// 服务器内部错误 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/http/HttpOutHandler.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.http; 2 | 3 | import io.netty.channel.ChannelHandlerAdapter; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelPromise; 6 | 7 | public class HttpOutHandler extends ChannelHandlerAdapter { 8 | 9 | public HttpOutHandlerImp handler = new HttpOutHandlerImp(); 10 | 11 | @Override 12 | public void write(ChannelHandlerContext ctx, Object msg, 13 | ChannelPromise promise) throws Exception { 14 | super.write(ctx, msg, promise); 15 | handler.write(ctx, msg, promise); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/http/HttpOutHandlerImp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.http; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.hjc.herol.util.Constants; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.ByteBufUtil; 12 | import io.netty.buffer.Unpooled; 13 | import io.netty.buffer.UnpooledUnsafeDirectByteBuf; 14 | import io.netty.channel.ChannelHandlerContext; 15 | import io.netty.channel.ChannelPromise; 16 | import io.netty.handler.codec.http.DefaultFullHttpResponse; 17 | import io.netty.handler.codec.http.HttpHeaders; 18 | 19 | public class HttpOutHandlerImp { 20 | public Logger logger = LoggerFactory.getLogger(HttpOutHandlerImp.class); 21 | 22 | public void write(ChannelHandlerContext ctx, Object msg, 23 | ChannelPromise promise) throws Exception { 24 | if (Constants.MSG_LOG_DEBUG) { 25 | DefaultFullHttpResponse resp = (DefaultFullHttpResponse) msg; 26 | logger.info("ip:{},write:{}", ctx.channel().remoteAddress(), resp 27 | .content().toString(Charset.forName("UTF-8"))); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/http/SessionKey.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.http; 2 | 3 | import com.hjc.herol.core.GameInit; 4 | 5 | public class SessionKey { 6 | public static final String CACHE_ONLINE = "online_" + GameInit.serverId 7 | + "_"; 8 | } 9 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/message/BaseReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.message; 2 | 3 | public class BaseReq { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/message/BaseResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.message; 2 | 3 | public class BaseResp { 4 | public int code; 5 | public String errMsg; 6 | 7 | public int getCode() { 8 | return code; 9 | } 10 | 11 | public void setCode(int code) { 12 | this.code = code; 13 | } 14 | 15 | public String getErrMsg() { 16 | return errMsg; 17 | } 18 | 19 | public void setErrMsg(String errMsg) { 20 | this.errMsg = errMsg; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/message/LoginReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.message; 2 | 3 | public class LoginReq extends BaseReq { 4 | private int accId; 5 | 6 | public int getAccId() { 7 | return accId; 8 | } 9 | 10 | public void setAccId(int accId) { 11 | this.accId = accId; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/message/LoginResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.message; 2 | 3 | public class LoginResp extends BaseResp { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/message/TestReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.message; 2 | 3 | public class TestReq { 4 | public String name; 5 | public String errMsg; 6 | public int health; 7 | public int attack; 8 | public int defend; 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public String getErrMsg() { 19 | return errMsg; 20 | } 21 | 22 | public void setErrMsg(String errMsg) { 23 | this.errMsg = errMsg; 24 | } 25 | 26 | public int getHealth() { 27 | return health; 28 | } 29 | 30 | public void setHealth(int health) { 31 | this.health = health; 32 | } 33 | 34 | public int getAttack() { 35 | return attack; 36 | } 37 | 38 | public void setAttack(int attack) { 39 | this.attack = attack; 40 | } 41 | 42 | public int getDefend() { 43 | return defend; 44 | } 45 | 46 | public void setDefend(int defend) { 47 | this.defend = defend; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/socket/ChannelAttKey.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.socket; 2 | 3 | public class ChannelAttKey { 4 | public static final String JUNZHU_ID = "junZhuId"; 5 | public static final String CHANNEL_ID = "channelId"; 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/net/socket/ChannelUser.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.net.socket; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | 5 | public class ChannelUser { 6 | public Long channelId; 7 | public Long userId; 8 | public ChannelHandlerContext ctx; 9 | } 10 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/notification/message/ServerReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.notification.message; 2 | 3 | public class ServerReq { 4 | private int serverId; 5 | private int state; 6 | private int accId; 7 | 8 | public int getServerId() { 9 | return serverId; 10 | } 11 | 12 | public void setServerId(int serverId) { 13 | this.serverId = serverId; 14 | } 15 | 16 | public int getState() { 17 | return state; 18 | } 19 | 20 | public void setState(int state) { 21 | this.state = state; 22 | } 23 | 24 | public int getAccId() { 25 | return accId; 26 | } 27 | 28 | public void setAccId(int accId) { 29 | this.accId = accId; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/notification/message/ServerResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.notification.message; 2 | 3 | public class ServerResp { 4 | private int code;// 100-成功 5 | private String result; 6 | public int getCode() { 7 | return code; 8 | } 9 | public void setCode(int code) { 10 | this.code = code; 11 | } 12 | public String getResult() { 13 | return result; 14 | } 15 | public void setResult(String result) { 16 | this.result = result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/task/DailyTaskService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.task; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * @ClassName: DailyTask 8 | * @Description: 每日定时任务 9 | * @author 何金成 10 | * @date 2016年3月30日 下午4:57:35 11 | * 12 | */ 13 | public class DailyTaskService { 14 | public static Logger logger = LoggerFactory 15 | .getLogger(DailyTaskService.class); 16 | 17 | public void pkDailyAwardMail() { 18 | // TODO 19 | logger.info("每日定时发送邮件"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/task/ExecutorPool.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.task; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /** 10 | * @ClassName: ExecutorPool 11 | * @Description: 线程池管理 12 | * @author 何金成 13 | * @date 2016年4月18日 下午3:42:42 14 | * 15 | */ 16 | public class ExecutorPool { 17 | public static ExecutorService channelHandleThreadPool = null; 18 | 19 | public Logger logger = LoggerFactory.getLogger(ExecutorPool.class); 20 | 21 | public static void initThreadsExecutor() { 22 | channelHandleThreadPool = Executors.newCachedThreadPool(); 23 | } 24 | 25 | public static void execute(Runnable runnable) { 26 | channelHandleThreadPool.execute(runnable); 27 | } 28 | 29 | public static void shutdown() { 30 | if (!channelHandleThreadPool.isShutdown()) { 31 | channelHandleThreadPool.shutdown(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/task/TaskService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.task; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.core.task.TaskExecutor; 7 | import org.springframework.scheduling.annotation.Scheduled; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @ClassName: DailyTask 12 | * @Description: 每日定时任务 13 | * @author 何金成 14 | * @date 2016年3月30日 下午4:57:35 15 | * 16 | */ 17 | @Service 18 | public class TaskService { 19 | @Autowired 20 | private TaskExecutor executor; 21 | public Logger logger = LoggerFactory.getLogger(TaskService.class); 22 | private static DailyTaskService dailyTaskService = new DailyTaskService(); 23 | 24 | @Scheduled(cron = "0 0 22 * * ? ") 25 | public void pkDailyAwardMail() { 26 | executor.execute(new Runnable() { 27 | public void run() { 28 | dailyTaskService.pkDailyAwardMail(); 29 | } 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/template/Treasure.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.template; 2 | 3 | public class Treasure { 4 | private int type; 5 | private int name; 6 | private int hero1; 7 | private int hero2; 8 | private int hero3; 9 | 10 | public int getType() { 11 | return type; 12 | } 13 | 14 | public void setType(int type) { 15 | this.type = type; 16 | } 17 | 18 | public int getName() { 19 | return name; 20 | } 21 | 22 | public void setName(int name) { 23 | this.name = name; 24 | } 25 | 26 | public int getHero1() { 27 | return hero1; 28 | } 29 | 30 | public void setHero1(int hero1) { 31 | this.hero1 = hero1; 32 | } 33 | 34 | public int getHero2() { 35 | return hero2; 36 | } 37 | 38 | public void setHero2(int hero2) { 39 | this.hero2 = hero2; 40 | } 41 | 42 | public int getHero3() { 43 | return hero3; 44 | } 45 | 46 | public void setHero3(int hero3) { 47 | this.hero3 = hero3; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/AppContext.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | import org.springframework.context.support.AbstractApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class AppContext { 7 | 8 | private static AppContext instance; 9 | 10 | private AbstractApplicationContext appContext; 11 | 12 | public synchronized static AppContext getInstance() { 13 | if (instance == null) { 14 | instance = new AppContext(); 15 | } 16 | return instance; 17 | } 18 | 19 | private AppContext() { 20 | this.appContext = new ClassPathXmlApplicationContext( 21 | "/applicationContext.xml"); 22 | } 23 | 24 | public AbstractApplicationContext getAppContext() { 25 | return appContext; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | public class Constants { 4 | public static final String MD5_KEY = "blog"; 5 | public static final int COMMON_PAGE_SIZE = 10; 6 | /**日志记录配置**/ 7 | public static boolean SDK_DEBUG = true; 8 | public static boolean MSG_LOG_DEBUG = true; 9 | public static boolean CLIENT_DEBUG = true; 10 | } 11 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/ExceWriteInter.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | 4 | import java.util.List; 5 | 6 | import org.apache.poi.ss.usermodel.Cell; 7 | import org.apache.poi.ss.usermodel.Row; 8 | import org.apache.poi.ss.usermodel.Sheet; 9 | import org.apache.poi.ss.usermodel.Workbook; 10 | 11 | /** 12 | * 写Excel文档 13 | * @author songhn 14 | * 15 | */ 16 | public interface ExceWriteInter { 17 | 18 | /** 19 | * 创建Excel文档 20 | * @param excelFilePath 21 | */ 22 | public void createExcel(Workbook workBook,List list)throws Exception; 23 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/HMACSHA1.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | import java.security.InvalidKeyException; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | 7 | 8 | 9 | 10 | 11 | import javax.crypto.Mac; 12 | import javax.crypto.spec.SecretKeySpec; 13 | 14 | import com.hjc.herol.util.encrypt.Md5Coder; 15 | 16 | public class HMACSHA1 { 17 | private static final String HMAC_SHA1 = "HmacSHA1"; 18 | 19 | /** 20 | * 生成签名数据 21 | * 22 | * @param data 待加密的数据 23 | * @param key 加密使用的key 24 | * @return 生成MD5编码的字符串 25 | * @throws InvalidKeyException 26 | * @throws NoSuchAlgorithmException 27 | */ 28 | public static String getSignature(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { 29 | SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1); 30 | Mac mac = Mac.getInstance(HMAC_SHA1); 31 | mac.init(signingKey); 32 | byte[] rawHmac = mac.doFinal(data); 33 | return Md5Coder.encodeByMD5(new String(rawHmac)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | public class IOUtil { 11 | public static final InputStream byte2Input(byte[] buf) { 12 | return new ByteArrayInputStream(buf); 13 | } 14 | 15 | public static final byte[] input2byte(InputStream inStream) 16 | throws IOException { 17 | ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); 18 | byte[] buff = new byte[100]; 19 | int rc = 0; 20 | while ((rc = inStream.read(buff, 0, 100)) > 0) { 21 | swapStream.write(buff, 0, rc); 22 | } 23 | byte[] in2b = swapStream.toByteArray(); 24 | return in2b; 25 | } 26 | 27 | // public static final ByteBuf strToByteBuf(String str){ 28 | // ByteBuf buf = new 29 | // } 30 | } 31 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/PatternMatcher.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | public interface PatternMatcher { 4 | 5 | boolean matches(String pattern, String source); 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/ReadExcelUtile.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | /** 4 | * 5 | */ 6 | 7 | 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.Set; 13 | 14 | import org.apache.poi.ss.usermodel.Workbook; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | /** 18 | * @author songtao 19 | * 20 | */ 21 | public class ReadExcelUtile { 22 | public List> readEXCl(MultipartFile file ,String fileType){ 23 | WorkbookFactory factory = new WorkbookFactory(); 24 | List> listResult = new ArrayList>(); 25 | Map map = null; 26 | try { 27 | Workbook workBook= factory.create(file,fileType); 28 | 29 | ExcelReadUtil util = new ExcelReadUtil(); 30 | map = util.readSheet(workBook); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | Set set = map.keySet(); 35 | for(Iterator it=set.iterator();it.hasNext();){ 36 | String key = (String)it.next(); 37 | List list = (List)map.get(key); 38 | listResult.add(list); 39 | } 40 | return listResult; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util; 2 | 3 | public class StringUtils { 4 | 5 | public static String getCutString(String str){ 6 | return getCutString(str,10); 7 | } 8 | public static String getCutString(String str,int len){ 9 | if(len<=1) len=1; 10 | if(null ==str){ 11 | return ""; 12 | } 13 | if(str.length()<=len){ 14 | return str; 15 | }else{ 16 | return str.subSequence(0, len-1)+"..."; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/cache/CacheKeys.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.cache; 2 | 3 | public class CacheKeys { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/cache/MCSupport.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.cache; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 实现此接口后还需要再MC类中增加cachedClass,并使用 7 | * com.qx.persistent.HibernateUtil.find(Class, long) 8 | * 代替where进行查询。 9 | * 需要对控制了的对象在第一次存库时调用MC.add,再调用HIbernateUtil.insert 10 | * @author 何金成 11 | * 12 | */ 13 | public interface MCSupport extends Serializable{ 14 | long getIdentifier(); 15 | } 16 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/cache/SerializeUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.cache; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectOutputStream; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * @author 康建虎 14 | * 15 | */ 16 | public class SerializeUtil { 17 | private static Logger log = LoggerFactory.getLogger(SerializeUtil.class); 18 | public static byte[] encode(Object o) throws IOException{ 19 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 20 | ObjectOutputStream os = new ObjectOutputStream(bos); 21 | os.writeObject(o); 22 | os.close(); 23 | bos.close(); 24 | byte[] arr = bos.toByteArray(); 25 | return arr; 26 | } 27 | public static T decode(byte[] data) throws IOException{ 28 | ByteArrayInputStream bis = new ByteArrayInputStream(data); 29 | ObjectInputStream ois = new ObjectInputStream(bis); 30 | Object o = null; 31 | try{ 32 | o = ois.readObject(); 33 | }catch(ClassNotFoundException e){ 34 | log.error("解析失败", e); 35 | } 36 | return (T)o; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/context/SpringInit.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.context; 2 | import javax.servlet.ServletContextEvent; 3 | import javax.servlet.ServletContextListener; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.web.context.WebApplicationContext; 6 | import org.springframework.web.context.support.WebApplicationContextUtils; 7 | public class SpringInit implements ServletContextListener { 8 | 9 | private static WebApplicationContext springContext; 10 | 11 | public SpringInit() { 12 | super(); 13 | } 14 | 15 | public void contextInitialized(ServletContextEvent event) { 16 | springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); 17 | } 18 | 19 | public void contextDestroyed(ServletContextEvent event) { 20 | } 21 | 22 | public static ApplicationContext getApplicationContext() { 23 | return springContext; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/mongo/MainTest.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.mongo; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.lang.reflect.Field; 8 | import java.net.HttpURLConnection; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | 12 | import com.hjc.herol.util.HttpClient; 13 | 14 | public class MainTest { 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/mongo/MongoCollections.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.mongo; 2 | 3 | public class MongoCollections { 4 | public static final String USER_DATA = "user_data"; 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/mongo/SubBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.mongo; 2 | 3 | import org.mongodb.morphia.annotations.Entity; 4 | 5 | @Entity 6 | public class SubBean { 7 | private Long id; 8 | private String str; 9 | 10 | public String getStr() { 11 | return str; 12 | } 13 | 14 | public void setStr(String str) { 15 | this.str = str; 16 | } 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/mongo/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.mongo; 2 | 3 | import java.util.Map; 4 | 5 | import org.mongodb.morphia.annotations.Entity; 6 | import org.mongodb.morphia.annotations.Id; 7 | 8 | @Entity 9 | public class TestBean { 10 | @Id 11 | private Long _id; 12 | private String msg; 13 | private Double score; 14 | private SubBean subBean; 15 | private Map subBeans; 16 | 17 | public Long getId() { 18 | return _id; 19 | } 20 | 21 | public void setId(Long _id) { 22 | this._id = _id; 23 | } 24 | 25 | public String getMsg() { 26 | return msg; 27 | } 28 | 29 | public void setMsg(String msg) { 30 | this.msg = msg; 31 | } 32 | 33 | public Double getScore() { 34 | return score; 35 | } 36 | 37 | public void setScore(Double score) { 38 | this.score = score; 39 | } 40 | 41 | public SubBean getSubBean() { 42 | return subBean; 43 | } 44 | 45 | public void setSubBean(SubBean subBean) { 46 | this.subBean = subBean; 47 | } 48 | 49 | public Map getSubBeans() { 50 | return subBeans; 51 | } 52 | 53 | public void setSubBeans(Map subBeans) { 54 | this.subBeans = subBeans; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/DB2Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | /** 4 | * Title : DB2Dialect .
5 | * Description : DB2数据方言,目前实现了物理分页.
6 | */ 7 | public class DB2Dialect implements Dialect { 8 | 9 | public String getPageSql(String sql, long offset, long limit) { 10 | sql = sql.trim(); 11 | StringBuffer pagingSelect = new StringBuffer(sql.length() + 100); 12 | pagingSelect.append(" SELECT * FROM (SELECT PAGE_B.*, ROWNUMBER() OVER() AS RN FROM ( "); 13 | pagingSelect.append(sql); 14 | pagingSelect.append(" ) AS PAGE_B )AS PAGE_A WHERE PAGE_A.RN BETWEEN ").append(offset).append(" AND ") 15 | .append(offset + limit - 1); 16 | return pagingSelect.toString(); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | /** 4 | * Title : Dialect .
5 | * Description : 数据库方言接口.
6 | *
7 | */ 8 | public interface Dialect { 9 | 10 | public static enum Type{ 11 | MYSQL, 12 | ORACLE, 13 | DB2 14 | } 15 | 16 | /** 17 | * 获取分页SQL. 18 | * @param sql 原始查询SQL 19 | * @param offset 开始记录索引(从0开始计算) 20 | * @param pageSize 每页记录大小 21 | * @return 返回数据库相关的分页SQL语句 22 | */ 23 | public abstract String getPageSql(String sql, long offset, long pageSize); 24 | } 25 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/Mysql5Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | /** 4 | * Title : Mysql5Dialect .
5 | * Description : Mysql数据库方言,目前实现了物理分页.
6 | *
7 | */ 8 | public class Mysql5Dialect implements Dialect { 9 | 10 | public String getPageSql(String sql, long offset, long pageSize) { 11 | return sql + " limit " + offset + "," + pageSize; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/OracleDialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | /** 4 | * Title : OracleDialect .
5 | * Description : Oracle数据库方言,目前实现了物理分页.
6 | *
7 | */ 8 | public class OracleDialect implements Dialect { 9 | 10 | public String getPageSql(String sql, long offset, long pageSize) { 11 | StringBuffer pagingSelect = new StringBuffer(sql.length() + 100); 12 | pagingSelect.append(" select * from ( select row_.*, rownum rownum_ from ( ") 13 | .append(sql) 14 | .append(" ) row_ ) where rownum_ > ") 15 | .append(offset) 16 | .append(" and rownum_ <= ") 17 | .append(offset + pageSize); 18 | return pagingSelect.toString(); 19 | } 20 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/PageContext.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | public class PageContext extends Page { 4 | 5 | private static final long serialVersionUID = 1L; 6 | private static ThreadLocal context = new ThreadLocal(); 7 | 8 | /** 9 | * 将构造方法设置为私有 10 | */ 11 | private PageContext() { 12 | } 13 | 14 | public static PageContext getContext() { 15 | return getContext(null); 16 | } 17 | 18 | public static PageContext getContext(Page page) { 19 | PageContext ci = context.get(); 20 | if (ci == null) { 21 | ci = new PageContext(); 22 | ci.setPage(page); 23 | context.set(ci); 24 | } 25 | return ci; 26 | } 27 | 28 | public static void removeContext() { 29 | context.remove(); 30 | } 31 | 32 | protected void initialize() { 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/herol/util/page/PageList.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herol.util.page; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 翻页列表 7 | */ 8 | public class PageList implements java.io.Serializable { 9 | 10 | private List objectList; 11 | private Page page; 12 | private static final long serialVersionUID = 1L; 13 | 14 | public PageList(Page page) { 15 | PageContext pageContext = PageContext.getContext(); 16 | pageContext.setPage(page); 17 | pageContext.setPagination(true); 18 | this.page = pageContext; 19 | } 20 | 21 | 22 | public List getObjectList() { 23 | return objectList; 24 | } 25 | 26 | public void setObjectList(List objectList) { 27 | this.objectList = objectList; 28 | } 29 | 30 | public Page getPage() { 31 | return page; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/java/com/hjc/pay/client/pay/IPay.java: -------------------------------------------------------------------------------- 1 | package com.hjc.pay.client.pay; 2 | 3 | /** 4 | * @ClassName: IPay 5 | * @Description: 支付接口,由支付服务器实现 6 | * @author 何金成 7 | * @date 2016年4月28日 下午5:03:20 8 | * 9 | */ 10 | public interface IPay { 11 | public long generateOrder(Pay pay); 12 | 13 | public Pay queryOrder(long billno); 14 | 15 | public boolean sendGoods(long billno,boolean success); 16 | 17 | public int queryPaySum(long userid); 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 导入applicationContext文件列表 6 | 7 | 8 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/csv/Hero.csv: -------------------------------------------------------------------------------- 1 | 英雄id,英雄名字,生命,物理攻击,物理防御,法术攻击,法术防御,暴击率,暴击,吸血 2 | HeroId,HeroName,Hp,WuliAttack,WuliDefence,FashuAttack,FashuDefence,BaojiLv,Baoji,Blood 3 | 1,无极剑圣,1000,100,100,100,100,30,100,100 4 | 2,寒冰射手,800,400,400,100,100,40,100,100 5 | 3,武器大师,1200,200,200,100,100,30,100,200 6 | 4,狂暴之心,1000,200,200,400,400,40,100,80 7 | 5,暗影猎手,800,400,400,100,100,40,100,80 8 | 6,冰霜女巫,1000,100,100,400,400,10,100,80 9 | 7,疾风剑豪,800,200,200,100,100,30,100,400 10 | 8,诅咒巨魔,1200,200,200,100,100,10,100,400 11 | 9,德玛西亚,1200,200,200,100,100,20,100,80 12 | 10,暗裔剑魔,800,200,200,100,100,10,100,80 13 | 11,复仇焰魂,600,100,100,400,400,10,100,80 14 | 12,不祥之刃,600,100,100,400,400,10,100,80 15 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/csv/Treasure.csv: -------------------------------------------------------------------------------- 1 | 宝箱类型,宝箱名字,卡牌1,卡牌2,卡牌3 2 | type,name,hero1,hero2,hero3 3 | 1,木制宝箱,1,2,0 4 | 2,白银宝箱,3,4,0 5 | 3,黄金宝箱,5,6,7 6 | 4,超级宝箱,8,9,10 7 | 5,至尊宝箱,10,11,12 8 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/dataConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/datasource.properties: -------------------------------------------------------------------------------- 1 | ######################################################## 2 | jdbc.url=jdbc:mysql://123.57.211.130:3306/herol?useUnicode=true&characterEncoding=utf-8 3 | jdbc.user=root 4 | jdbc.password=123456 5 | 6 | jdbc.initialSize=1 7 | jdbc.maxActive=10 8 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console,dailyFile 2 | # 控制台(console) 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.Threshold=INFO 5 | log4j.appender.console.ImmediateFlush=true 6 | log4j.appender.console.Target=System.out 7 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 9 | # 每天产生一个日志文件(dailyFile) 10 | log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender 11 | #当天的日志文件全路径 12 | log4j.appender.dailyFile.File=/data/log/herol/herol.log 13 | #服务器启动日志是追加,false:服务器启动后会生成日志文件把老的覆盖掉 14 | log4j.appender.dailyFile.Append=true 15 | #日志文件格式 16 | log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.dailyFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 18 | log4j.appender.dailyFile.Threshold=INFO 19 | #设置每天生成一个文件名后添加的名称,备份名称:年月日.log 20 | log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd'.log' -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/net.properties: -------------------------------------------------------------------------------- 1 | # local server 2 | port = 8586 3 | ip=127.0.0.1 4 | # pvp server 5 | pvpIp=127.0.0.1 6 | pvpPort=8400 7 | # task 8 | handleTaskQueueCapacity=1000 9 | handleTaskCorePoolSize=10 10 | handleTaskMaxPoolSize=30 11 | handleTaskKeepAliveSeconds=300 -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/server.properties: -------------------------------------------------------------------------------- 1 | serverId = 1 2 | pvpIp = 127.0.0.1 3 | pvpPort = 8400 4 | loginServer = 127.0.0.1 5 | loginPort = 81 6 | redisServer = 123.57.211.130:6444 7 | redisPwd = 123456 8 | cacheServer = 123.57.211.130:11211 -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/spring-email/applicationContext-email.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | true 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/spring-mongodb/mongo operate.txt: -------------------------------------------------------------------------------- 1 | mongo集群配置:http://www.lanceyan.com/tech/mongodb/mongodb_cluster_1.html 2 | mongo java api:http://api.mongodb.org/java/3.1/ 3 | mongo 高级查询示例: 4 | http://blog.csdn.net/maosijunzi/article/details/42100535 5 | http://blog.csdn.net/tujiyue/article/details/6437821 6 | -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/spring-mongodb/mongodb.properties: -------------------------------------------------------------------------------- 1 | #ip和端口,多个主机用&相连 2 | db.host=123.57.211.130:27017 3 | #数据库名字 4 | db.database=war 5 | #用户名 6 | db.username=hjc 7 | #密码 8 | db.password=123321 9 | #每个主机的最大连接数 10 | db.connectionsPerHost=50 11 | #线程允许最大等待连接数 12 | db.threadsAllowedToBlockForConnectionMultiplier=50 13 | #连接超时时间1分钟 14 | db.connectTimeout=60000 15 | #一个线程访问数据库的时候,在成功获取到一个可用数据库连接之前的最长等待时间为2分钟 16 | #这里比较危险,如果超过maxWaitTime都没有获取到这个连接的话,该线程就会抛出Exception 17 | #故这里设置的maxWaitTime应该足够大,以免由于排队线程过多造成的数据库访问失败 18 | db.maxWaitTime=120000 -------------------------------------------------------------------------------- /第九章/herol/src/main/resources/spring-redis/redis.properties: -------------------------------------------------------------------------------- 1 | #\u6700\u5927\u5206\u914d\u7684\u5bf9\u8c61\u6570 2 | redis.pool.maxActive=1024 3 | #\u6700\u5927\u80fd\u591f\u4fdd\u6301idel\u72b6\u6001\u7684\u5bf9\u8c61\u6570 4 | redis.pool.maxIdle=200 5 | #\u5f53\u6c60\u5185\u6ca1\u6709\u8fd4\u56de\u5bf9\u8c61\u65f6\uff0c\u6700\u5927\u7b49\u5f85\u65f6\u95f4 6 | redis.pool.maxWait=1000 7 | #\u5f53\u8c03\u7528borrow Object\u65b9\u6cd5\u65f6\uff0c\u662f\u5426\u8fdb\u884c\u6709\u6548\u6027\u68c0\u67e5 8 | redis.pool.testOnBorrow=true 9 | #IP 10 | #redis.ip=192.168.6.66 11 | redis.ip=123.57.211.130 12 | #redis.ip=redis.ha.cmcc 13 | #Port 14 | redis.port=6379 -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/WEB-INF/Spring MVC Dispatcher Servlet-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/WdatePicker.css: -------------------------------------------------------------------------------- 1 | .Wdate{ 2 | border:#999 1px solid; 3 | height:20px; 4 | background:#fff url(datePicker.gif) no-repeat right; 5 | } 6 | 7 | .WdateFmtErr{ 8 | font-weight:bold; 9 | color:red; 10 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/admin/style.css: -------------------------------------------------------------------------------- 1 | 2 | *{margin:0;padding:0;} 3 | .top{width:100%;height:60px;background-color:#c3bdfc;} 4 | .logo{width:15%;height:100%;float:left;background-color:#746cb9;} 5 | .title{width:15%;height:100%;float:right;background-color:#a09db9;} 6 | 7 | .main{clear:both;min-height:81%;} 8 | .left{width:15%;height:81%;float:left;background-color:#cfd7e0;overflow:auto;} 9 | .right{width:85%;height:81%;float:right;display:block;background-color:#f8fafd;overflow:auto;} 10 | 11 | .foot{width:100%;height:10%;background-color:#d1cdd1;clear:both;} 12 | 13 | -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/icomoon.eot -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/icomoon.ttf -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/css/fonts/icomoon.woff -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/scroll.css: -------------------------------------------------------------------------------- 1 | ::-webkit-scrollbar { 2 | width: 1.2%; 3 | } 4 | 5 | /* 滚动槽*/ 6 | ::-webkit-scrollbar-track { 7 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0); 8 | border-radius: 10px; 9 | filter:alpha(opacity=80); 10 | 11 | } 12 | 13 | /* 滚动条滑块 */ 14 | ::-webkit-scrollbar-thumb { 15 | border-radius: 10px; 16 | background: rgba(0,0,0,0.1); 17 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/tablestyle.css: -------------------------------------------------------------------------------- 1 | 2 | /* Table 1 Style */ 3 | table{ 4 | font-size:14px; 5 | } 6 | table td{ 7 | padding:5px; 8 | margin:5px; 9 | } 10 | input{ 11 | height:30px; 12 | } 13 | .btn 14 | { 15 | border: none; 16 | background-color: #615c8d; 17 | color: #fff; 18 | border-radius: 4px; 19 | padding: 1px 8px; 20 | font-size: 14px; 21 | text-align: center; 22 | margin:10px; 23 | width:100px; 24 | height:30px; 25 | } -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/css/tips.css: -------------------------------------------------------------------------------- 1 | /* 提示页面 */ 2 | .tips { 3 | padding: 0 20px; 4 | height: 35px; 5 | background-color: #000; 6 | margin: 0 auto; 7 | filter: alpha(opacity=60); 8 | opacity: 0.6; 9 | line-height: 35px; 10 | font-size: 1.6rem; 11 | text-align: center; 12 | color: #fff; 13 | -moz-border-radius: 0.5rem; 14 | -webkit-border-radius: 0.5rem; 15 | border-radius: 0.5rem; 16 | font-size:1.1rem; 17 | } 18 | -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/js/admin/login.js: -------------------------------------------------------------------------------- 1 | function login(){ 2 | if($("#loginname").val() == null || $("#loginname").val() == "" ){ 3 | alert('用户名不能为空'); 4 | return; 5 | } 6 | if($("#password").val() == null || $("#password").val() == "" ){ 7 | alert('密码不能为空'); 8 | return; 9 | } 10 | var datas={ 11 | name:$("#loginname").val(), 12 | pwd:$("#password").val() 13 | } 14 | $.ajax({ 15 | data : datas, 16 | type : "POST", 17 | dataType : "text", 18 | url : "../admin/loginHandle", 19 | success : function(data) { 20 | console.log(data); 21 | if (data == "success") { 22 | location.href="../admin/index "; 23 | } else { 24 | alert("登录失败"); 25 | } 26 | }, 27 | error : function(result) { 28 | alert("登录失败"); 29 | } 30 | }); 31 | } 32 | 33 | //enter键触发登录功能 34 | document.onkeydown=function(event){ 35 | var e = event || window.event || arguments.callee.caller.arguments[0]; 36 | if(e && e.keyCode==13){ // enter 键 37 | login(); 38 | } 39 | }; -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/js/admin/menu.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(e) { 2 | 3 | /*左侧多级菜单*/ 4 | $(".page-sidebar-menu>li>a").click(function(e) { 5 | $(this).parent().children(".sub-menu").toggle(); 6 | $(this).children("span.arrow").toggleClass("open"); 7 | }); 8 | 9 | /*二级菜单点击样式*/ 10 | $(".sub-menu>li").click(function(e) { 11 | //给二级菜单添加样式 12 | $(this).addClass("active").siblings().removeClass("active"); 13 | //给一级菜单添加样式 14 | $(this).parent().parent().addClass("active").children("a").children("span").first().after(""); 15 | //取消其他一级菜单以及二级菜单样式 16 | $(this).parent().parent().siblings().removeClass("active").children(".sub-menu").hide().children("li").removeClass("active").parent().parent().children("a").children("span.arrow").removeClass("open"); 17 | }); 18 | 19 | $(".nav>li").click(function(e) { 20 | $(this).addClass("active").siblings().removeClass("active"); 21 | }); 22 | 23 | $(".mix-filter>li").click(function(e) { 24 | $(this).addClass("active").siblings().removeClass("active"); 25 | }); 26 | }); -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/js/config.js: -------------------------------------------------------------------------------- 1 | var langList = 2 | [ 3 | {name:'en', charset:'UTF-8'}, 4 | {name:'zh-cn', charset:'UTF-8'}, 5 | {name:'zh-tw', charset:'UTF-8'} 6 | ]; 7 | 8 | var skinList = 9 | [ 10 | {name:'default', charset:'UTF-8'}, 11 | {name:'whyGreen', charset:'UTF-8'} 12 | ]; -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/uploadify/uploadify-cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/uploadify/uploadify-cancel.png -------------------------------------------------------------------------------- /第九章/herol/src/main/webapp/uploadify/uploadify.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herol/src/main/webapp/uploadify/uploadify.swf -------------------------------------------------------------------------------- /第九章/herol/src/test/java/httptest/HttpClientHandler.java: -------------------------------------------------------------------------------- 1 | package httptest; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandlerAdapter; 6 | import io.netty.handler.codec.http.HttpContent; 7 | import io.netty.handler.codec.http.HttpHeaders; 8 | import io.netty.handler.codec.http.HttpResponse; 9 | 10 | public class HttpClientHandler extends ChannelInboundHandlerAdapter { 11 | @Override 12 | public void channelRead(ChannelHandlerContext ctx, Object msg) 13 | throws Exception { 14 | if (msg instanceof HttpResponse) { 15 | HttpResponse response = (HttpResponse) msg; 16 | System.out.println("CONTENT_TYPE:" 17 | + response.headers().get(HttpHeaders.Names.CONTENT_TYPE)); 18 | } 19 | if (msg instanceof HttpContent) { 20 | HttpContent content = (HttpContent) msg; 21 | ByteBuf buf = content.content(); 22 | System.out.println(buf.toString(io.netty.util.CharsetUtil.UTF_8)); 23 | buf.release(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第九章/herolclient/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /第九章/herolclient/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | herolclient 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /第九章/herolclient/libs/fastjson-1.1.36.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolclient/libs/fastjson-1.1.36.jar -------------------------------------------------------------------------------- /第九章/herolclient/libs/netty-all-5.0.0.Alpha1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolclient/libs/netty-all-5.0.0.Alpha1.jar -------------------------------------------------------------------------------- /第九章/herolclient/libs/slf4j-api-1.7.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolclient/libs/slf4j-api-1.7.2.jar -------------------------------------------------------------------------------- /第九章/herolclient/src/com/hjc/net/LogicProtoIds.java: -------------------------------------------------------------------------------- 1 | package com.hjc.net; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 8 | * @ClassName: ProtoIds 9 | * @Description: 存储协议号,添加协议号时,既要定义静态常量的协议号,也要在init方法中调用regist注册,方便协议号的管理 10 | * @author 何金成 11 | * @date 2015年5月23日 下午4:34:41 12 | * 13 | */ 14 | public class LogicProtoIds { 15 | public static Map protoClassMap = new HashMap();// 协议号-类名map存储 16 | public static Map classProtoMap = new HashMap();// 类名-协议号map存储 17 | 18 | // 初始化 19 | public static void init() { 20 | // 协议初始化 21 | // regist(C_LOGIN_REQ, LoginReq.class.getName()); 22 | // regist(S_LOGIN_RESP, LoginResp.class.getName()); 23 | } 24 | 25 | /** 登录请求 **/ 26 | public static final short TEST = 10000; 27 | public static final short GET_PVP_SERVER = 10001; 28 | public static final short CREATE_ROLE = 1;// 创建角色 29 | public static final short HERO_PICK = 2;// 抽取英雄 30 | 31 | public static void regist(int protoId, String className) { 32 | protoClassMap.put(protoId, className); 33 | classProtoMap.put(className, protoId); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /第九章/herolclient/src/com/hjc/net/PvpProtoIds.java: -------------------------------------------------------------------------------- 1 | package com.hjc.net; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 8 | * @ClassName: ProtoIds 9 | * @Description: 存储协议号,添加协议号时,既要定义静态常量的协议号,也要在init方法中调用regist注册,方便协议号的管理 10 | * @author 何金成 11 | * @date 2015年5月23日 下午4:34:41 12 | * 13 | */ 14 | public class PvpProtoIds { 15 | public static Map protoClassMap = new HashMap();// 协议号-类名map存储 16 | public static Map classProtoMap = new HashMap();// 类名-协议号map存储 17 | 18 | // 初始化 19 | public static void init() { 20 | // 协议初始化 21 | // regist(C_LOGIN_REQ, LoginReq.class.getName()); 22 | // regist(S_LOGIN_RESP, LoginResp.class.getName()); 23 | } 24 | 25 | /** 登录请求 **/ 26 | public static final short TEST = 10000; 27 | public static final short EXIT_SCENE = 10002; 28 | public static final short FIGHT_ENTER_SCENE = 1;// 进入游戏场景 29 | public static final short FIGHT_SKILL = 2;// 释放技能 30 | 31 | public static void regist(int protoId, String className) { 32 | protoClassMap.put(protoId, className); 33 | classProtoMap.put(className, protoId); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /第九章/herolclient/src/com/hjc/net/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.hjc.net; 2 | 3 | public class ResultCode { 4 | public static final int SUCCESS = 100;// 成功 5 | public static final int COMMON_ERR = 101;// 默认错误 6 | public static final int DB_ERR = 102;// 数据库错误 7 | public static final int PARAM_ERR = 103;// 参数错误 8 | public static final int COIN_ERR = 104;// 金币不足 9 | public static final int YUANBAO_ERR = 105;// 元宝不足 10 | public static final int JIANGHUN_ERR = 106;// 将魂不足 11 | public static final int JUN_GONG_ERR = 107;// 军功不足 12 | public static final int IRON_ERR = 108;// 精铁不足 13 | public static final int FOOD_ERR = 109;// 粮食不足 14 | public static final int VIP_ERR = 110;// vip不足 15 | public static final int HCZS_ERR = 111;// 强征次数不足 16 | public static final int CANGKU_COIN_ERR = 112;// 仓库银两已满 17 | public static final int CANGKU_FOOD_ERR = 113;// 仓库粮食已满 18 | public static final int SERVER_ERR = 500;// 服务器内部错误 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herolpvp/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/core/CoreServlet.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.core; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.ServletRequest; 7 | import javax.servlet.ServletResponse; 8 | import javax.servlet.http.HttpServlet; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | public class CoreServlet extends HttpServlet { 14 | private static final long serialVersionUID = -2082543656440562457L; 15 | public static final Logger logger = LoggerFactory 16 | .getLogger(CoreServlet.class); 17 | 18 | @Override 19 | public void service(ServletRequest req, ServletResponse res) 20 | throws ServletException, IOException { 21 | logger.info("servlet service"); 22 | } 23 | 24 | @Override 25 | public void destroy() { 26 | logger.info("CoreServelet destroy"); 27 | GameInit.shutdown();// 通知服务器关服 28 | } 29 | 30 | @Override 31 | public void init() throws ServletException { 32 | logger.info("CoreServelet init"); 33 | GameInit.init();// 初始化游戏服务器 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/core/GameServer.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.core; 2 | 3 | import com.hjc.herolpvp.net.socket.SocketServer; 4 | 5 | public class GameServer { 6 | public static volatile boolean shutdown = false; 7 | private static GameServer server; 8 | 9 | private GameServer() { 10 | } 11 | 12 | public static GameServer getInstance() { 13 | if (null == server) { 14 | server = new GameServer(); 15 | } 16 | return server; 17 | } 18 | 19 | /** 20 | * @Title: startServer 21 | * @Description: 开启服务器 22 | * @throws 23 | */ 24 | public void startServer() { 25 | SocketServer.getInstance().start(); 26 | shutdown = false; 27 | } 28 | 29 | /** 30 | * @Title: shutServer 31 | * @Description: 关闭服务器 32 | * @throws 33 | */ 34 | public void shutServer() { 35 | SocketServer.getInstance().shut(); 36 | shutdown = true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/manager/event/Event.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.manager.event; 2 | 3 | /** 4 | * @author 康建虎 5 | * 6 | */ 7 | public class Event { 8 | public int id; 9 | public Object param; 10 | } 11 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/manager/event/EventProc.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.manager.event; 2 | 3 | /** 4 | * 事件处理器。 5 | * 6 | * @author 何金成 7 | * 8 | */ 9 | public abstract class EventProc { 10 | public boolean disable; 11 | 12 | public EventProc() { 13 | doReg(); 14 | } 15 | 16 | public abstract void proc(Event param); 17 | 18 | protected abstract void doReg(); 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net; 2 | 3 | public class ResultCode { 4 | public static final int SUCCESS = 100;// 成功 5 | public static final int COMMON_ERR = 101;// 默认错误 6 | public static final int DB_ERR = 102;// 数据库错误 7 | public static final int PARAM_ERR = 103;// 参数错误 8 | public static final int ENTER_PVP = 200;// 进入对战场景 9 | public static final int SERVER_ERR = 500;// 服务器内部错误 10 | } 11 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/http/HttpOutHandler.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net.http; 2 | 3 | import io.netty.channel.ChannelHandlerAdapter; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelPromise; 6 | 7 | public class HttpOutHandler extends ChannelHandlerAdapter { 8 | 9 | public HttpOutHandlerImp handler = new HttpOutHandlerImp(); 10 | 11 | @Override 12 | public void write(ChannelHandlerContext ctx, Object msg, 13 | ChannelPromise promise) throws Exception { 14 | super.write(ctx, msg, promise); 15 | handler.write(ctx, msg, promise); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/http/HttpOutHandlerImp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net.http; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.hjc.herolpvp.util.Constants; 9 | 10 | import io.netty.buffer.ByteBuf; 11 | import io.netty.buffer.ByteBufUtil; 12 | import io.netty.buffer.Unpooled; 13 | import io.netty.buffer.UnpooledUnsafeDirectByteBuf; 14 | import io.netty.channel.ChannelHandlerContext; 15 | import io.netty.channel.ChannelPromise; 16 | import io.netty.handler.codec.http.DefaultFullHttpResponse; 17 | import io.netty.handler.codec.http.HttpHeaders; 18 | 19 | public class HttpOutHandlerImp { 20 | public Logger logger = LoggerFactory.getLogger(HttpOutHandlerImp.class); 21 | 22 | public void write(ChannelHandlerContext ctx, Object msg, 23 | ChannelPromise promise) throws Exception { 24 | if (Constants.MSG_LOG_DEBUG) { 25 | DefaultFullHttpResponse resp = (DefaultFullHttpResponse) msg; 26 | logger.info("ip:{},write:{}", ctx.channel().remoteAddress(), resp 27 | .content().toString(Charset.forName("UTF-8"))); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/http/SessionKey.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net.http; 2 | 3 | import com.hjc.herolpvp.core.GameInit; 4 | 5 | public class SessionKey { 6 | public static final String CACHE_ONLINE = "online_" + GameInit.serverId 7 | + "_"; 8 | } 9 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/socket/ChannelAttKey.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net.socket; 2 | 3 | public class ChannelAttKey { 4 | public static final String JUNZHU_ID = "junZhuId"; 5 | public static final String CHANNEL_ID = "channelId"; 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/net/socket/ChannelUser.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.net.socket; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | public class ChannelUser { 6 | public String channelId; 7 | public Long userid; 8 | public Channel channel; 9 | } 10 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/task/DailyTaskService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.task; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * @ClassName: DailyTask 8 | * @Description: 每日定时任务 9 | * @author 何金成 10 | * @date 2016年3月30日 下午4:57:35 11 | * 12 | */ 13 | public class DailyTaskService { 14 | public static Logger logger = LoggerFactory 15 | .getLogger(DailyTaskService.class); 16 | 17 | public void pkDailyAwardMail() { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/task/ExecutorPool.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.task; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /** 10 | * @ClassName: ExecutorPool 11 | * @Description: 线程池管理 12 | * @author 何金成 13 | * @date 2016年4月18日 下午3:42:42 14 | * 15 | */ 16 | public class ExecutorPool { 17 | public static ExecutorService channelHandleThreadPool = null; 18 | 19 | public Logger logger = LoggerFactory.getLogger(ExecutorPool.class); 20 | 21 | public static void initThreadsExecutor() { 22 | channelHandleThreadPool = Executors.newCachedThreadPool(); 23 | } 24 | 25 | public static void execute(Runnable runnable) { 26 | channelHandleThreadPool.execute(runnable); 27 | } 28 | 29 | public static void shutdown() { 30 | if (!channelHandleThreadPool.isShutdown()) { 31 | channelHandleThreadPool.shutdown(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/task/TaskService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.task; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.core.task.TaskExecutor; 7 | import org.springframework.scheduling.annotation.Scheduled; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @ClassName: DailyTask 12 | * @Description: 每日定时任务 13 | * @author 何金成 14 | * @date 2016年3月30日 下午4:57:35 15 | * 16 | */ 17 | @Service 18 | public class TaskService { 19 | @Autowired 20 | private TaskExecutor executor; 21 | public Logger logger = LoggerFactory.getLogger(TaskService.class); 22 | private static DailyTaskService dailyTaskService = new DailyTaskService(); 23 | 24 | @Scheduled(cron = "0 0 22 * * ? ") 25 | public void pkDailyAwardMail() { 26 | executor.execute(new Runnable() { 27 | public void run() { 28 | dailyTaskService.pkDailyAwardMail(); 29 | } 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/AppContext.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | import org.springframework.context.support.AbstractApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class AppContext { 7 | 8 | private static AppContext instance; 9 | 10 | private AbstractApplicationContext appContext; 11 | 12 | public synchronized static AppContext getInstance() { 13 | if (instance == null) { 14 | instance = new AppContext(); 15 | } 16 | return instance; 17 | } 18 | 19 | private AppContext() { 20 | this.appContext = new ClassPathXmlApplicationContext( 21 | "/applicationContext.xml"); 22 | } 23 | 24 | public AbstractApplicationContext getAppContext() { 25 | return appContext; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | public class Constants { 4 | public static final String MD5_KEY = "blog"; 5 | public static final int COMMON_PAGE_SIZE = 10; 6 | /**日志记录配置**/ 7 | public static boolean SDK_DEBUG = true; 8 | public static boolean MSG_LOG_DEBUG = true; 9 | public static boolean CLIENT_DEBUG = true; 10 | } 11 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/HMACSHA1.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | import java.security.InvalidKeyException; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | import javax.crypto.Mac; 13 | import javax.crypto.spec.SecretKeySpec; 14 | 15 | import com.hjc.herolpvp.util.encrypt.Md5Coder; 16 | 17 | public class HMACSHA1 { 18 | private static final String HMAC_SHA1 = "HmacSHA1"; 19 | 20 | /** 21 | * 生成签名数据 22 | * 23 | * @param data 待加密的数据 24 | * @param key 加密使用的key 25 | * @return 生成MD5编码的字符串 26 | * @throws InvalidKeyException 27 | * @throws NoSuchAlgorithmException 28 | */ 29 | public static String getSignature(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { 30 | SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1); 31 | Mac mac = Mac.getInstance(HMAC_SHA1); 32 | mac.init(signingKey); 33 | byte[] rawHmac = mac.doFinal(data); 34 | return Md5Coder.encodeByMD5(new String(rawHmac)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | public class IOUtil { 11 | public static final InputStream byte2Input(byte[] buf) { 12 | return new ByteArrayInputStream(buf); 13 | } 14 | 15 | public static final byte[] input2byte(InputStream inStream) 16 | throws IOException { 17 | ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); 18 | byte[] buff = new byte[100]; 19 | int rc = 0; 20 | while ((rc = inStream.read(buff, 0, 100)) > 0) { 21 | swapStream.write(buff, 0, rc); 22 | } 23 | byte[] in2b = swapStream.toByteArray(); 24 | return in2b; 25 | } 26 | 27 | // public static final ByteBuf strToByteBuf(String str){ 28 | // ByteBuf buf = new 29 | // } 30 | } 31 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/PatternMatcher.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | public interface PatternMatcher { 4 | 5 | boolean matches(String pattern, String source); 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util; 2 | 3 | public class StringUtils { 4 | 5 | public static String getCutString(String str){ 6 | return getCutString(str,10); 7 | } 8 | public static String getCutString(String str,int len){ 9 | if(len<=1) len=1; 10 | if(null ==str){ 11 | return ""; 12 | } 13 | if(str.length()<=len){ 14 | return str; 15 | }else{ 16 | return str.subSequence(0, len-1)+"..."; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/cache/CacheKeys.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.cache; 2 | 3 | public class CacheKeys { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/cache/MCSupport.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.cache; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 实现此接口后还需要再MC类中增加cachedClass,并使用 7 | * com.qx.persistent.HibernateUtil.find(Class, long) 8 | * 代替where进行查询。 9 | * 需要对控制了的对象在第一次存库时调用MC.add,再调用HIbernateUtil.insert 10 | * @author 何金成 11 | * 12 | */ 13 | public interface MCSupport extends Serializable{ 14 | long getIdentifier(); 15 | } 16 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/cache/SerializeUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.cache; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectOutputStream; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * @author 康建虎 14 | * 15 | */ 16 | public class SerializeUtil { 17 | private static Logger log = LoggerFactory.getLogger(SerializeUtil.class); 18 | public static byte[] encode(Object o) throws IOException{ 19 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 20 | ObjectOutputStream os = new ObjectOutputStream(bos); 21 | os.writeObject(o); 22 | os.close(); 23 | bos.close(); 24 | byte[] arr = bos.toByteArray(); 25 | return arr; 26 | } 27 | public static T decode(byte[] data) throws IOException{ 28 | ByteArrayInputStream bis = new ByteArrayInputStream(data); 29 | ObjectInputStream ois = new ObjectInputStream(bis); 30 | Object o = null; 31 | try{ 32 | o = ois.readObject(); 33 | }catch(ClassNotFoundException e){ 34 | log.error("解析失败", e); 35 | } 36 | return (T)o; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/context/SpringInit.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.context; 2 | import javax.servlet.ServletContextEvent; 3 | import javax.servlet.ServletContextListener; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.web.context.WebApplicationContext; 6 | import org.springframework.web.context.support.WebApplicationContextUtils; 7 | public class SpringInit implements ServletContextListener { 8 | 9 | private static WebApplicationContext springContext; 10 | 11 | public SpringInit() { 12 | super(); 13 | } 14 | 15 | public void contextInitialized(ServletContextEvent event) { 16 | springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); 17 | } 18 | 19 | public void contextDestroyed(ServletContextEvent event) { 20 | } 21 | 22 | public static ApplicationContext getApplicationContext() { 23 | return springContext; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/mongo/MainTest.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.mongo; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.lang.reflect.Field; 8 | import java.net.HttpURLConnection; 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | 12 | import com.hjc.herolpvp.util.HttpClient; 13 | 14 | public class MainTest { 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/mongo/MongoCollections.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.mongo; 2 | 3 | public class MongoCollections { 4 | public static final String USER_DATA = "user_data"; 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/mongo/SubBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.mongo; 2 | 3 | public class SubBean { 4 | private Long id; 5 | private String str; 6 | 7 | public String getStr() { 8 | return str; 9 | } 10 | 11 | public void setStr(String str) { 12 | this.str = str; 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/mongo/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.mongo; 2 | 3 | import java.util.List; 4 | 5 | public class TestBean { 6 | private Long id; 7 | private String msg; 8 | private Double score; 9 | private SubBean subBean; 10 | private List subBeans; 11 | 12 | public Long getId() { 13 | return id; 14 | } 15 | 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | 20 | public String getMsg() { 21 | return msg; 22 | } 23 | 24 | public void setMsg(String msg) { 25 | this.msg = msg; 26 | } 27 | 28 | public Double getScore() { 29 | return score; 30 | } 31 | 32 | public void setScore(Double score) { 33 | this.score = score; 34 | } 35 | 36 | public SubBean getSubBean() { 37 | return subBean; 38 | } 39 | 40 | public void setSubBean(SubBean subBean) { 41 | this.subBean = subBean; 42 | } 43 | 44 | public List getSubBeans() { 45 | return subBeans; 46 | } 47 | 48 | public void setSubBeans(List subBeans) { 49 | this.subBeans = subBeans; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/DB2Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | /** 4 | * Title : DB2Dialect .
5 | * Description : DB2数据方言,目前实现了物理分页.
6 | */ 7 | public class DB2Dialect implements Dialect { 8 | 9 | public String getPageSql(String sql, long offset, long limit) { 10 | sql = sql.trim(); 11 | StringBuffer pagingSelect = new StringBuffer(sql.length() + 100); 12 | pagingSelect.append(" SELECT * FROM (SELECT PAGE_B.*, ROWNUMBER() OVER() AS RN FROM ( "); 13 | pagingSelect.append(sql); 14 | pagingSelect.append(" ) AS PAGE_B )AS PAGE_A WHERE PAGE_A.RN BETWEEN ").append(offset).append(" AND ") 15 | .append(offset + limit - 1); 16 | return pagingSelect.toString(); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | /** 4 | * Title : Dialect .
5 | * Description : 数据库方言接口.
6 | *
7 | */ 8 | public interface Dialect { 9 | 10 | public static enum Type{ 11 | MYSQL, 12 | ORACLE, 13 | DB2 14 | } 15 | 16 | /** 17 | * 获取分页SQL. 18 | * @param sql 原始查询SQL 19 | * @param offset 开始记录索引(从0开始计算) 20 | * @param pageSize 每页记录大小 21 | * @return 返回数据库相关的分页SQL语句 22 | */ 23 | public abstract String getPageSql(String sql, long offset, long pageSize); 24 | } 25 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/Mysql5Dialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | /** 4 | * Title : Mysql5Dialect .
5 | * Description : Mysql数据库方言,目前实现了物理分页.
6 | *
7 | */ 8 | public class Mysql5Dialect implements Dialect { 9 | 10 | public String getPageSql(String sql, long offset, long pageSize) { 11 | return sql + " limit " + offset + "," + pageSize; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/OracleDialect.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | /** 4 | * Title : OracleDialect .
5 | * Description : Oracle数据库方言,目前实现了物理分页.
6 | *
7 | */ 8 | public class OracleDialect implements Dialect { 9 | 10 | public String getPageSql(String sql, long offset, long pageSize) { 11 | StringBuffer pagingSelect = new StringBuffer(sql.length() + 100); 12 | pagingSelect.append(" select * from ( select row_.*, rownum rownum_ from ( ") 13 | .append(sql) 14 | .append(" ) row_ ) where rownum_ > ") 15 | .append(offset) 16 | .append(" and rownum_ <= ") 17 | .append(offset + pageSize); 18 | return pagingSelect.toString(); 19 | } 20 | } -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/PageContext.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | public class PageContext extends Page { 4 | 5 | private static final long serialVersionUID = 1L; 6 | private static ThreadLocal context = new ThreadLocal(); 7 | 8 | /** 9 | * 将构造方法设置为私有 10 | */ 11 | private PageContext() { 12 | } 13 | 14 | public static PageContext getContext() { 15 | return getContext(null); 16 | } 17 | 18 | public static PageContext getContext(Page page) { 19 | PageContext ci = context.get(); 20 | if (ci == null) { 21 | ci = new PageContext(); 22 | ci.setPage(page); 23 | context.set(ci); 24 | } 25 | return ci; 26 | } 27 | 28 | public static void removeContext() { 29 | context.remove(); 30 | } 31 | 32 | protected void initialize() { 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/java/com/hjc/herolpvp/util/page/PageList.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolpvp.util.page; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 翻页列表 7 | */ 8 | public class PageList implements java.io.Serializable { 9 | 10 | private List objectList; 11 | private Page page; 12 | private static final long serialVersionUID = 1L; 13 | 14 | public PageList(Page page) { 15 | PageContext pageContext = PageContext.getContext(); 16 | pageContext.setPage(page); 17 | pageContext.setPagination(true); 18 | this.page = pageContext; 19 | } 20 | 21 | 22 | public List getObjectList() { 23 | return objectList; 24 | } 25 | 26 | public void setObjectList(List objectList) { 27 | this.objectList = objectList; 28 | } 29 | 30 | public Page getPage() { 31 | return page; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 导入applicationContext文件列表 6 | 7 | 8 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/dataConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/datasource.properties: -------------------------------------------------------------------------------- 1 | ########################################################local 2 | jdbc.url=jdbc:mysql://123.57.211.130:3306/herol?useUnicode=true&characterEncoding=utf-8 3 | jdbc.user=root 4 | jdbc.password=123456 5 | 6 | jdbc.initialSize=1 7 | jdbc.maxActive=10 8 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console,dailyFile 2 | # 控制台(console) 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.Threshold=INFO 5 | log4j.appender.console.ImmediateFlush=true 6 | log4j.appender.console.Target=System.out 7 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 9 | # 每天产生一个日志文件(dailyFile) 10 | log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender 11 | #当天的日志文件全路径 12 | log4j.appender.dailyFile.File=/data/log/herol/herol.log 13 | #服务器启动日志是追加,false:服务器启动后会生成日志文件把老的覆盖掉 14 | log4j.appender.dailyFile.Append=true 15 | #日志文件格式 16 | log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.dailyFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 18 | log4j.appender.dailyFile.Threshold=INFO 19 | #设置每天生成一个文件名后添加的名称,备份名称:年月日.log 20 | log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd'.log' -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/net.properties: -------------------------------------------------------------------------------- 1 | # local server 2 | port = 8400 3 | ip=127.0.0.1 4 | # task 5 | handleTaskQueueCapacity=1000 6 | handleTaskCorePoolSize=10 7 | handleTaskMaxPoolSize=30 8 | handleTaskKeepAliveSeconds=300 -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/server.properties: -------------------------------------------------------------------------------- 1 | serverId = 1 2 | loginServer = 127.0.0.1 3 | loginPort = 81 4 | redisServer = 127.0.0.1:6444 5 | redisPwd = 123456 6 | cacheServer = 127.0.0.1:11211 7 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/spring-mongodb/mongo operate.txt: -------------------------------------------------------------------------------- 1 | mongo集群配置:http://www.lanceyan.com/tech/mongodb/mongodb_cluster_1.html 2 | mongo java api:http://api.mongodb.org/java/3.1/ 3 | mongo 高级查询示例: 4 | http://blog.csdn.net/maosijunzi/article/details/42100535 5 | http://blog.csdn.net/tujiyue/article/details/6437821 6 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/resources/spring-mongodb/mongodb.properties: -------------------------------------------------------------------------------- 1 | #ip和端口,多个主机用&相连 2 | db.host=123.57.211.130:27017 3 | #数据库名字 4 | db.database=war 5 | #用户名 6 | db.username=hjc 7 | #密码 8 | db.password=123321 9 | #每个主机的最大连接数 10 | db.connectionsPerHost=50 11 | #线程允许最大等待连接数 12 | db.threadsAllowedToBlockForConnectionMultiplier=50 13 | #连接超时时间1分钟 14 | db.connectTimeout=60000 15 | #一个线程访问数据库的时候,在成功获取到一个可用数据库连接之前的最长等待时间为2分钟 16 | #这里比较危险,如果超过maxWaitTime都没有获取到这个连接的话,该线程就会抛出Exception 17 | #故这里设置的maxWaitTime应该足够大,以免由于排队线程过多造成的数据库访问失败 18 | db.maxWaitTime=120000 -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/Spring MVC Dispatcher Servlet-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/admin/bottom.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 管理系统 9 | 10 | 11 | 12 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/admin/content.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 后台管理系统 8 | 9 | 10 |
 
11 |
12 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/admin/left.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 后台管理页面 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/admin/top.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 后台管理页面 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 退出登录 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ${user.nickname} 27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/403.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

403 Oops! Page Access 7 | Denied

8 |

错误提示:

9 | 10 |

11 | 该资源您没权限访问,请返回!!! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

404 Oops! Page Not 7 | Found

8 |

9 | 10 |

11 | 该资源不存在,请返回! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/405.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

405 Oops! unknown page 7 | error

8 |

错误提示:

9 | 10 |

11 | 发生未知错误,请联系管理员 或返回! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/500.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 | 3 |
4 | 5 | 6 | 15 | 16 |
7 |

500 Oops! Internal 8 | Server Error

9 |

错误提示:

10 | 11 |

12 | 服务器内部错误,请稍候再试!!!返回! 13 |

14 |
17 |
18 | <%@ include file="end.jsp" %> 19 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/end.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8"%> 2 | <%@page pageEncoding="UTF-8"%> 3 | 4 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/err.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 | 4 |
5 |
6 | 首页 7 |

异常页面

8 |
9 |
10 | <%-- <% Exception ex = (Exception)request.getAttribute("exception"); %> 11 |

Exception: <%= ex.getMessage()%>

12 |

13 | <%ex.printStackTrace(new java.io.PrintWriter(out)); %> --%> 14 | 系统出现异常了,请您点击左上角的首页返回到首页面,您可以在首页面中的反馈里面想管理员反映情况,谢谢您的使用 15 |

16 |
17 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/error.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 | 4 |
5 |
6 |

7 | 错误页面 8 |

9 |
10 |
11 | ${requestScope.error} 12 |
13 |
14 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/WEB-INF/views/common/upload_error.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 |
4 |
5 | 首页 6 |

上传异常

7 |
8 |
9 | 对不起,您上传的图片大小超过了我们规定的范围,请您上传50kb以内的图片 10 |
11 |
12 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/WdatePicker.css: -------------------------------------------------------------------------------- 1 | .Wdate{ 2 | border:#999 1px solid; 3 | height:20px; 4 | background:#fff url(datePicker.gif) no-repeat right; 5 | } 6 | 7 | .WdateFmtErr{ 8 | font-weight:bold; 9 | color:red; 10 | } -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/admin/style.css: -------------------------------------------------------------------------------- 1 | 2 | *{margin:0;padding:0;} 3 | .top{width:100%;height:60px;background-color:#c3bdfc;} 4 | .logo{width:15%;height:100%;float:left;background-color:#746cb9;} 5 | .title{width:15%;height:100%;float:right;background-color:#a09db9;} 6 | 7 | .main{clear:both;min-height:81%;} 8 | .left{width:15%;height:81%;float:left;background-color:#cfd7e0;overflow:auto;} 9 | .right{width:85%;height:81%;float:right;display:block;background-color:#f8fafd;overflow:auto;} 10 | 11 | .foot{width:100%;height:10%;background-color:#d1cdd1;clear:both;} 12 | 13 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/icomoon.eot -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/icomoon.ttf -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/css/fonts/icomoon.woff -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/scroll.css: -------------------------------------------------------------------------------- 1 | ::-webkit-scrollbar { 2 | width: 1.2%; 3 | } 4 | 5 | /* 滚动槽*/ 6 | ::-webkit-scrollbar-track { 7 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0); 8 | border-radius: 10px; 9 | filter:alpha(opacity=80); 10 | 11 | } 12 | 13 | /* 滚动条滑块 */ 14 | ::-webkit-scrollbar-thumb { 15 | border-radius: 10px; 16 | background: rgba(0,0,0,0.1); 17 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/tablestyle.css: -------------------------------------------------------------------------------- 1 | 2 | /* Table 1 Style */ 3 | table{ 4 | font-size:14px; 5 | } 6 | table td{ 7 | padding:5px; 8 | margin:5px; 9 | } 10 | input{ 11 | height:30px; 12 | } 13 | .btn 14 | { 15 | border: none; 16 | background-color: #615c8d; 17 | color: #fff; 18 | border-radius: 4px; 19 | padding: 1px 8px; 20 | font-size: 14px; 21 | text-align: center; 22 | margin:10px; 23 | width:100px; 24 | height:30px; 25 | } -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/css/tips.css: -------------------------------------------------------------------------------- 1 | /* 提示页面 */ 2 | .tips { 3 | padding: 0 20px; 4 | height: 35px; 5 | background-color: #000; 6 | margin: 0 auto; 7 | filter: alpha(opacity=60); 8 | opacity: 0.6; 9 | line-height: 35px; 10 | font-size: 1.6rem; 11 | text-align: center; 12 | color: #fff; 13 | -moz-border-radius: 0.5rem; 14 | -webkit-border-radius: 0.5rem; 15 | border-radius: 0.5rem; 16 | font-size:1.1rem; 17 | } 18 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/js/admin/login.js: -------------------------------------------------------------------------------- 1 | function login(){ 2 | if($("#loginname").val() == null || $("#loginname").val() == "" ){ 3 | alert('用户名不能为空'); 4 | return; 5 | } 6 | if($("#password").val() == null || $("#password").val() == "" ){ 7 | alert('密码不能为空'); 8 | return; 9 | } 10 | var datas={ 11 | name:$("#loginname").val(), 12 | pwd:$("#password").val() 13 | } 14 | $.ajax({ 15 | data : datas, 16 | type : "POST", 17 | dataType : "text", 18 | url : "../admin/loginHandle", 19 | success : function(data) { 20 | console.log(data); 21 | if (data == "success") { 22 | location.href="../admin/index "; 23 | } else { 24 | alert("登录失败"); 25 | } 26 | }, 27 | error : function(result) { 28 | alert("登录失败"); 29 | } 30 | }); 31 | } 32 | 33 | //enter键触发登录功能 34 | document.onkeydown=function(event){ 35 | var e = event || window.event || arguments.callee.caller.arguments[0]; 36 | if(e && e.keyCode==13){ // enter 键 37 | login(); 38 | } 39 | }; -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/js/admin/menu.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(e) { 2 | 3 | /*左侧多级菜单*/ 4 | $(".page-sidebar-menu>li>a").click(function(e) { 5 | $(this).parent().children(".sub-menu").toggle(); 6 | $(this).children("span.arrow").toggleClass("open"); 7 | }); 8 | 9 | /*二级菜单点击样式*/ 10 | $(".sub-menu>li").click(function(e) { 11 | //给二级菜单添加样式 12 | $(this).addClass("active").siblings().removeClass("active"); 13 | //给一级菜单添加样式 14 | $(this).parent().parent().addClass("active").children("a").children("span").first().after(""); 15 | //取消其他一级菜单以及二级菜单样式 16 | $(this).parent().parent().siblings().removeClass("active").children(".sub-menu").hide().children("li").removeClass("active").parent().parent().children("a").children("span.arrow").removeClass("open"); 17 | }); 18 | 19 | $(".nav>li").click(function(e) { 20 | $(this).addClass("active").siblings().removeClass("active"); 21 | }); 22 | 23 | $(".mix-filter>li").click(function(e) { 24 | $(this).addClass("active").siblings().removeClass("active"); 25 | }); 26 | }); -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/js/config.js: -------------------------------------------------------------------------------- 1 | var langList = 2 | [ 3 | {name:'en', charset:'UTF-8'}, 4 | {name:'zh-cn', charset:'UTF-8'}, 5 | {name:'zh-tw', charset:'UTF-8'} 6 | ]; 7 | 8 | var skinList = 9 | [ 10 | {name:'default', charset:'UTF-8'}, 11 | {name:'whyGreen', charset:'UTF-8'} 12 | ]; -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/uploadify/uploadify-cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/uploadify/uploadify-cancel.png -------------------------------------------------------------------------------- /第九章/herolpvp/src/main/webapp/uploadify/uploadify.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolpvp/src/main/webapp/uploadify/uploadify.swf -------------------------------------------------------------------------------- /第九章/herolpvp/src/test/java/httptest/HttpClientHandler.java: -------------------------------------------------------------------------------- 1 | package httptest; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandlerAdapter; 6 | import io.netty.handler.codec.http.HttpContent; 7 | import io.netty.handler.codec.http.HttpHeaders; 8 | import io.netty.handler.codec.http.HttpResponse; 9 | 10 | public class HttpClientHandler extends ChannelInboundHandlerAdapter { 11 | @Override 12 | public void channelRead(ChannelHandlerContext ctx, Object msg) 13 | throws Exception { 14 | if (msg instanceof HttpResponse) { 15 | HttpResponse response = (HttpResponse) msg; 16 | System.out.println("CONTENT_TYPE:" 17 | + response.headers().get(HttpHeaders.Names.CONTENT_TYPE)); 18 | } 19 | if (msg instanceof HttpContent) { 20 | HttpContent content = (HttpContent) msg; 21 | ByteBuf buf = content.content(); 22 | System.out.println(buf.toString(io.netty.util.CharsetUtil.UTF_8)); 23 | buf.release(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/test/java/httptest/HttpClientTest.java: -------------------------------------------------------------------------------- 1 | package httptest; 2 | 3 | import com.hjc.herolpvp.util.HttpClient; 4 | 5 | public class HttpClientTest { 6 | 7 | public volatile long time = 0; 8 | 9 | public static void main(String[] args) throws Exception { 10 | HttpClientTest test = new HttpClientTest(); 11 | test.test(); 12 | } 13 | 14 | public void test() { 15 | String ret = null; 16 | try { 17 | ret = HttpClient.post( 18 | "http://127.0.0.1:81/herolrouter/route/loginOrRegist", 19 | "name=hjc&pwd=123456"); 20 | } catch (Exception e) { 21 | // TODO Auto-generated catch block 22 | e.printStackTrace(); 23 | } 24 | System.out.println(ret); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /第九章/herolpvp/src/test/java/sockettest/SocketTest.java: -------------------------------------------------------------------------------- 1 | package sockettest; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.io.PrintWriter; 7 | import java.net.Socket; 8 | import java.net.UnknownHostException; 9 | 10 | public class SocketTest { 11 | 12 | public static void main(String[] args) throws UnknownHostException, 13 | IOException { 14 | Socket socket = new Socket("localhost", 8586); 15 | BufferedReader in = new BufferedReader(new InputStreamReader( 16 | socket.getInputStream())); 17 | PrintWriter out = new PrintWriter(socket.getOutputStream()); 18 | BufferedReader reader = new BufferedReader(new InputStreamReader( 19 | System.in)); 20 | while (true) { 21 | String msg = reader.readLine(); 22 | out.println(msg); 23 | out.flush(); 24 | if (msg.equals("bye")) { 25 | break; 26 | } 27 | System.out.println(in.readLine()); 28 | } 29 | socket.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /第九章/herolrouter/lib/signature.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/lib/signature.jar -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/client/message/LoginReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.client.message; 2 | 3 | public class LoginReq { 4 | private String token; 5 | private int channel; 6 | private long appid; 7 | private long uid; 8 | private String username; 9 | 10 | public String getToken() { 11 | return token; 12 | } 13 | 14 | public void setToken(String token) { 15 | this.token = token; 16 | } 17 | 18 | public int getChannel() { 19 | return channel; 20 | } 21 | 22 | public void setChannel(int channel) { 23 | this.channel = channel; 24 | } 25 | 26 | public long getAppid() { 27 | return appid; 28 | } 29 | 30 | public void setAppid(long appid) { 31 | this.appid = appid; 32 | } 33 | 34 | public long getUid() { 35 | return uid; 36 | } 37 | 38 | public void setUid(long uid) { 39 | this.uid = uid; 40 | } 41 | 42 | public String getUsername() { 43 | return username; 44 | } 45 | 46 | public void setUsername(String username) { 47 | this.username = username; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/client/message/LoginResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.client.message; 2 | 3 | public class LoginResp { 4 | private String ip; 5 | private int port; 6 | private int code; 7 | private int accId; 8 | private String errMsg; 9 | 10 | public int getCode() { 11 | return code; 12 | } 13 | 14 | public void setCode(int code) { 15 | this.code = code; 16 | } 17 | 18 | public String getIp() { 19 | return ip; 20 | } 21 | 22 | public void setIp(String ip) { 23 | this.ip = ip; 24 | } 25 | 26 | public int getPort() { 27 | return port; 28 | } 29 | 30 | public void setPort(int port) { 31 | this.port = port; 32 | } 33 | 34 | public String getErrMsg() { 35 | return errMsg; 36 | } 37 | 38 | public void setErrMsg(String errMsg) { 39 | this.errMsg = errMsg; 40 | } 41 | 42 | public int getAccId() { 43 | return accId; 44 | } 45 | 46 | public void setAccId(int accId) { 47 | this.accId = accId; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/client/pay/PayController.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.client.pay; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | @Controller 9 | @RequestMapping(value = "/pay") 10 | public class PayController { 11 | public Logger logger = LoggerFactory.getLogger(PayController.class); 12 | } 13 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/client/rpc/TestService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.client.rpc; 2 | 3 | public interface TestService { 4 | 5 | public void testMethod(String msg, int code); 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/client/rpc/TestServiceImply.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.client.rpc; 2 | 3 | public class TestServiceImply implements TestService { 4 | public void testMethod(String msg, int code) { 5 | System.out.println("msg is " + msg + " ,code is " + code); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/core/TaskService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.core; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.core.task.TaskExecutor; 7 | import org.springframework.scheduling.annotation.Scheduled; 8 | import org.springframework.stereotype.Component; 9 | 10 | 11 | 12 | /** 13 | * 14 | * Title : TaskService .
15 | * Description : 定时任务服务.
16 | * 17 | */ 18 | @Component 19 | public class TaskService { 20 | 21 | @Autowired 22 | private TaskExecutor taskExecutor; 23 | 24 | /** 25 | * 并发处理线程数 26 | */ 27 | private static int threadNum = 100; 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(TaskService.class); 30 | 31 | /** 32 | * 测试 33 | * */ 34 | @Scheduled(cron = "0 */5 * * * *") 35 | public void testTask() { 36 | taskExecutor.execute(new Runnable() { 37 | public void run() { 38 | // Test Code 39 | // logger.info("Task Test"); 40 | } 41 | }); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/message/GetServersReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.message; 2 | 3 | public class GetServersReq { 4 | private String uid; 5 | 6 | public String getUid() { 7 | return uid; 8 | } 9 | 10 | public void setUid(String uid) { 11 | this.uid = uid; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/message/GetServersResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.message; 2 | 3 | import java.util.List; 4 | 5 | import com.hjc.herolrouter.server.ServerConfig; 6 | import com.hjc.herolrouter.util.JsonUtils; 7 | 8 | public class GetServersResp { 9 | private String serverList; 10 | 11 | public String getServerList() { 12 | return serverList; 13 | } 14 | 15 | public void setServerList(List serverList) { 16 | this.serverList = JsonUtils.objectToJson(serverList); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/message/ServerReq.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.message; 2 | 3 | public class ServerReq { 4 | private int serverId; 5 | private int state; 6 | private int accId; 7 | 8 | public int getServerId() { 9 | return serverId; 10 | } 11 | 12 | public void setServerId(int serverId) { 13 | this.serverId = serverId; 14 | } 15 | 16 | public int getState() { 17 | return state; 18 | } 19 | 20 | public void setState(int state) { 21 | this.state = state; 22 | } 23 | 24 | public int getAccId() { 25 | return accId; 26 | } 27 | 28 | public void setAccId(int accId) { 29 | this.accId = accId; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/message/ServerResp.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.message; 2 | 3 | public class ServerResp { 4 | private int code;// 100-成功 5 | private String result; 6 | public int getCode() { 7 | return code; 8 | } 9 | public void setCode(int code) { 10 | this.code = code; 11 | } 12 | public String getResult() { 13 | return result; 14 | } 15 | public void setResult(String result) { 16 | this.result = result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/AppContext.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util; 2 | 3 | import org.springframework.context.support.AbstractApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class AppContext { 7 | 8 | private static AppContext instance; 9 | 10 | private AbstractApplicationContext appContext; 11 | 12 | public synchronized static AppContext getInstance() { 13 | if (instance == null) { 14 | instance = new AppContext(); 15 | } 16 | return instance; 17 | } 18 | 19 | private AppContext() { 20 | this.appContext = new ClassPathXmlApplicationContext( 21 | "/applicationContext.xml"); 22 | } 23 | 24 | public AbstractApplicationContext getAppContext() { 25 | return appContext; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util; 2 | 3 | public class Constants { 4 | /**日志记录配置**/ 5 | public static boolean SDK_DEBUG = true; 6 | public static boolean MSG_LOG_DEBUG = true; 7 | public static boolean CLIENT_DEBUG = true; 8 | } 9 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/PatternMatcher.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util; 2 | 3 | public interface PatternMatcher { 4 | 5 | boolean matches(String pattern, String source); 6 | } 7 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util; 2 | 3 | public class StringUtils { 4 | 5 | public static String getCutString(String str){ 6 | return getCutString(str,10); 7 | } 8 | public static String getCutString(String str,int len){ 9 | if(len<=1) len=1; 10 | if(null ==str){ 11 | return ""; 12 | } 13 | if(str.length()<=len){ 14 | return str; 15 | }else{ 16 | return str.subSequence(0, len-1)+"..."; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/cache/CacheKeys.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util.cache; 2 | 3 | public class CacheKeys { 4 | public static String LOGIN_CACHE = "login:_";// login_serverid:userId 5 | } 6 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/cache/MCSupport.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util.cache; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 实现此接口后还需要再MC类中增加cachedClass,并使用 7 | * com.qx.persistent.HibernateUtil.find(Class, long) 8 | * 代替where进行查询。 9 | * 需要对控制了的对象在第一次存库时调用MC.add,再调用HIbernateUtil.insert 10 | * @author 康建虎 11 | * 12 | */ 13 | public interface MCSupport extends Serializable{ 14 | long getIdentifier(); 15 | } 16 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/java/com/hjc/herolrouter/util/context/SpringInit.java: -------------------------------------------------------------------------------- 1 | package com.hjc.herolrouter.util.context; 2 | import javax.servlet.ServletContextEvent; 3 | import javax.servlet.ServletContextListener; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.web.context.WebApplicationContext; 6 | import org.springframework.web.context.support.WebApplicationContextUtils; 7 | public class SpringInit implements ServletContextListener { 8 | 9 | private static WebApplicationContext springContext; 10 | 11 | public SpringInit() { 12 | super(); 13 | } 14 | 15 | public void contextInitialized(ServletContextEvent event) { 16 | springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); 17 | } 18 | 19 | public void contextDestroyed(ServletContextEvent event) { 20 | } 21 | 22 | public static ApplicationContext getApplicationContext() { 23 | return springContext; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 导入applicationContext文件列表 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/datasource.properties: -------------------------------------------------------------------------------- 1 | jdbc.url=jdbc:mysql://123.57.211.130:3306/herolrouter?useUnicode=true&characterEncoding=utf-8 2 | jdbc.user=root 3 | jdbc.password=123456 4 | 5 | jdbc.initialSize=1 6 | jdbc.maxActive=10 7 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console,dailyFile 2 | # 控制台(console) 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.Threshold=INFO 5 | log4j.appender.console.ImmediateFlush=true 6 | log4j.appender.console.Target=System.out 7 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 9 | # 每天产生一个日志文件(dailyFile) 10 | log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender 11 | #当天的日志文件全路径 12 | log4j.appender.dailyFile.File=/data/log/herolrouter/herolrouter.log 13 | #服务器启动日志是追加,false:服务器启动后会生成日志文件把老的覆盖掉 14 | log4j.appender.dailyFile.Append=true 15 | #日志文件格式 16 | log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.dailyFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} %-5p %-40.40c -%m%n 18 | log4j.appender.dailyFile.Threshold=INFO 19 | #设置每天生成一个文件名后添加的名称,备份名称:年月日.log 20 | log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd'.log' -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/server.properties: -------------------------------------------------------------------------------- 1 | loginServer = 127.0.0.1 2 | loginPort = 81 3 | redisServer = 123.57.211.130:6444 4 | redisPwd = 123456 5 | cacheServer = 123.57.211.130:11211 -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/spring-cxf/cxf-client.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/spring-cxf/cxf-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/resources/spring-redis/redis.properties: -------------------------------------------------------------------------------- 1 | #\u6700\u5927\u5206\u914d\u7684\u5bf9\u8c61\u6570 2 | redis.pool.maxActive=1024 3 | #\u6700\u5927\u80fd\u591f\u4fdd\u6301idel\u72b6\u6001\u7684\u5bf9\u8c61\u6570 4 | redis.pool.maxIdle=200 5 | #\u5f53\u6c60\u5185\u6ca1\u6709\u8fd4\u56de\u5bf9\u8c61\u65f6\uff0c\u6700\u5927\u7b49\u5f85\u65f6\u95f4 6 | redis.pool.maxWait=1000 7 | #\u5f53\u8c03\u7528borrow Object\u65b9\u6cd5\u65f6\uff0c\u662f\u5426\u8fdb\u884c\u6709\u6548\u6027\u68c0\u67e5 8 | redis.pool.testOnBorrow=true 9 | #IP 10 | #redis.ip=192.168.6.66 11 | redis.ip=123.57.211.130 12 | #redis.ip=redis.ha.cmcc 13 | #Port 14 | redis.port=6379 -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/Spring MVC Dispatcher Servlet-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/admin/bottom.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 管理系统 9 | 10 | 11 | 12 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/admin/content.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 后台管理系统 8 | 9 | 10 |
 
11 |
12 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/admin/left.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 后台管理页面 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/admin/top.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=utf-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 后台管理页面 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 退出登录 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ${user.nickname} 27 |
28 |
29 | 30 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/403.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

403 Oops! Page Access 7 | Denied

8 |

错误提示:

9 | 10 |

11 | 该资源您没权限访问,请返回!!! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

404 Oops! Page Not 7 | Found

8 |

9 | 10 |

11 | 该资源不存在,请返回! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/405.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 |
3 | 4 | 5 | 14 | 15 |
6 |

405 Oops! unknown page 7 | error

8 |

错误提示:

9 | 10 |

11 | 发生未知错误,请联系管理员 或返回! 12 |

13 |
16 |
17 | <%@ include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/500.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 2 | 3 |
4 | 5 | 6 | 15 | 16 |
7 |

500 Oops! Internal 8 | Server Error

9 |

错误提示:

10 | 11 |

12 | 服务器内部错误,请稍候再试!!!返回! 13 |

14 |
17 |
18 | <%@ include file="end.jsp" %> 19 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/end.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8"%> 2 | <%@page pageEncoding="UTF-8"%> 3 | 4 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/err.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 | 4 |
5 |
6 | 首页 7 |

异常页面

8 |
9 |
10 | <%-- <% Exception ex = (Exception)request.getAttribute("exception"); %> 11 |

Exception: <%= ex.getMessage()%>

12 |

13 | <%ex.printStackTrace(new java.io.PrintWriter(out)); %> --%> 14 | 系统出现异常了,请您点击左上角的首页返回到首页面,您可以在首页面中的反馈里面想管理员反映情况,谢谢您的使用 15 |

16 |
17 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/error.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 | 4 |
5 |
6 |

7 | 错误页面 8 |

9 |
10 |
11 | ${requestScope.error} 12 |
13 |
14 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/WEB-INF/views/common/upload_error.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" %> 2 | <%@page pageEncoding="UTF-8" %> 3 |
4 |
5 | 首页 6 |

上传异常

7 |
8 |
9 | 对不起,您上传的图片大小超过了我们规定的范围,请您上传50kb以内的图片 10 |
11 |
12 | <%@include file="end.jsp" %> -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/WdatePicker.css: -------------------------------------------------------------------------------- 1 | .Wdate{ 2 | border:#999 1px solid; 3 | height:20px; 4 | background:#fff url(datePicker.gif) no-repeat right; 5 | } 6 | 7 | .WdateFmtErr{ 8 | font-weight:bold; 9 | color:red; 10 | } -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/admin/style.css: -------------------------------------------------------------------------------- 1 | 2 | *{margin:0;padding:0;} 3 | .top{width:100%;height:60px;background-color:#c3bdfc;} 4 | .logo{width:15%;height:100%;float:left;background-color:#746cb9;} 5 | .title{width:15%;height:100%;float:right;background-color:#a09db9;} 6 | 7 | .main{clear:both;min-height:81%;} 8 | .left{width:15%;height:81%;float:left;background-color:#cfd7e0;overflow:auto;} 9 | .right{width:85%;height:81%;float:right;display:block;background-color:#f8fafd;overflow:auto;} 10 | 11 | .foot{width:100%;height:10%;background-color:#d1cdd1;clear:both;} 12 | 13 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/icomoon.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/icomoon.eot -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/icomoon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/icomoon.ttf -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/fonts/icomoon.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/css/fonts/icomoon.woff -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/scroll.css: -------------------------------------------------------------------------------- 1 | ::-webkit-scrollbar { 2 | width: 1.2%; 3 | } 4 | 5 | /* 滚动槽*/ 6 | ::-webkit-scrollbar-track { 7 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0); 8 | border-radius: 10px; 9 | filter:alpha(opacity=80); 10 | 11 | } 12 | 13 | /* 滚动条滑块 */ 14 | ::-webkit-scrollbar-thumb { 15 | border-radius: 10px; 16 | background: rgba(0,0,0,0.1); 17 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/tablestyle.css: -------------------------------------------------------------------------------- 1 | 2 | /* Table 1 Style */ 3 | table{ 4 | font-size:14px; 5 | } 6 | table td{ 7 | padding:5px; 8 | margin:5px; 9 | } 10 | input{ 11 | height:30px; 12 | } 13 | .btn 14 | { 15 | border: none; 16 | background-color: #615c8d; 17 | color: #fff; 18 | border-radius: 4px; 19 | padding: 1px 8px; 20 | font-size: 14px; 21 | text-align: center; 22 | margin:10px; 23 | width:100px; 24 | height:30px; 25 | } -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/css/tips.css: -------------------------------------------------------------------------------- 1 | /* 提示页面 */ 2 | .tips { 3 | padding: 0 20px; 4 | height: 35px; 5 | background-color: #000; 6 | margin: 0 auto; 7 | filter: alpha(opacity=60); 8 | opacity: 0.6; 9 | line-height: 35px; 10 | font-size: 1.6rem; 11 | text-align: center; 12 | color: #fff; 13 | -moz-border-radius: 0.5rem; 14 | -webkit-border-radius: 0.5rem; 15 | border-radius: 0.5rem; 16 | font-size:1.1rem; 17 | } 18 | -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/js/admin/login.js: -------------------------------------------------------------------------------- 1 | function login(){ 2 | if($("#loginname").val() == null || $("#loginname").val() == "" ){ 3 | alert('用户名不能为空'); 4 | return; 5 | } 6 | if($("#password").val() == null || $("#password").val() == "" ){ 7 | alert('密码不能为空'); 8 | return; 9 | } 10 | var datas={ 11 | name:$("#loginname").val(), 12 | pwd:$("#password").val() 13 | } 14 | $.ajax({ 15 | data : datas, 16 | type : "POST", 17 | dataType : "text", 18 | url : "../admin/loginHandle", 19 | success : function(data) { 20 | console.log(data); 21 | if (data == "success") { 22 | location.href="../admin/index "; 23 | } else { 24 | alert("登录失败"); 25 | } 26 | }, 27 | error : function(result) { 28 | alert("登录失败"); 29 | } 30 | }); 31 | } 32 | 33 | //enter键触发登录功能 34 | document.onkeydown=function(event){ 35 | var e = event || window.event || arguments.callee.caller.arguments[0]; 36 | if(e && e.keyCode==13){ // enter 键 37 | login(); 38 | } 39 | }; -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/js/admin/menu.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(e) { 2 | 3 | /*左侧多级菜单*/ 4 | $(".page-sidebar-menu>li>a").click(function(e) { 5 | $(this).parent().children(".sub-menu").toggle(); 6 | $(this).children("span.arrow").toggleClass("open"); 7 | }); 8 | 9 | /*二级菜单点击样式*/ 10 | $(".sub-menu>li").click(function(e) { 11 | //给二级菜单添加样式 12 | $(this).addClass("active").siblings().removeClass("active"); 13 | //给一级菜单添加样式 14 | $(this).parent().parent().addClass("active").children("a").children("span").first().after(""); 15 | //取消其他一级菜单以及二级菜单样式 16 | $(this).parent().parent().siblings().removeClass("active").children(".sub-menu").hide().children("li").removeClass("active").parent().parent().children("a").children("span.arrow").removeClass("open"); 17 | }); 18 | 19 | $(".nav>li").click(function(e) { 20 | $(this).addClass("active").siblings().removeClass("active"); 21 | }); 22 | 23 | $(".mix-filter>li").click(function(e) { 24 | $(this).addClass("active").siblings().removeClass("active"); 25 | }); 26 | }); -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/uploadify/uploadify-cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/uploadify/uploadify-cancel.png -------------------------------------------------------------------------------- /第九章/herolrouter/src/main/webapp/uploadify/uploadify.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第九章/herolrouter/src/main/webapp/uploadify/uploadify.swf -------------------------------------------------------------------------------- /第五章/demo_05/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | demo_05 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.wst.common.project.facet.core.nature 33 | org.eclipse.jdt.core.javanature 34 | org.eclipse.wst.jsdt.core.jsNature 35 | 36 | 37 | -------------------------------------------------------------------------------- /第五章/demo_05/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第五章/demo_05/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /第五章/demo_05/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /第五章/demo_05/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第五章/demo_05/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第五章/demo_05/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第五章/demo_05/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第五章/demo_05/lib/antlr-2.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/antlr-2.7.7.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/catalina.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/catalina.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/commons-lang3-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/commons-lang3-3.1.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/commons-pool-1.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/commons-pool-1.6.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/commons-pool2-2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/commons-pool2-2.2.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/fastjson-1.1.36.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/fastjson-1.1.36.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/hibernate-commons-annotations-4.0.5.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/hibernate-commons-annotations-4.0.5.Final.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/hibernate-core-4.3.10.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/hibernate-core-4.3.10.Final.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/jandex-1.1.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/jandex-1.1.0.Final.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/javassist-3.18.1-GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/javassist-3.18.1-GA.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/jboss-logging-3.1.3.GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/jboss-logging-3.1.3.GA.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/jboss-logging-annotations-1.2.0.Beta1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/jboss-logging-annotations-1.2.0.Beta1.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/jboss-transaction-api_1.2_spec-1.0.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/jboss-transaction-api_1.2_spec-1.0.0.Final.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/jedis-2.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/jedis-2.8.1.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/memcached-2.5.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/memcached-2.5.3.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/mongo-java-driver-2.11.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/mongo-java-driver-2.11.2.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/morphia-0.102.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/morphia-0.102.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/mysql-connector-java-5.1.22.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/mysql-connector-java-5.1.22.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/servlet-api.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/slf4j-api-1.7.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/slf4j-api-1.7.2.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/spring-data-redis-1.7.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/spring-data-redis-1.7.1.RELEASE.jar -------------------------------------------------------------------------------- /第五章/demo_05/lib/tomcat-coyote.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第五章/demo_05/lib/tomcat-coyote.jar -------------------------------------------------------------------------------- /第五章/demo_05/src/com/hjc/demo/DemoBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class DemoBean implements Serializable { 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = -2753477901931164396L; 11 | 12 | public DemoBean() { 13 | 14 | } 15 | 16 | private long id; 17 | private String name; 18 | private String sex; 19 | private Date createtime; 20 | 21 | public long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getSex() { 38 | return sex; 39 | } 40 | 41 | public void setSex(String sex) { 42 | this.sex = sex; 43 | } 44 | 45 | public Date getCreatetime() { 46 | return createtime; 47 | } 48 | 49 | public void setCreatetime(Date createtime) { 50 | this.createtime = createtime; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /第五章/demo_05/src/com/hjc/demo/hibernate/DemoBean.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /第五章/demo_05/src/com/hjc/demo/mongo/MongoCollections.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.mongo; 2 | 3 | public class MongoCollections { 4 | public static final String USER_DATA = "user_data";// 用户数据表 5 | } 6 | -------------------------------------------------------------------------------- /第五章/demo_05/src/com/hjc/demo/mongo/SubBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.mongo; 2 | 3 | public class SubBean { 4 | private Long id; 5 | private String str; 6 | 7 | public String getStr() { 8 | return str; 9 | } 10 | 11 | public void setStr(String str) { 12 | this.str = str; 13 | } 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第五章/demo_05/src/com/hjc/demo/mongo/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.mongo; 2 | 3 | public class TestBean { 4 | private Long id; 5 | private String msg; 6 | private Double score; 7 | private SubBean subBean; 8 | 9 | public Long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(Long id) { 14 | this.id = id; 15 | } 16 | 17 | public String getMsg() { 18 | return msg; 19 | } 20 | 21 | public void setMsg(String msg) { 22 | this.msg = msg; 23 | } 24 | 25 | public Double getScore() { 26 | return score; 27 | } 28 | 29 | public void setScore(Double score) { 30 | this.score = score; 31 | } 32 | 33 | public SubBean getSubBean() { 34 | return subBean; 35 | } 36 | 37 | public void setSubBean(SubBean subBean) { 38 | this.subBean = subBean; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /第五章/demo_05/src/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | org.hibernate.dialect.MySQLDialect 9 | 10 | com.mysql.jdbc.Driver 11 | 12 | jdbc:mysql://127.0.0.1:3306/demo 13 | 14 | root 15 | 16 | 123456 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /第六章/demo_06/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /第六章/demo_06/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | demo_06 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.wst.common.project.facet.core.nature 33 | org.eclipse.jdt.core.javanature 34 | org.eclipse.wst.jsdt.core.jsNature 35 | 36 | 37 | -------------------------------------------------------------------------------- /第六章/demo_06/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第六章/demo_06/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /第六章/demo_06/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /第六章/demo_06/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第六章/demo_06/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第六章/demo_06/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第六章/demo_06/README: -------------------------------------------------------------------------------- 1 | 本章内容是逻辑层代码 2 | 游戏逻辑处理 3 | 模块化思想 4 | 事件处理机制 5 | 并发控制 -------------------------------------------------------------------------------- /第六章/demo_06/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第六章/demo_06/lib/catalina.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/catalina.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/fastjson-1.1.36.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/fastjson-1.1.36.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/quartz-1.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/quartz-1.5.2.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/quartz-2.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/quartz-2.2.3.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/quartz-jobs-2.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/quartz-jobs-2.2.3.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/servlet-api.jar -------------------------------------------------------------------------------- /第六章/demo_06/lib/tomcat-coyote.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第六章/demo_06/lib/tomcat-coyote.jar -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/event/ED.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.event; 2 | 3 | /** 4 | * Event Id Definition 5 | * 6 | * @author 何金成 7 | * 8 | */ 9 | public class ED { 10 | /** 11 | * @Fields EVE1 : 事件1 12 | */ 13 | public static final int EVE1 = 1; 14 | /** 15 | * @Fields EVE1 : 事件2 16 | */ 17 | public static final int EVE2 = 2; 18 | /** 19 | * @Fields EVE1 : 事件3 20 | */ 21 | public static final int EVE3 = 3; 22 | /** 23 | * @Fields EVE1 : 事件4 24 | */ 25 | public static final int EVE4 = 4; 26 | } 27 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/event/Event.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.event; 2 | 3 | /** 4 | * @ClassName: Event 5 | * @Description: 事件 6 | * @author 何金成 7 | * @date 2016年5月2日 下午9:12:30 8 | * 9 | */ 10 | public class Event { 11 | public int id; 12 | public Object param; 13 | } 14 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/event/EventProc.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.event; 2 | 3 | /** 4 | * @ClassName: EventProc 5 | * @Description: 事件处理器 6 | * @author 何金成 7 | * @date 2016年5月2日 下午8:58:01 8 | * 9 | */ 10 | public abstract class EventProc { 11 | public boolean disable; 12 | 13 | public EventProc() { 14 | doReg(); 15 | } 16 | 17 | public abstract void proc(Event param); 18 | 19 | protected abstract void doReg(); 20 | } 21 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module1/Demo1Mgr.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module1; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.hjc.demo.net.NetFramework; 5 | import com.hjc.demo.net.ProtoMessage; 6 | import com.hjc.test.Demo; 7 | 8 | public class Demo1Mgr { 9 | private static Demo1Mgr demo1Mgr; 10 | 11 | private Demo1Mgr() { 12 | 13 | } 14 | 15 | public static Demo1Mgr getInstance() { 16 | if (demo1Mgr == null) { 17 | demo1Mgr = new Demo1Mgr(); 18 | } 19 | return demo1Mgr; 20 | } 21 | 22 | public void initData() { 23 | Demo.print("Demp1Mgr initData"); 24 | } 25 | 26 | public void demoLogic1(NetFramework net, ProtoMessage msg, long userid) { 27 | Demo.print("invoke demoLogic1"); 28 | JSONArray ret = new JSONArray(); 29 | ret.add(userid); 30 | ret.add(msg.getData()); 31 | net.write(ret); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module2/Demo2Mgr.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module2; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.hjc.demo.net.NetFramework; 5 | import com.hjc.demo.net.ProtoMessage; 6 | import com.hjc.test.Demo; 7 | 8 | public class Demo2Mgr { 9 | private static Demo2Mgr demo2Mgr; 10 | 11 | private Demo2Mgr() { 12 | 13 | } 14 | 15 | public static Demo2Mgr getInstance() { 16 | if (demo2Mgr == null) { 17 | demo2Mgr = new Demo2Mgr(); 18 | } 19 | return demo2Mgr; 20 | } 21 | 22 | public void initData() { 23 | Demo.print("Demp2Mgr initData"); 24 | // Demo 25 | } 26 | 27 | public void demoLogic2(NetFramework net, ProtoMessage msg, long userid) { 28 | Demo.print("invoke demoLogic2"); 29 | JSONArray ret = new JSONArray(); 30 | ret.add(userid); 31 | ret.add(msg.getData()); 32 | net.write(ret); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module3/Demo3Mgr.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module3; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.hjc.demo.net.NetFramework; 5 | import com.hjc.demo.net.ProtoMessage; 6 | import com.hjc.test.Demo; 7 | 8 | public class Demo3Mgr { 9 | private static Demo3Mgr demo3Mgr; 10 | 11 | private Demo3Mgr() { 12 | 13 | } 14 | 15 | public static Demo3Mgr getInstance() { 16 | if (demo3Mgr == null) { 17 | demo3Mgr = new Demo3Mgr(); 18 | } 19 | return demo3Mgr; 20 | } 21 | 22 | public void initData() { 23 | Demo.print("Demp3Mgr initData"); 24 | // Demo 25 | } 26 | 27 | public void demoLogic3(NetFramework net, ProtoMessage msg, long userid) { 28 | Demo.print("invoke demoLogic3"); 29 | JSONArray ret = new JSONArray(); 30 | ret.add(userid); 31 | ret.add(msg.getData()); 32 | net.write(ret); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module4/Demo4Mgr.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module4; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.hjc.demo.net.NetFramework; 5 | import com.hjc.demo.net.ProtoMessage; 6 | import com.hjc.test.Demo; 7 | 8 | public class Demo4Mgr { 9 | private static Demo4Mgr demo4Mgr; 10 | 11 | private Demo4Mgr() { 12 | 13 | } 14 | 15 | public static Demo4Mgr getInstance() { 16 | if (demo4Mgr == null) { 17 | demo4Mgr = new Demo4Mgr(); 18 | } 19 | return demo4Mgr; 20 | } 21 | 22 | public void initData() { 23 | Demo.print("Demp4Mgr initData"); 24 | // Demo 25 | } 26 | 27 | public void demoLogic4(NetFramework net, ProtoMessage msg, long userid) { 28 | Demo.print("invoke demoLogic4"); 29 | JSONArray ret = new JSONArray(); 30 | ret.add(userid); 31 | ret.add(msg.getData()); 32 | net.write(ret); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module5/Demo5Mgr.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module5; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.hjc.demo.net.NetFramework; 5 | import com.hjc.demo.net.ProtoMessage; 6 | import com.hjc.test.Demo; 7 | 8 | public class Demo5Mgr { 9 | private static Demo5Mgr demo5Mgr; 10 | 11 | private Demo5Mgr() { 12 | 13 | } 14 | 15 | public static Demo5Mgr getInstance() { 16 | if (demo5Mgr == null) { 17 | demo5Mgr = new Demo5Mgr(); 18 | } 19 | return demo5Mgr; 20 | } 21 | 22 | public void initData() { 23 | Demo.print("Demp5Mgr initData"); 24 | // Demo 25 | } 26 | 27 | public void demoLogic5(NetFramework net, ProtoMessage msg, long userid) { 28 | Demo.print("invoke demoLogic5"); 29 | JSONArray ret = new JSONArray(); 30 | ret.add(userid); 31 | ret.add(msg.getData()); 32 | net.write(ret); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/manager/module8/DemoBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.manager.module8; 2 | 3 | public class DemoBean { 4 | private long id; 5 | private String msg; 6 | 7 | public String getMsg() { 8 | return msg; 9 | } 10 | 11 | public void setMsg(String msg) { 12 | this.msg = msg; 13 | } 14 | 15 | public long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(long id) { 20 | this.id = id; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/net/NetHandler.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.net; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | /** 6 | * @ClassName: NetHandler 7 | * @Description: 网络消息处理接口 8 | * @author 何金成 9 | * @date 2016年4月27日 下午3:31:04 10 | * 11 | */ 12 | public interface NetHandler { 13 | public void read(JSON request); 14 | 15 | public void write(JSON request); 16 | 17 | public void connect(String host); 18 | 19 | public void disconnect(String host); 20 | 21 | public void exceptionCaught(String host); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/net/ProtoIds.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.net; 2 | 3 | /** 4 | * 5 | * @ClassName: ProtoIds 6 | * @Description: 存储协议号 7 | * @author 何金成 8 | * @date 2015年5月23日 下午4:34:41 9 | * 10 | */ 11 | public class ProtoIds { 12 | public static final short TEST = 0; 13 | public static final short DEMO_LOGIC_1 = 1; 14 | public static final short DEMO_LOGIC_2 = 2; 15 | public static final short DEMO_LOGIC_3 = 3; 16 | public static final short DEMO_LOGIC_4 = 4; 17 | public static final short DEMO_LOGIC_5 = 5; 18 | public static final short DEMO_LOGIC_6 = 6; 19 | public static final short DEMO_LOGIC_7 = 7; 20 | public static final short DEMO_LOGIC_8 = 8; 21 | public static final short DEMO_LOGIC_9 = 9; 22 | } 23 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/net/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.net; 2 | 3 | /** 4 | * @ClassName: ResultCode 5 | * @Description: 返回代码 6 | * @author 何金成 7 | * @date 2016年5月2日 下午8:30:29 8 | * 9 | */ 10 | public class ResultCode { 11 | public static final int SUCCESS = 100;// 成功 12 | public static final int COMMON_ERR = 101;// 默认错误 13 | } 14 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/net/net.properties: -------------------------------------------------------------------------------- 1 | port = 8100 2 | ip=127.0.0.1 -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/net/rpc/README.txt: -------------------------------------------------------------------------------- 1 | RPC框架的使用单独写了两个demo项目 2 | 1.Motan 3 | 介绍了Motan框架的基本使用和集群使用 4 | github地址:https://github.com/hjcenry/motan-demo.git 5 | 2.JsonRpc 6 | 介绍了JsonRpc框架的基本使用 7 | github地址:https://github.com/hjcenry/json-rpc-demo.git -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/task/TestJob.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.task; 2 | 3 | import java.util.Date; 4 | 5 | import org.quartz.Job; 6 | import org.quartz.JobExecutionContext; 7 | import org.quartz.JobExecutionException; 8 | 9 | import com.hjc.test.Demo; 10 | 11 | /** 12 | * @ClassName: TestJob 13 | * @Description: 测试Job 14 | * @author 何金成 15 | * @date 2016年4月28日 下午10:16:04 16 | * 17 | */ 18 | public class TestJob implements Job { 19 | 20 | @Override 21 | public void execute(JobExecutionContext ctx) throws JobExecutionException { 22 | Demo.print("现在时间:" + new Date().toLocaleString()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/template/DataLoader.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.template; 2 | 3 | import com.hjc.test.Demo; 4 | 5 | public class DataLoader { 6 | 7 | public void load() { 8 | Demo.print("载入游戏数据"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/util/CacheUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.util; 2 | 3 | public class CacheUtil { 4 | 5 | public static void add(Object obj) { 6 | 7 | } 8 | 9 | public static void update(Object obj) { 10 | 11 | } 12 | 13 | public static Object find(String where) { 14 | return null; 15 | } 16 | 17 | public static Object list(String where) { 18 | return null; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/util/DBUtil.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.util; 2 | 3 | public class DBUtil { 4 | public static void insert(Object obj) { 5 | 6 | } 7 | 8 | public static void update(Object obj) { 9 | 10 | } 11 | 12 | public static Object find(String where) { 13 | Object ret = CacheUtil.find(where); 14 | if (ret != null) { 15 | return ret; 16 | } else { 17 | 18 | } 19 | return ret; 20 | } 21 | 22 | public static Object list(String where) { 23 | return null; 24 | } 25 | 26 | public static void delete(Object obj) { 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /第六章/demo_06/src/com/hjc/demo/util/ExecutorPool.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.util; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * @ClassName: ExecutorPool 8 | * @Description: 线程池管理 9 | * @author 何金成 10 | * @date 2016年4月18日 下午3:42:42 11 | * 12 | */ 13 | public class ExecutorPool { 14 | public static ExecutorService handleThreadPool = null; 15 | 16 | public static void initThreadsExecutor() { 17 | handleThreadPool = Executors.newCachedThreadPool(); 18 | } 19 | 20 | public static void execute(Runnable runnable) { 21 | handleThreadPool.execute(runnable); 22 | } 23 | 24 | public static void shutdown() { 25 | if (!handleThreadPool.isShutdown()) 26 | handleThreadPool.shutdown(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第六章/jsonrpc_server/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/java/com/hjc/demo/DemoBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo; 2 | 3 | import java.io.Serializable; 4 | 5 | public class DemoBean implements Serializable{ 6 | private static final long serialVersionUID = -5141784402935371524L; 7 | private int code; 8 | private String msg; 9 | 10 | public int getCode() { 11 | return code; 12 | } 13 | 14 | public void setCode(int code) { 15 | this.code = code; 16 | } 17 | 18 | public String getMsg() { 19 | return msg; 20 | } 21 | 22 | public void setMsg(String msg) { 23 | this.msg = msg; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/java/com/hjc/demo/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo; 2 | 3 | public interface DemoService { 4 | 5 | public DemoBean getDemo(String code, String msg); 6 | 7 | public Integer getInt(Integer code); 8 | 9 | public String getString(String msg); 10 | 11 | public void doSomething(); 12 | } 13 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/java/com/hjc/demo/DemoServiceImply.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo; 2 | 3 | public class DemoServiceImply { 4 | 5 | public DemoBean getDemo2(DemoBean bean, String msg) { 6 | DemoBean bean1 = new DemoBean(); 7 | System.out.println(bean.getCode()); 8 | System.out.println(bean.getMsg()); 9 | System.out.println(msg); 10 | bean1 = bean; 11 | return bean1; 12 | } 13 | 14 | public DemoBean getDemo(String code, String msg) { 15 | DemoBean bean1 = new DemoBean(); 16 | bean1.setCode(Integer.parseInt(code)); 17 | bean1.setMsg(msg); 18 | return bean1; 19 | } 20 | 21 | public Integer getInt(Integer code) { 22 | return code; 23 | } 24 | 25 | public String getString(String msg) { 26 | return msg; 27 | } 28 | 29 | public void doSomething() { 30 | System.out.println("do something"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/java/com/hjc/demo/RpcServer.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.googlecode.jsonrpc4j.JsonRpcServer; 11 | 12 | public class RpcServer extends HttpServlet { 13 | private static final long serialVersionUID = 1L; 14 | private JsonRpcServer rpcServer = null; 15 | 16 | public RpcServer() { 17 | super(); 18 | rpcServer = new JsonRpcServer(new DemoServiceImply(), DemoService.class); 19 | } 20 | 21 | @Override 22 | protected void service(HttpServletRequest request, 23 | HttpServletResponse response) throws ServletException, IOException { 24 | rpcServer.handle(request, response); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | RpcServer 9 | RpcServer 10 | 11 | com.hjc.demo.RpcServer 12 | 13 | 14 | RpcServer 15 | /rpc 16 | 17 | 18 | -------------------------------------------------------------------------------- /第六章/jsonrpc_server/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /第六章/motandemo/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第六章/motandemo/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/java/com/hjc/motan/DemoBean.java: -------------------------------------------------------------------------------- 1 | package com.hjc.motan; 2 | 3 | import java.io.Serializable; 4 | 5 | public class DemoBean implements Serializable { 6 | private static final long serialVersionUID = -3822931722874826165L; 7 | private long id; 8 | private String name; 9 | private double score; 10 | 11 | public long getId() { 12 | return id; 13 | } 14 | 15 | public void setId(long id) { 16 | this.id = id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public double getScore() { 28 | return score; 29 | } 30 | 31 | public void setScore(double score) { 32 | this.score = score; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/java/com/hjc/motan/server/FooService.java: -------------------------------------------------------------------------------- 1 | package com.hjc.motan.server; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.hjc.motan.DemoBean; 7 | 8 | public interface FooService { 9 | public String hello(String name); 10 | 11 | public int helloInt(int number1); 12 | 13 | public double helloDouble(double number2); 14 | 15 | public List helloList(List list); 16 | 17 | public Map> helloMap(Map> map); 18 | 19 | public DemoBean helloJavabean(DemoBean bean); 20 | } 21 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/resources/motan_client.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/resources/motan_server.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第六章/motandemo/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /第四章/demo_04/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第四章/demo_04/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /第四章/demo_04/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /第四章/demo_04/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /第四章/demo_04/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /第四章/demo_04/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /第四章/demo_04/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /第四章/demo_04/lib/commons-beanutils-1.8.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/commons-beanutils-1.8.3.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/commons-collections-3.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/commons-collections-3.2.1.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/commons-lang-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/commons-lang-2.5.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/ezmorph-1.0.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/ezmorph-1.0.6.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/fastjson-1.1.36.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/fastjson-1.1.36.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/gson-2.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/gson-2.2.4.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/jackson-all-1.9.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/jackson-all-1.9.0.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/jdom-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/jdom-1.1.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/protobuf-java-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/protobuf-java-2.5.0.jar -------------------------------------------------------------------------------- /第四章/demo_04/lib/slf4j-api-1.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hjcenry/JavaServerBookCode/807ce3afe2eba4ba34b6150f7e9b4b3b6da795a8/第四章/demo_04/lib/slf4j-api-1.7.7.jar -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/json/FastjsonDemo.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.json; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | public class FastjsonDemo { 6 | 7 | public static void main(String[] args) { 8 | String jsonString = null; 9 | // Java序列化为Json 10 | JsonObject obj = new JsonObject(); 11 | obj.setId(1l); 12 | obj.setOrderId("2016_3_27"); 13 | JsonSubObject subObject = new JsonSubObject(); 14 | subObject.setCode(1001); 15 | subObject.setMsg("message"); 16 | obj.setSubObject(subObject); 17 | jsonString = JSON.toJSONString(obj); 18 | System.out.println("json string:"); 19 | System.out.println(jsonString); 20 | // Json反序列化为Java 21 | obj = JSON.parseObject(jsonString, JsonObject.class); 22 | System.out.println("Java Object:"); 23 | System.out.println(obj); 24 | System.out.println("id:" + obj.getId()); 25 | System.out.println("orderId:" + obj.getOrderId()); 26 | System.out.println("sub code:" + obj.getSubObject().getCode()); 27 | System.out.println("sub msg:" + obj.getSubObject().getMsg()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/json/GsonDemo.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.json; 2 | 3 | import com.google.gson.Gson; 4 | 5 | public class GsonDemo { 6 | 7 | public static void main(String[] args) { 8 | String jsonString = null; 9 | // Java序列化为Json 10 | JsonObject obj = new JsonObject(); 11 | obj.setId(1l); 12 | obj.setOrderId("2016_3_27"); 13 | JsonSubObject subObject = new JsonSubObject(); 14 | subObject.setCode(1001); 15 | subObject.setMsg("message"); 16 | obj.setSubObject(subObject); 17 | Gson gson = new Gson(); 18 | jsonString = gson.toJson(obj); 19 | System.out.println("json string:"); 20 | System.out.println(jsonString); 21 | // Json反序列化为Java 22 | obj = gson.fromJson(jsonString, obj.getClass()); 23 | System.out.println("Java Object:"); 24 | System.out.println(obj); 25 | System.out.println("id:" + obj.getId()); 26 | System.out.println("orderId:" + obj.getOrderId()); 27 | System.out.println("sub code:" + obj.getSubObject().getCode()); 28 | System.out.println("sub msg:" + obj.getSubObject().getMsg()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/json/JsonObject.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.json; 2 | 3 | public class JsonObject { 4 | private long id; 5 | private String orderId; 6 | private JsonSubObject subObject; 7 | 8 | public long getId() { 9 | return id; 10 | } 11 | 12 | public void setId(long id) { 13 | this.id = id; 14 | } 15 | 16 | public String getOrderId() { 17 | return orderId; 18 | } 19 | 20 | public void setOrderId(String orderId) { 21 | this.orderId = orderId; 22 | } 23 | 24 | public JsonSubObject getSubObject() { 25 | return subObject; 26 | } 27 | 28 | public void setSubObject(JsonSubObject subObject) { 29 | this.subObject = subObject; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/json/JsonSubObject.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.json; 2 | 3 | public class JsonSubObject { 4 | private int code; 5 | private String msg; 6 | 7 | public int getCode() { 8 | return code; 9 | } 10 | 11 | public void setCode(int code) { 12 | this.code = code; 13 | } 14 | 15 | public String getMsg() { 16 | return msg; 17 | } 18 | 19 | public void setMsg(String msg) { 20 | this.msg = msg; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/pb/PbDemo.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.pb; 2 | 3 | import com.hjc.demo.pb.DemoProto.Obj1; 4 | import com.hjc.demo.pb.DemoProto.Obj2; 5 | 6 | public class PbDemo { 7 | 8 | public static void main(String[] args) { 9 | PbDemo demo = new PbDemo(); 10 | demo.run(); 11 | } 12 | 13 | public void run() { 14 | // 构建Protocol Javabean 15 | Obj1.Builder obj1 = Obj1.newBuilder(); 16 | obj1.setVal1(1); 17 | Obj2.Builder obj21 = Obj2.newBuilder(); 18 | obj21.setSubval1("protocol buffer demo 1"); 19 | obj21.setSubval2(1.9999d); 20 | obj1.addVal2(obj21); 21 | Obj2.Builder obj22 = Obj2.newBuilder(); 22 | obj22.setSubval1("protocol buffer demo 2"); 23 | obj22.setSubval2(1.9999d); 24 | obj1.addVal2(obj22); 25 | System.out.println(obj1); 26 | System.out.println(obj1.build()); 27 | // 接收到的proto直接对应Protocol Javabean 28 | System.out.println("接收到的proto直接对应Protocol Javabean"); 29 | System.out.println("val1:" + obj1.getVal1()); 30 | System.out.println("val2:" + obj1.getVal2List()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/pb/demo.proto: -------------------------------------------------------------------------------- 1 | option java_outer_classname = "DemoProto"; 2 | 3 | message Obj1 { 4 | required int32 val1 = 1; 5 | repeated Obj2 val2 = 2; 6 | } 7 | 8 | message Obj2 { 9 | required string subval1 = 1; 10 | optional double subval2 = 2; 11 | } -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/xml/RootElement.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.xml; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | /** 6 | * @author hjc Unmarshaller的文档根元素 7 | * 8 | */ 9 | @XmlRootElement 10 | public class RootElement { 11 | private long val1; 12 | private double val2; 13 | private SubElement val3; 14 | 15 | public RootElement() { 16 | super(); 17 | } 18 | 19 | public long getVal1() { 20 | return val1; 21 | } 22 | 23 | public void setVal1(long val1) { 24 | this.val1 = val1; 25 | } 26 | 27 | public double getVal2() { 28 | return val2; 29 | } 30 | 31 | public void setVal2(double val2) { 32 | this.val2 = val2; 33 | } 34 | 35 | public SubElement getVal3() { 36 | return val3; 37 | } 38 | 39 | public void setVal3(SubElement val3) { 40 | this.val3 = val3; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /第四章/demo_04/src/com/hjc/demo/xml/SubElement.java: -------------------------------------------------------------------------------- 1 | package com.hjc.demo.xml; 2 | 3 | public class SubElement { 4 | private int subval1; 5 | private String subval2; 6 | public SubElement(){ 7 | super(); 8 | } 9 | 10 | public int getSubval1() { 11 | return subval1; 12 | } 13 | 14 | public void setSubval1(int subval1) { 15 | this.subval1 = subval1; 16 | } 17 | 18 | public String getSubval2() { 19 | return subval2; 20 | } 21 | 22 | public void setSubval2(String subval2) { 23 | this.subval2 = subval2; 24 | } 25 | } 26 | --------------------------------------------------------------------------------