代码拉取完成,页面将自动刷新
同步操作将从 htwin/基于SSM开发的个人博客系统 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50728
Source Host : localhost:3306
Source Database : blog
Target Server Type : MYSQL
Target Server Version : 50728
File Encoding : 65001
Date: 2020-12-21 20:17:28
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tb_blog
-- ----------------------------
DROP TABLE IF EXISTS `tb_blog`;
CREATE TABLE `tb_blog` (
`blog_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`pic` varchar(255) DEFAULT NULL,
`introduction` varchar(400) NOT NULL,
`content` text NOT NULL,
`clickNum` int(11) DEFAULT NULL,
`replyNum` int(11) DEFAULT NULL,
`createDate` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
`updateDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`typeId` int(11) NOT NULL,
PRIMARY KEY (`blog_id`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_blog
-- ----------------------------
INSERT INTO `tb_blog` VALUES ('1', '如何大概率找回遗失被盗苹果手机', '/title_pics/huoying.jpg', '这个黄金周算是我自由旅行以来最惨的一次体验了。因为连续几天晚睡加饮酒,身体始终很疲劳;一个人旅行火车上不敢合眼就变得更累,脑子也麻木起来,于是苹果手机就这么丢了。。。', '<p>\r\n </p>\r\n <h1 class=\"title\" style=\"font-size:34px;font-family:-apple-system, "color:#333333;background-color:#FFFFFF;\">\r\n 如何大概率找回遗失被盗苹果手机\r\n</h1>\r\n <div class=\"author\" style=\"margin:30px 0px 40px;color:#333333;font-family:-apple-system, "font-size:17px;background-color:#FFFFFF;\">\r\n <a class=\"avatar\" href=\"https://www.jianshu.com/u/0bf3ef432765\"><img src=\"https://upload.jianshu.io/users/upload_avatars/10427724/31247303-4517-455e-be1a-f79504087aa8.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96\" alt=\"96\" style=\"width:48px;height:48px;\" /></a> \r\n <div class=\"info\" style=\"vertical-align:middle;margin-left:8px;\">\r\n <span class=\"name\" style=\"font-size:16px;vertical-align:middle;\"><a href=\"https://www.jianshu.com/u/0bf3ef432765\">披尘掠风</a></span> \r\n <a class=\"btn btn-default following\">已关注</a>\r\n <div class=\"meta\" style=\"font-size:12px;color:#969696;\">\r\n <span class=\"publish-time\">2018.10.05 15:07</span> <span class=\"wordage\">字数 4815</span> <span class=\"views-count\">阅读 635</span><span class=\"comments-count\">评论 10</span><span class=\"likes-count\">喜欢 4</span><span class=\"rewards-count \">赞赏 4</span>\r\n </div>\r\n </div>\r\n </div>\r\n <div class=\"show-content\" style=\"color:#2F2F2F;font-size:16px;font-family:-apple-system, "background-color:#FFFFFF;\">\r\n <div class=\"show-content-free\">\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-c3e0156a54425c84.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"889\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 请及时收藏该文并认真学习,以备不时之需\r\n </div>\r\n </div>\r\n <p>\r\n 这个黄金周算是我自由旅行以来最惨的一次体验了。因为连续几天晚睡加饮酒,身体始终很疲劳;一个人旅行火车上不敢合眼就变得更累,脑子也麻木起来,于是苹果手机就这么丢了。\r\n </p>\r\n <p>\r\n 此行除了参加小兄弟婚礼,与多年战友见面外,还有一个心愿就是参观云冈石窟。堵车2小时,辛苦步行3公里到达云冈石窟,心里憋足了劲想要好好呆上一整天。结果上卫生间时手机遗忘在洗漱台上,出门回身2分钟手机也就没了。\r\n </p>\r\n <blockquote style=\"background-color:#F7F7F7;\">\r\n 第一、源泉自查和迅速报警\r\n </blockquote>\r\n <p>\r\n 手机丢了,肯定先在丢失可能性最大的区域附近寻找,及时报警协助找回。第一案发地的价值是极高的,哪怕找不到也可以顺藤摸瓜找到蛛丝马迹。\r\n </p>\r\n <p>\r\n 景区保洁大爷人特别好。他指认了还在厕所里的某大爷拿了我手机,可是某大爷拒不承认。保洁大爷又用自己的手机给我拨号,可是很不幸我的手机长期处于振动状态,景区的自然噪音屏蔽了微弱的振动声。作为普通公民,我没有权利对嫌疑人搜身或拘押。考虑到警务亭就在卫生间对面十米处,我请保洁大爷帮我看一下贼大爷,自己马上去报警。\r\n </p>\r\n <p>\r\n 警亭里的警官叔叔态度很温和,但一位女游客正在问询。她的问题是这样的:1.门票在哪里买?我忍;2.景区里好玩么?我有点难忍;3.景区里好玩还是景区外面好玩?我忍无可忍;4.值不值得买票进景区玩啊?我无需再忍了(此处对说话啰嗦的人提出警告,你们会毁了自己的婚姻的)。\r\n </p>\r\n <p>\r\n 因为这位女游客无厘头的勾引行为,耽误了我找回手机最宝贵的黄金时间。待我三分钟后领着警官赶回时,某大爷已经离开,成功晋级贼大爷了。\r\n </p>\r\n <p>\r\n 我马上返回警务亭请求警察叔叔帮我调取监控,因为他们监控设备的探头区域正好是贼大爷坐过的区域,这是顺藤摸瓜的起点。可是按照警方的程序我自己不能看监控,要调看必须先作好报案记录。\r\n </p>\r\n <p>\r\n 背运到底的我此时又遇到了景区门口村民设卡收钱引发矛盾,警察叔叔必须出警解决。20分钟叔叔返回后才继续开始走程序。可是......当我做好一切记录后叔叔告诉我那个监控探头没有录像设备。呃......在此强烈建议大同市政认真完善与公民生命财产安全相关的基础设施设备,不要把城墙修的那么漂亮却忽略了里子。\r\n </p>\r\n <p>\r\n 为什么怀疑是贼大爷偷了,一方面是保洁大爷的指认,一方面是我与他眼神对视时他的躲闪,还有一方面是手机丢失后几小时里始终没有关机,打得通可就是没有接。这样的情况只有在没有偷盗经验甚至不熟悉电子设备却有占便宜心态的老年、幼年身上才会出现。\r\n </p>\r\n <p>\r\n 第一段落到此结束,自寻自查+报警查证均无效的情况下,这个程序就没有意义了。作为善后弥补,我借用警察叔叔的手机给较为重要的利害关系人打了电话发了微信,告知了下步打算。同时也用警察叔叔的手机给我原号码发了短信请嫌疑人有偿归还手机,并留下了警察叔叔的手机号码(不留就斩断了前面所有的努力以及各种后续可能)。\r\n </p>\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-3b26f3835eaf5f4d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"889\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 我还在大同没能离开,我的手机就已经被带到了几百公里外的吕梁地区,真是一个落荒而逃的笨贼\r\n </div>\r\n </div>\r\n <blockquote style=\"background-color:#F7F7F7;\">\r\n 第二、迅速接驳同账号苹果设备进行应急处理\r\n </blockquote>\r\n <p>\r\n 苹果设备都有一个核心ID账号,你的自用设备在下载APP,运用其它功能时都需要使用这个ID,哪怕是你已经淘汰停用了的设备,只要关机拔卡前没有更换ID都可以在“查找iPhone”这个自带APP上记录在案。\r\n </p>\r\n <p>\r\n 如果你有使用同一关联账号的其它苹果设备,那就迅速在网络环境下启动这个软件。然后点开遗失设备的操作选项将手机设为“丢失模式”,填写相关信息。这样该设备哪怕之前没有启用定位功能此时也会被激活定位,并向你手中有网状态的设备发送定位信息。同时遗失设备的锁屏界面上也会显示你的联系方式以供对方(假设好人)联系你。\r\n </p>\r\n <p>\r\n 如果你想让占有者不得安宁还可点击“播放声音”,如果不是设备丢了,我自然没有听过这个声音是怎样的,是“手机丢了”,还是“Ta是贼”,或者“该设备将在10秒后自毁”,但肯定会让非法占有者一开机就很不爽(因为在设完这些后不久,占有者就和我主动联系了)。\r\n </p>\r\n <p>\r\n 最右侧有一个“抹掉iPhone”功能,这是在确知设备已经无法取回情况下进行的毁灭性处理。一旦启用,你的手机就被刷成出厂状态了,这当然是为了保护个人隐私,也是无奈的不得已。\r\n </p>\r\n <p>\r\n 以上几个功能必须在遗失设备有网开机状态下才能实现,如果对方到大沙漠里完全没有信号的地方开机处理你也没有办法收到反馈。不过相信没几个人会为了一台打不开、用不了的砖头费这么多周折。\r\n </p>\r\n <p>\r\n 我的不幸,就在于我旅游是一个人,也没有携带其它苹果设备,所以这种时候很绝望啊。\r\n </p>\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-529b587effaa9bb6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"889\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 一旦设备遗失,请认真按照文中步骤进行处理,可以很大概率止损,并让非法占有者极不痛快\r\n </div>\r\n </div>\r\n <blockquote style=\"background-color:#F7F7F7;\">\r\n 第三,购买新设备进行紧急接驳\r\n </blockquote>\r\n <p>\r\n 在丢失苹果身边又没有其它苹果的状态下如何继续生存,答案是再去购买一个苹果。\r\n </p>\r\n <p>\r\n 我们对移动支付和手机生活的过度依赖,使得我们一旦丢失了手机就会变得弱小而无助。我在云冈石窟门口遗失手机时身上只有300现金,门票130左右。哪怕我买的起票后面连吃饭坐车的钱也都没有了,于是,痛定思痛也极度郁闷的我在景区门口拐了个弯决定返回市区尽快弥补失窃带来的损失。\r\n </p>\r\n <p>\r\n 回城的车子要100元,我知道这是坐地起价,可是我必须坐。为什么?因为没有了手机,我没有地图导航,在一个完全陌生又缺少陪伴的城市里,我几乎寸步难行。我甚至不记得订好的酒店叫什么名字,回程的交通节点是何时,以及,到哪里取钱办卡买手机。老板不讲价,硬是把我留着吃饭的零钱一张张抢走凑够一百才开车(没错,真的是直接五块、十块的从我手里抽走)。\r\n </p>\r\n <p>\r\n 老板收钱办事,把我送到了销售点和吃住都比较方便的大同城墙西门华林新天地附近。可是买手机办卡又遇到了一系列波折。\r\n </p>\r\n <p>\r\n 首先,我这人恋旧,用惯了的手机还是只想买老型号,iPhone8P只有黑色的,有点遗憾但还是买了。不要觉得我在说废话,在心情不好情况不熟的情况下使用熟悉的操作系统是很重要的。在公务卡失效情况下,我用老板手机给媳妇打了电话让她给我打钱到卡里(本人不喜欢用信用卡,没有安全感)然后迅速提货。\r\n </p>\r\n <p>\r\n 如果是本地手机丢失补办原号码,只需要本人携带身份证到业务大厅便可以办理。要回号码后手机的各种关联会迅速到位,除了破点财外损失很小。可是我是异地丢失,还必须输入手机号码的验证密码。我是个恋旧的人,这个号码从当排长用到现在已经16年从未换过,可是谁记得什么手机号码的密码呀,平时也不用啊。所以,在试过一些诸如123123,以及手机号后6位的可能验证号码无效之后,我放弃了停卡补办(事实证明这一举动起到了无心插柳的好作用)。\r\n </p>\r\n <p>\r\n 我用剩下的200块钱买了几瓶饮料给手机店里帮助我的朋友,买了2包烟,买了一个新号码以及维持基本通联的最廉价套餐。此时身上只剩下了60块左右。但我终于有可能联系上此行的关键人物——我那15年未见的战友了。\r\n </p>\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-4e07ea0679261ca4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"889\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 锁定手机为丢失状态后,即便没有在遗失设备上启用定位功能,也可以遥控启用。一旦网络环境中开机你就可以快速定位设备所在位置\r\n </div>\r\n </div>\r\n <blockquote style=\"background-color:#F7F7F7;\">\r\n 第四、挑战密保限制激活生存功能\r\n </blockquote>\r\n <p>\r\n 号码与新设备不匹配会带来很多问题。比如在这台新买的iPhone上要使用统一账号ID,通常是默认为更换和升级设备,而非遗失状态下隔空操作。使用老的ID账号时需要短信验证码,可是我的手机失窃了呀。苹果这里很轴,要输入关联号码我输了,也点选了“此号码无法接受”选项,并留下了新买的号码以供发送验证短信,可它就是不给新号码发送,始终奔着老号码发送。\r\n </p>\r\n <p>\r\n 如此困难情况下我决定注册新的ID账号。可是这样的困难更大。一会儿要邮箱验证,可裸机连基本的浏览器APP都没有,你想下载APP进入苹果商店又要你提供各种ID验证信息,结果每到注册最后一步时它就提示“对不起,系统在吃必胜客,请稍后再试”。总之就是你要蛋它问你鸡呢?你要鸡它又问蛋都没有哪来鸡。\r\n </p>\r\n <p>\r\n 屡试都爽之后,我放弃了注册新ID的想法,回到了启用老ID的路上。尽管我记得Apple ID,可是手机号码短信验证是我绕不过去的双重验证必经程序。这里要划重点了啊:界面小菜单处用蓝色小字写着“不知道此号码”选项。点进去后就会出现各种密保提醒问题:“诸如你的第一辆车是什么型号,你父母在哪里认识的”这些。这些是你购买设备初期激活时需要回答的问题,请务必认真填写并牢牢记住,关键时刻能挽回全局。\r\n </p>\r\n <p>\r\n 回答完问题后你就可以临时关掉双重验证断掉与手机号码的关联。此时你必须首先更换苹果ID密码,然后你的ID就与新手机实现了接驳(与手机号码无关)。接下来你可以打开苹果商店下载所需基本软件。首先是用QQ助手找回手机联系号码,接下来是打开QQ认证关联的其它常用软件,最后是打开微信号。你在陌生设备登陆必须要手机扫码或短信验证,这两者明显不适合手机遗失的我。但是有一个微信好友辅助打开功能,就是电话联系你的两个常用好友,请他们对你的微信号聊天界面发送你提供的6位验证数字,只要成功发送你一刷新就可以在这种极端情况下启用微信了。\r\n </p>\r\n <p>\r\n 这里本应该有掌声,可是我居然把微信密码忘记了。平时都扫码或短信验证,我把号码记到了备忘录里可是手机没了我记录的东西自然也就没了呀。好啦这里继续划重点:只要你的新设备关联账号成功,苹果自带的备忘录可以打开点选后自动恢复你记录的文本信息。这个虽然普通,可是你不丢一次手机也许永远不知道。\r\n </p>\r\n <p>\r\n 就这样,我终于这么瞎打误撞的恢复了手机的大部分联系通信功能,除了微信支付因为受限于号码绑定的双验证无法使用外。我和所有要紧的人都联系上了。也通过导航软件知道了自己从哪里来?在哪里?以及该往哪里去?\r\n </p>\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-782d52b48972b8a4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"349\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 老子混蛋,儿子未必有罪,我不想把事情闹大,就给对方留个面子吧\r\n </div>\r\n </div>\r\n <blockquote style=\"background-color:#F7F7F7;\">\r\n 第五、尝试找回遗失手机\r\n </blockquote>\r\n <p>\r\n 虽然联系上了战友,但是我这次旅游算是无功而返了。买了个肯德基基础套餐后我兜里只有36块4毛零钱,买了16块的好丽来面包作第二天早午餐后我只剩下最后的20元零钱。除了生存我没法再做其它任何事了。\r\n </p>\r\n <p>\r\n 如果小偷没有走远还在大同,我要回手机就能让自己恢复到之前的“贵族”生活,所以我开始连哄带骗的发信息,我的好朋友也和我演对手戏帮我一起连哄带骗。可是小偷好不容易回了个电话还恰巧走开没有接到。\r\n </p>\r\n <p>\r\n 不过,小偷回电话,说明我们各种骚扰警告、威逼利诱已经发挥作用了。于是,继续威逼利诱,并且不断定位丢失手机的位置,警告对方我们会追你到天涯海角的。\r\n </p>\r\n <p>\r\n 即将离开太原的前一天,我终于再次接到了我原号码打来的电话。对方说手机是他家老人旅游时捡到的,还说在原地等了很久没有见到失主来找才带回了家里。老人带回手机后他儿子说要把东西还给失主于是主动联系了我。此时我告诉他能不能用他自己的手机号码联系我,我把我的收件地址发到他手机上。再次敲黑板,这是在做证据保全,手机实名认证的情况下,他的号码与我联系了也就说明他和我的手机有关联了,哪怕他后来变卦想要讹我,我也可以有足够证据证明事件过程,如果不还我,哪怕我没有证据指认他们盗窃,也可以指认他们非法占有他人财物。\r\n </p>\r\n <p>\r\n 果不其然,这个儿子一开始说话很客气,说老人也不懂请我原谅。因为急于拿回手机,我不在乎你是否承认是偷的。可在得到我违心的原谅后,这个儿子突然变了脸,马上把自己的老子粉饰成拾金不昧的好汉,那种口气恨不得我给他老子还要送面锦旗。\r\n </p>\r\n <p>\r\n 第一,我们当场质问时老家伙没有还回手机,事后拒绝配合对峙迅速离开;第二,手机丢失后我们多次发短信和致电,均未得到回应,在启动定位追踪和报警功能后才做出回应;第三,我跨越几千公里从昆明到大同的云冈石窟之旅因为这个原因折戟在景区门口;第四,因为遗失我新买了一台本不用再买的手机,造成了经济损失。还要让我对老头说谢谢?对不起这个我做不到。\r\n </p>\r\n <p>\r\n 所以,在我完全掌握主动之后我已经不再害怕你的要挟,人证、书证,甚至关联物证均在。你敢不还我就可以让你身败名裂。不怕专业小偷,他们不会轻易对安全的苹果下手。就怕这种不懂又还喜欢占便宜的蠢贼。70多岁了,很缺么?做坏事不怕遭报应么?不过因为不懂,当我暗示了他们所处位置后他们显然吓到了。也因为不懂,他们没有丢弃掉这部对他们来说无用却对我重要的手机。还是因为不懂,对方居然用自己的手机与我联系,留下了足够指证的证据。\r\n </p>\r\n <div class=\"image-package\" style=\"margin-left:-40px;text-align:center;\">\r\n <div class=\"image-container\" style=\"background-color:transparent;margin:0px auto;\">\r\n <div class=\"image-container-fill\">\r\n </div>\r\n <div class=\"image-view\">\r\n <img class=\"\" src=\"https://upload-images.jianshu.io/upload_images/10427724-03ce38b97e76d0a3.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp\" style=\"height:auto;\" width=\"500\" height=\"667\" title=\"\" align=\"\" alt=\"\" />\r\n </div>\r\n </div>\r\n <div class=\"image-caption\" style=\"padding:10px;margin:0px auto;font-size:14px;color:#969696;\">\r\n 经过这次的体验,深深感到人对电子设备的依赖已经到了令人发指的地步,看来还是有必要保留一些野性,以防一旦遭遇信息攻击后只能任人宰割。平安回到昆明,也算另一个意义上的圆满吧\r\n </div>\r\n </div>\r\n <p>\r\n 经历了这么多,这个国庆出游算是白瞎了。但是我参加了好兄弟的婚礼,给了他最有力的陪伴。也因为及时建立联系,见到了阔别15年的二班长,还让他管吃管喝解决了基本温饱。尽管有很多遗憾,但是主要目的实现了。没有这次得失,永远不知道卸下的有多轻飘,找回的有多重要。也不知道自己还是这么特别能尝试,特别能吃苦,特别能战斗。\r\n </p>\r\n <p>\r\n 因为这样的失而复得,旅程的遗憾和沮丧一扫而光。依然在成长和学习,也算重要的收获。\r\n </p>\r\n <p>\r\n 最后有一点小经验分享,手机最好的防盗措施是在人多时戴上有线耳机听歌,这是蓝牙耳机无法替代的重要功能。一旦戴着耳机手机被偷走,你马上会获得触觉听觉的复合报警提示。我这次遭殃,就是因为连续熬夜缺觉,连最基本的保护习惯都没有坚持好,希望我的遭遇能对大家有所帮助。\r\n </p>\r\n </div>\r\n </div>\r\n <p>\r\n <br />\r\n </p>\r\n', '100', '201', '2019-03-23 20:08:03', '2019-03-23 20:08:03', '1');
INSERT INTO `tb_blog` VALUES ('2', 'Spring Boot 整合 rabbitmq', null, '消息中间件的应用场景\r\n异步处理\r\n场景:用户注册,信息写入数据库后,需要给用户发送注册成功的邮件,再发送注册成功的邮件。。。。', '<p>\r\n <br />\r\n</p>\r\n<h2 id=\"一消息中间件的应用场景\" style=\"font-size:20px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 一、消息中间件的应用场景\r\n</h2>\r\n<h3 id=\"异步处理\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 异步处理\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 场景:用户注册,信息写入数据库后,需要给用户发送注册成功的邮件,再发送注册成功的邮件。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 1.同步调用:注册成功后,顺序执行发送邮件方法,发送短信方法,最后响应用户\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320113845387-729713912.png\" style=\"height:auto;\" width=\"500\" height=\"127\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 2.并行调用:注册成功后,用多线程的方式并发执行发邮件和发短信方法,最后响应用户\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320113900156-786429372.png\" style=\"height:auto;\" width=\"500\" height=\"265\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 3.消息队列:注册成功后,将要发送的消息用很短的时间写入消息队列中,之后响应用户;发送邮件的服务和发送短息的服务就可以从消息队列中异步读去,然后发送任务。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320113912692-176278267.png\" style=\"height:auto;\" width=\"500\" height=\"166\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<h3 id=\"应用解耦\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 应用解耦\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 场景:购物下单后,调用库存系统,更新库存。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 1.耦合的方式:订单系统,写调用库存系统的逻辑。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320113924859-347437808.png\" style=\"height:auto;\" />\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 2.解耦的方式:订单系统,将下达的消息写入消息队列,库存系统从消息队列中读取消息,更新库存。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320113952636-1353602023.png\" style=\"height:auto;\" />\r\n</p>\r\n<h3 id=\"流量削峰\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 流量削峰\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 秒杀场景中,我们可以设置一个定长的消息队列,秒杀开始,谁快谁先进入队列,然后快速返回用户是否秒到 ,之后在平稳的处理秒杀后的业务。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114004242-1553991013.png\" style=\"height:auto;\" width=\"500\" height=\"130\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<h1 id=\"二消息服务中间件概述\" style=\"font-size:28px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 二、消息服务中间件概述\r\n</h1>\r\n<ul style=\"margin-left:30px;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <ol>\r\n <li>\r\n 大多应用中,可通过消息服务中间件来提升系统异步通信、扩展解耦能力\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 消息服务中两个重要概念:<br />\r\n消息代理(message broker)和目的地(destination) 当消息发送者发送消息以后,将由消息代理接管,消息代理保证消息传递到指定目<br />\r\n的地。\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 消息队列主要有两种形式的目的地\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 队列(queue):点对点消息通信(point-to-point)\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 主题(topic):发布(publish)/订阅(subscribe)消息通信\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 点对点式:\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 消息发送者发送消息,消息代理将其放入一个队列中,消息接收者从队列中获取消息内容, 消息读取后被移出队列\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 消息只有唯一的发送者和接受者,但并不是说只能有一个接收者\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n 发布订阅式:\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n 发送者(发布者)发送消息到主题,多个接收者(订阅者)监听(订阅)这个主题,那么 就会在消息到达时同时收到消息\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n JMS(Java Message Service)JAVA消息服务:\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n 基于JVM消息代理的规范。ActiveMQ、HornetMQ是JMS实现\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n AMQP(Advanced Message Queuing Protocol)\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n 高级消息队列协议,也是一个消息代理的规范,兼容JMS\r\n </li>\r\n <li>\r\n RabbitMQ是AMQP的实现\r\n </li>\r\n</ul>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114016382-1214993572.png\" style=\"height:auto;\" width=\"500\" height=\"283\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<ul style=\"margin-left:30px;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <ol>\r\n <li>\r\n Spring支持\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n spring-jms提供了对JMS的支持\r\n </li>\r\n <li>\r\n spring-rabbit提供了对AMQP的支持\r\n </li>\r\n <li>\r\n 需要ConnectionFactory的实现来连接消息代理\r\n </li>\r\n <li>\r\n 提供JmsTemplate、RabbitTemplate来发送消息\r\n </li>\r\n <li>\r\n @JmsListener(JMS)、@RabbitListener(AMQP)注解在方法上监听消息代理发 布的消息\r\n </li>\r\n <li>\r\n @EnableJms、@EnableRabbit开启支持\r\n </li>\r\n <li>\r\n <ol>\r\n <li>\r\n Spring Boot自动配置\r\n </li>\r\n </ol>\r\n </li>\r\n <li>\r\n JmsAutoConfiguration\r\n </li>\r\n <li>\r\n RabbitAutoConfiguration\r\n </li>\r\n</ul>\r\n<h2 id=\"三rabbitmq简介\" style=\"font-size:20px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 三、RabbitMQ简介\r\n</h2>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n RabbitMQ是一个由erlang开发的AMQP(Advanved Message Queue Protocol)的开源实现。\r\n</p>\r\n<h3 id=\"核心概念\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 1. 核心概念\r\n</h3>\r\n<ul style=\"margin-left:30px;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <strong>Message</strong> :消息,消息是不具名的,它由消息头和消息体组成。消息体是不透明的,而消息头则由一系列的可选属性组 成,这些属性包括routing-key(路由键)、priority(相对于其他消息的优先权)、delivery-mode(指出 该消息可能需要持久性存储)等。\r\n </li>\r\n <li>\r\n <strong>Publisher</strong> :消息的生产者,也是一个向交换器发布消息的客户端应用程序。\r\n </li>\r\n <li>\r\n <strong>Exchange</strong> :交换器,用来接收生产者发送的消息并将这些消息路由给服务器中的队列。Exchange有4种类型:direct(默认),fanout, topic, 和headers,不同类型的Exchange转发消息的策略有所区别\r\n </li>\r\n <li>\r\n <strong>Queue</strong> :消息队列,用来保存消息直到发送给消费者。它是消息的容器,也是消息的终点。一个消息可投入一个或多个队列。消息一直在队列里面,等待消费者连接到这个队列将其取走。\r\n </li>\r\n <li>\r\n <strong>Binding</strong> :绑定,用于消息队列和交换器之间的关联。一个绑定就是基于路由键将交换器和消息队列连接起来的路由规则,所以可以将交换器理解成一个由绑定构成的路由表。Exchange 和Queue的绑定可以是多对多的关系。\r\n </li>\r\n <li>\r\n <strong>Connection</strong> :网络连接,比如一个TCP连接。\r\n </li>\r\n <li>\r\n <strong>Channel</strong> :信道,多路复用连接中的一条独立的双向数据流通道。信道是建立在真实的TCP连接内的虚 拟连接,AMQP 命令都是通过信道发出去的,不管是发布消息、订阅队列还是接收消息,这 些动作都是通过信道完成。因为对于操作系统来说建立和销毁 TCP 都是非常昂贵的开销,所 以引入了信道的概念,以复用一条 TCP 连接。\r\n </li>\r\n <li>\r\n <strong>Consumer</strong> :消息的消费者,表示一个从消息队列中取得消息的客户端应用程序。\r\n </li>\r\n <li>\r\n <strong>Virtual Host</strong> :虚拟主机,表示一批交换器、消息队列和相关对象。虚拟主机是共享相同的身份认证和加 密环境的独立服务器域。每个 vhost 本质上就是一个 mini 版的 RabbitMQ 服务器,拥有 自己的队列、交换器、绑定和权限机制。vhost 是 AMQP 概念的基础,必须在连接时指定, RabbitMQ 默认的 vhost 是 / 。\r\n </li>\r\n <li>\r\n <strong>Broker</strong> :表示消息队列服务器实体。\r\n </li>\r\n</ul>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114030572-222489732.png\" style=\"height:auto;\" width=\"500\" height=\"143\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<h2 id=\"四rabbitmq运行机制\" style=\"font-size:20px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 四、RabbitMQ运行机制\r\n</h2>\r\n<h3 id=\"amqp-中的消息路由\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n AMQP 中的消息路由\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n AMQP 中消息的路由过程和 Java 开发者熟悉的 JMS 存在一些差别,AMQP 中增加了 Exchange 和 Binding 的角色。生产者把消息发布到 Exchange 上,消息最终到达队列并被 消费者接收,而 Binding 决定交换器的消息应该发送到那个队列。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114044050-1531316505.png\" style=\"height:auto;\" width=\"500\" height=\"174\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<h3 id=\"exchange-类型\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Exchange 类型\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n Exchange分发消息时根据类型的不同分发策略有区别,目前共四种类型:direct、fanout、topic、headers 。headers 匹配 AMQP 消息的 header 而不是路由键, headers 交换器和 direct 交换器完全一致,但性能差很多,目前几乎用不到了,所以直接看另外三种类型:\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n [](https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114258490-1938032571.png<br />\r\n<img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114316235-301285022.png\" style=\"height:auto;\" width=\"500\" height=\"139\" title=\"\" align=\"\" alt=\"\" /><br />\r\n<img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114324738-141569216.png\" style=\"height:auto;\" width=\"500\" height=\"129\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<h2 id=\"五rabbitmq安装\" style=\"font-size:20px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 五、RabbitMQ安装\r\n</h2>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 我们使用 docker 来安装 RabbitMQ。<br />\r\n我们在 docker hub上选择官方的带management管理界面的最新版本。\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114345340-839301073.png\" style=\"height:auto;\" width=\"500\" height=\"326\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<pre><span class=\"hljs-comment\" style=\"color:green;\">#获取rabbitmq镜像</span> docker pull rabbitmq:<span class=\"hljs-number\">3</span>-management <span class=\"hljs-comment\" style=\"color:green;\">#启动 rabbitmq镜像,5672是mq通信端口,15672是mq的web管理界面端口</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">run</span><span class=\"bash\"> -d -p 5672:5672 -p 15672:15672 --name myrabbitmq 镜像ID</span></pre>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 访问127.0.0.1:15672 ,用账号:guest 密码:guest 登录,界面如下:\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <img src=\"https://img2018.cnblogs.com/blog/528977/201903/528977-20190320114401131-1269631094.png\" style=\"height:auto;\" width=\"500\" height=\"290\" title=\"\" align=\"\" alt=\"\" />\r\n</p>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 对rabbitmq的详细使用在这里,就不讲解了,我们这节的重点是整合rabbitmq。\r\n</p>\r\n<h2 id=\"六整合rabbitmq\" style=\"font-size:20px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 六、整合RabbitMQ\r\n</h2>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 创建项目引入rabbitmq依赖。\r\n</p>\r\n<h3 id=\"pom.xml\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 1. pom.xml\r\n</h3>\r\n<pre class=\"xml\"><span class=\"php\"><span class=\"hljs-meta\" style=\"color:#2B91AF;\"><?</span>xml version=<span class=\"hljs-string\" style=\"color:#A31515;\">\"1.0\"</span> encoding=<span class=\"hljs-string\" style=\"color:#A31515;\">\"UTF-8\"</span><span class=\"hljs-meta\" style=\"color:#2B91AF;\">?></span></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project</span> <span class=\"hljs-attr\" style=\"color:red;\">xmlns</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://maven.apache.org/POM/4.0.0\"</span> <span class=\"hljs-attr\" style=\"color:red;\">xmlns:xsi</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://www.w3.org/2001/XMLSchema-instance\"</span> <span class=\"hljs-attr\" style=\"color:red;\">xsi:schemaLocation</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">modelVersion</span>></span>4.0.0<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">modelVersion</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>com.gf<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>springboot-rabbitmq<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>0.0.1-SNAPSHOT<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">packaging</span>></span>jar<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">packaging</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">name</span>></span>springboot-rabbitmq<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">name</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">description</span>></span>Demo project for Spring Boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">description</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">parent</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-parent<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>2.0.5.RELEASE<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">relativePath</span>/></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- lookup parent from repository --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">parent</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">properties</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project.build.sourceEncoding</span>></span>UTF-8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project.build.sourceEncoding</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project.reporting.outputEncoding</span>></span>UTF-8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project.reporting.outputEncoding</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">java.version</span>></span>1.8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">java.version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">properties</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependencies</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-amqp<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-web<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-test<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">scope</span>></span>test<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">scope</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependencies</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">build</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">plugins</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">plugin</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-maven-plugin<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">plugin</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">plugins</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">build</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project</span>></span> </pre>\r\n<h3 id=\"myamqpconfig\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 2. MyAMQPConfig\r\n</h3>\r\n<pre class=\"java\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">package</span> com.gf.config; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.context.annotation.Bean; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.context.annotation.Configuration; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.support.converter.MessageConverter; <span class=\"hljs-comment\" style=\"color:green;\">/**\r\n * 自定义消息转换器,默认是jdk的序列化转换器,我们自定义为json的\r\n */</span> <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Configuration</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> <span class=\"hljs-title\" style=\"color:#A31515;\">MyAMQPConfig</span> </span>{ <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Bean</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> MessageConverter <span class=\"hljs-title\" style=\"color:#A31515;\">messageConverter</span><span class=\"hljs-params\">()</span> </span>{ <span class=\"hljs-keyword\" style=\"color:#0000FF;\">return</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Jackson2JsonMessageConverter();\r\n }\r\n\r\n}</pre>\r\n<h3 id=\"springboot-测试类\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 3. springboot 测试类\r\n</h3>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 我们测试创建管理配置、发送消息、接收消息\r\n</p>\r\n<pre class=\"java\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">package</span> com.gf; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.junit.Test; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.junit.runner.RunWith; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.AmqpAdmin; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.Binding; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.DirectExchange; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.FanoutExchange; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.Queue; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.TopicExchange; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.rabbit.core.RabbitTemplate; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.beans.factory.annotation.Autowired; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.boot.test.context.SpringBootTest; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.test.context.junit4.SpringRunner; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> java.util.Arrays; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> java.util.HashMap; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> java.util.Map; <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@RunWith</span>(SpringRunner.class) <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@SpringBootTest</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> <span class=\"hljs-title\" style=\"color:#A31515;\">SpringbootRabbitmqApplicationTests</span> </span>{ <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Autowired</span> RabbitTemplate rabbitTemplate; <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Autowired</span> AmqpAdmin amqpAdmin; <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Test</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">contextLoads</span><span class=\"hljs-params\">()</span> </span>{\r\n } <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Test</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">create</span><span class=\"hljs-params\">()</span></span>{ <span class=\"hljs-comment\" style=\"color:green;\">//创建Exchange</span> amqpAdmin.declareExchange( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> DirectExchange( <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.direct\"</span>) );\r\n amqpAdmin.declareExchange( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> FanoutExchange( <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.fanout\"</span>) );\r\n amqpAdmin.declareExchange( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> TopicExchange( <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.topic\"</span>) ); <span class=\"hljs-comment\" style=\"color:green;\">//创建Queue</span> amqpAdmin.declareQueue( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Queue( <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">true</span> ) );\r\n amqpAdmin.declareQueue( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Queue( <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">true</span> ) ); <span class=\"hljs-comment\" style=\"color:green;\">//绑定Queue</span> amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.direct\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.direct\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.fanout\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.fanout\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.topic\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.#\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n amqpAdmin.declareBinding( <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> Binding( <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span> , Binding.DestinationType.QUEUE , <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.topic\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.*\"</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">null</span> ) );\r\n\r\n\r\n } <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Test</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">send2Direct</span><span class=\"hljs-params\">()</span> </span>{\r\n Map<String , Object> map = <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> HashMap<>();\r\n map.put( <span class=\"hljs-string\" style=\"color:#A31515;\">\"msg\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"这是一条点对点消息\"</span> );\r\n map.put( <span class=\"hljs-string\" style=\"color:#A31515;\">\"data\"</span> , Arrays.asList(<span class=\"hljs-string\" style=\"color:#A31515;\">\"helloworld\"</span> , <span class=\"hljs-number\">123</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">true</span>) );\r\n\r\n rabbitTemplate.convertAndSend( <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.direct\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> , map );\r\n\r\n } <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Test</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">send2Topic</span><span class=\"hljs-params\">()</span> </span>{\r\n Map<String , Object> map = <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> HashMap<>();\r\n map.put( <span class=\"hljs-string\" style=\"color:#A31515;\">\"msg\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"这是一条广播消息\"</span> );\r\n map.put( <span class=\"hljs-string\" style=\"color:#A31515;\">\"data\"</span> , Arrays.asList(<span class=\"hljs-string\" style=\"color:#A31515;\">\"topic消息\"</span> , <span class=\"hljs-number\">123</span> , <span class=\"hljs-keyword\" style=\"color:#0000FF;\">true</span>) );\r\n\r\n rabbitTemplate.convertAndSend( <span class=\"hljs-string\" style=\"color:#A31515;\">\"exchange.fanout\"</span> , <span class=\"hljs-string\" style=\"color:#A31515;\">\"\"</span>, map );\r\n\r\n } <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Test</span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">receive</span><span class=\"hljs-params\">()</span> </span>{\r\n Object o = rabbitTemplate.receiveAndConvert( <span class=\"hljs-string\" style=\"color:#A31515;\">\"direct.queue\"</span> );\r\n o.getClass();\r\n System.out.println(o.getClass());\r\n System.out.println(o);\r\n }\r\n\r\n}</pre>\r\n<p style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n 监听消息\r\n</p>\r\n<h3 id=\"启动类\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 4. 启动类\r\n</h3>\r\n<pre class=\"java\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">package</span> com.gf; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.rabbit.annotation.EnableRabbit; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.boot.SpringApplication; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.boot.autoconfigure.SpringBootApplication; <span class=\"hljs-comment\" style=\"color:green;\">/**\r\n * 自动配置\r\n * 1. RabbitAutoConfiguration\r\n * 2. 自动配置了连接工厂ConnectionFactory\r\n * 3. RabbitProperties 封装了RabbitMQ的配置\r\n * 4. RabbitTemplate : 给RabbitMQ发送和接受消息\r\n * 5. AmqpAdmin : RabbitMQ系统管理功能组件\r\n * 6. <span class=\"hljs-doctag\" style=\"color:gray;\">@EnableRabbit</span> + <span class=\"hljs-doctag\" style=\"color:gray;\">@RabbitListener</span> */</span> <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@EnableRabbit</span> <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@SpringBootApplication</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> <span class=\"hljs-title\" style=\"color:#A31515;\">SpringbootRabbitmqApplication</span> </span>{ <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">static</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">main</span><span class=\"hljs-params\">(String[] args)</span> </span>{\r\n SpringApplication.run(SpringbootRabbitmqApplication.class, args);\r\n }\r\n}</pre>\r\n<h3 id=\"mqservice\" style=\"font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 5. MQService\r\n</h3>\r\n<pre class=\"java\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">package</span> com.gf.service; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.core.Message; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.amqp.rabbit.annotation.RabbitListener; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.stereotype.Service; <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Service</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> <span class=\"hljs-title\" style=\"color:#A31515;\">MQService</span> </span>{ <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@RabbitListener</span>(queues = <span class=\"hljs-string\" style=\"color:#A31515;\">\"fanout.queue\"</span>) <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">void</span> <span class=\"hljs-title\" style=\"color:#A31515;\">receive</span><span class=\"hljs-params\">(Message message)</span> </span>{\r\n System.out.println(<span class=\"hljs-string\" style=\"color:#A31515;\">\"收到消息 : \"</span> + <span class=\"hljs-keyword\" style=\"color:#0000FF;\">new</span> String(message.getBody()));\r\n\r\n }\r\n\r\n}</pre>\r\n<p>\r\n <br />\r\n</p>\r\n<p>\r\n <br />\r\n</p>', '102', '12', '2019-03-23 20:07:28', '2019-03-23 20:07:28', '2');
INSERT INTO `tb_blog` VALUES ('3', 'Spring Boot【快速入门】', '/blogManager/images/huoying.jpg', '什么是 Spring Boot\r\n它使用 “习惯优于配置” (项目中存在大量的配置,此外还内置一个习惯性的配置,让你无须)的理念让你的项目快速运行起来。。。。', '<p>\r\n <h2 id=\"spring-boot-概述\" style=\"font-size:21px;color:#009688;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 概述\r\n </h2>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <p style=\"font-size:15px;font-family:微软雅黑;\">\r\n <strong>Build Anything with Spring Boot:</strong>Spring Boot is the starting point for building all Spring-based applications. Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring.\r\n </p>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 上面是引自官网的一段话,大概是说: Spring Boot 是所有基于 Spring 开发的项目的起点。Spring Boot 的设计是为了让你尽可能快的跑起来 Spring 应用程序并且尽可能减少你的配置文件。\r\n </p>\r\n <h4 id=\"什么是-spring-boot\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 什么是 Spring Boot\r\n </h4>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 它使用 “习惯优于配置” (项目中存在大量的配置,此外还内置一个习惯性的配置,让你无须)的理念让你的项目快速运行起来。\r\n </li>\r\n <li>\r\n 它并不是什么新的框架,而是默认配置了很多框架的使用方式,就像 Maven 整合了所有的 jar 包一样,Spring Boot 整合了所有框架(引自:<a href=\"http://www.ityouknow.com/springboot/2016/01/06/springboot(%E4%B8%80)-%E5%85%A5%E9%97%A8%E7%AF%87.html\">springboot(一):入门篇——纯洁的微笑</a>)\r\n </li>\r\n </ul>\r\n <h4 id=\"使用-spring-boot-有什么好处\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 使用 Spring Boot 有什么好处\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 回顾我们之前的 SSM 项目,搭建过程还是比较繁琐的,需要:\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 1)配置 web.xml,加载 spring 和 spring mvc\r\n </li>\r\n <li>\r\n 2)配置数据库连接、配置日志文件\r\n </li>\r\n <li>\r\n 3)配置家在配置文件的读取,开启注解\r\n </li>\r\n <li>\r\n 4)配置mapper文件\r\n </li>\r\n <li>\r\n <strong>.....</strong>\r\n </li>\r\n </ul>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 而使用 Spring Boot 来开发项目则只需要非常少的几个配置就可以搭建起来一个 Web 项目,并且利用 IDEA 可以自动生成生成,这简直是太爽了...\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 划重点:简单、快速、方便地搭建项目;对主流开发框架的无配置集成;极大提高了开发、部署效率。\r\n </li>\r\n </ul>\r\n <hr />\r\n <h2 id=\"spring-boot-快速搭建\" style=\"font-size:21px;color:#009688;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 快速搭建\r\n </h2>\r\n <h4 id=\"第一步新建项目\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 第一步:新建项目\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 选择 Spring Initializr ,然后选择默认的 url 点击【Next】:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-3e2c9c5742c10c86.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"408\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 然后修改一下项目的信息:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-28dbe478ff25a3a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"408\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 勾选上 Web 模板:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-532868b7e6760e03.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"408\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 选择好项目的位置,点击【Finish】:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-931cc2fb5c8964e9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"408\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 如果是第一次配置 Spring Boot 的话可能需要等待一会儿 IDEA 下载相应的 依赖包,默认创建好的项目结构如下:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-9ac7acc56d5a32f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 项目结构还是看上去挺清爽的,少了很多配置文件,我们来了解一下默认生成的有什么:\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n SpringbootApplication: 一个带有 main() 方法的类,用于启动应用程序\r\n </li>\r\n <li>\r\n SpringbootApplicationTests:一个空的 Junit 测试了,它加载了一个使用 Spring Boot 字典配置功能的 Spring 应用程序上下文\r\n </li>\r\n <li>\r\n application.properties:一个空的 properties 文件,可以根据需要添加配置属性\r\n </li>\r\n <li>\r\n pom.xml: Maven 构建说明文件\r\n </li>\r\n </ul>\r\n <h4 id=\"第二步hellocontroller\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 第二步:HelloController\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在【cn.wmyskxz.springboot】包下新建一个【HelloController】:\r\n </p>\r\n<pre><span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">package</span> <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">cn</span><span class=\"hljs-selector-class\">.wmyskxz</span><span class=\"hljs-selector-class\">.springboot</span>; <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">import</span> <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">org</span><span class=\"hljs-selector-class\">.springframework</span><span class=\"hljs-selector-class\">.web</span><span class=\"hljs-selector-class\">.bind</span><span class=\"hljs-selector-class\">.annotation</span><span class=\"hljs-selector-class\">.RequestMapping</span>; <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">import</span> <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">org</span><span class=\"hljs-selector-class\">.springframework</span><span class=\"hljs-selector-class\">.web</span><span class=\"hljs-selector-class\">.bind</span><span class=\"hljs-selector-class\">.annotation</span><span class=\"hljs-selector-class\">.RestController</span>; <span class=\"hljs-comment\" style=\"color:green;\">/**\r\n * 测试控制器\r\n *\r\n * @author: @我没有三颗心脏\r\n * @create: 2018-05-08-下午 16:46\r\n */</span> @<span class=\"hljs-keyword\" style=\"color:#0000FF;\">RestController</span> public class HelloController {\r\n\r\n @<span class=\"hljs-keyword\" style=\"color:#0000FF;\">RequestMapping</span>(\"/<span class=\"hljs-keyword\" style=\"color:#0000FF;\">hello</span>\")\r\n public String hello() { <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">return</span> \"<span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">Hello</span> <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">Spring</span> <span class=\"hljs-selector-tag\" style=\"color:#0000FF;\">Boot</span>!\";\r\n }\r\n}</pre>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <strong>@RestController 注解:</strong> 该注解是 @Controller 和 @ResponseBody 注解的合体版\r\n </li>\r\n </ul>\r\n <h4 id=\"第三步利用-idea-启动-spring-boot\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 第三步:利用 IDEA 启动 Spring Boot\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们回到 SpringbootApplication 这个类中,然后右键点击运行:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-bf1aa6ed5c0db7b4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"340\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <strong>注意</strong>:我们之所以在上面的项目中没有手动的去配置 Tomcat 服务器,是因为 Spring Boot 内置了 Tomcat\r\n </li>\r\n </ul>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 等待一会儿就会看到下方的成功运行的提示信息:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-63e43dc6a277de3e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"179\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 可以看到我们的 Tomcat 运行在 8080 端口,我们来访问 “/hello” 地址试一下:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-6111e1913c5bf6d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 可以看到页面成功显示出我们返回的信息。\r\n </p>\r\n <hr />\r\n <h2 id=\"解析-spring-boot-项目\" style=\"font-size:21px;color:#009688;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 解析 Spring Boot 项目\r\n </h2>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <p style=\"font-size:15px;font-family:微软雅黑;\">\r\n 这一部分参考自:<a href=\"http://tengj.top/2017/02/26/springboot1/\">Spring Boot干货系列(一)优雅的入门篇 ——嘟嘟独立博客</a>\r\n </p>\r\n </blockquote>\r\n <h4 id=\"解析-pom.xml-文件\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 解析 pom.xml 文件\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 让我们来看看默认生成的 pom.xml 文件中到底有一些什么特别:\r\n </p>\r\n<pre><span class=\"php\"><span class=\"hljs-meta\" style=\"color:#2B91AF;\"><?</span>xml version=<span class=\"hljs-string\" style=\"color:#A31515;\">\"1.0\"</span> encoding=<span class=\"hljs-string\" style=\"color:#A31515;\">\"UTF-8\"</span><span class=\"hljs-meta\" style=\"color:#2B91AF;\">?></span></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project</span> <span class=\"hljs-attr\" style=\"color:red;\">xmlns</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://maven.apache.org/POM/4.0.0\"</span> <span class=\"hljs-attr\" style=\"color:red;\">xmlns:xsi</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://www.w3.org/2001/XMLSchema-instance\"</span> <span class=\"hljs-attr\" style=\"color:red;\">xsi:schemaLocation</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">modelVersion</span>></span>4.0.0<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">modelVersion</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>cn.wmyskxz<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>springboot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>0.0.1-SNAPSHOT<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">packaging</span>></span>jar<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">packaging</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">name</span>></span>springboot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">name</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">description</span>></span>Demo project for Spring Boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">description</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">parent</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-parent<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>2.0.1.RELEASE<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">relativePath</span>/></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- lookup parent from repository --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">parent</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">properties</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project.build.sourceEncoding</span>></span>UTF-8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project.build.sourceEncoding</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">project.reporting.outputEncoding</span>></span>UTF-8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project.reporting.outputEncoding</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">java.version</span>></span>1.8<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">java.version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">properties</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependencies</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-web<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-test<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">scope</span>></span>test<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">scope</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependencies</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">build</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">plugins</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">plugin</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-maven-plugin<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">plugin</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">plugins</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">build</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">project</span>></span></pre>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们可以看到一个比较陌生一些的标签 <parent> ,这个标签是在配置 Spring Boot 的父级依赖:\r\n </p>\r\n<pre><span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">parent</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-starter-parent<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>2.0.1.RELEASE<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">relativePath</span>/></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- lookup parent from repository --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">parent</span>></span></pre>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 有了这个,当前的项目才是 Spring Boot 项目,spring-boot-starter-parent 是一个特殊的 starter ,它用来提供相关的 Maven 默认依赖,<strong>使用它之后,常用的包依赖就可以省去 version 标签。</strong>\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 关于具体 Spring Boot 提供了哪些 jar 包的依赖,我们可以查看本地 Maven 仓库下:\\repository\\org\\springframework\\boot\\spring-boot-dependencies\\2.0.1.RELEASE\\spring-boot-dependencies-2.0.1.RELEASE.pom 文件来查看,挺长的...\r\n </p>\r\n <h4 id=\"应用入口类\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 应用入口类\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n Spring Boot 项目通常有一个名为 *Application 的入口类,入口类里有一个 main 方法, <strong>这个 main 方法其实就是一个标准的 Javay 应用的入口方法。</strong>\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <strong>@SpringBootApplication</strong> 是 Spring Boot 的核心注解,它是一个组合注解,该注解组合了:<strong>@Configuration、@EnableAutoConfiguration、@ComponentScan;</strong> 若不是用 @SpringBootApplication 注解也可以使用这三个注解代替。\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 其中,<strong>@EnableAutoConfiguration 让 Spring Boot 根据类路径中的 jar 包依赖为当前项目进行自动配置</strong>,例如,添加了 spring-boot-starter-web 依赖,会自动添加 Tomcat 和 Spring MVC 的依赖,那么 Spring Boot 会对 Tomcat 和 Spring MVC 进行自动配置。\r\n </li>\r\n <li>\r\n <strong>Spring Boot 还会自动扫描 @SpringBootApplication 所在类的同级包以及下级包里的 Bean</strong> ,所以入口类建议就配置在 grounpID + arctifactID 组合的包名下(这里为 cn.wmyskxz.springboot 包)\r\n </li>\r\n </ul>\r\n <h4 id=\"spring-boot-的配置文件\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 的配置文件\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n Spring Boot 使用一个全局的配置文件 application.properties 或 application.yml,放置在【src/main/resources】目录或者类路径的 /config 下。\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n Spring Boot 不仅支持常规的 properties 配置文件,还支持 yaml 语言的配置文件。yaml 是以数据为中心的语言,在配置数据的时候具有面向对象的特征。\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n Spring Boot 的全局配置文件的作用是对一些默认配置的配置值进行修改。\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 简单实例一下\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-bcd65f7469b06608.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们同样的将 Tomcat 默认端口设置为 8080 ,并将默认的访问路径从 “/” 修改为 “/hello” 时,使用 properties 文件和 yml 文件的区别如上图。\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 注意: yml 需要在 “:” 后加一个空格,幸好 IDEA 很好地支持了 yml 文件的格式有良好的代码提示;\r\n </li>\r\n </ul>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 我们可以自己配置多个属性\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们直接把 .properties 后缀的文件删掉,使用 .yml 文件来进行简单的配置,然后使用 @Value 来获取配置属性:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-0e808a82254d6a4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 重启 Spring Boot ,输入地址:localhost:8080/hello 能看到正确的结果:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-c85216e8ea7910f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <strong>注意:</strong> 我们并没有在 yml 文件中注明属性的类型,而是在使用的时候定义的。\r\n </li>\r\n </ul>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 你也可以在配置文件中使用当前配置:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-37e91abbc4550982.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 仍然可以得到正确的结果:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-eabc3cd39b44fd0d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n <strong>问题:</strong> 这样写配置文件繁琐而且可能会造成类的臃肿,因为有许许多多的 @Value 注解。\r\n </li>\r\n </ul>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 封装配置信息\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-2599817d8f2f50d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们可以把配置信息封装成一个类,首先在我们的 name 和 age 前加一个 student 前缀,然后新建一个 StudentProperties 的类用来封装这些信息,并用上两个注解:\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n @Component:表明当前类是一个 Java Bean\r\n </li>\r\n <li>\r\n @ConfigurationProperties(prefix = \"student\"):表示获取前缀为 sutdent 的配置信息\r\n </li>\r\n </ul>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 这样我们就可以在控制器中使用,重启得到正确信息:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-84dc1215d01f3fa9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <h4 id=\"spring-boot-热部署\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 热部署\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在目前的 Spring Boot 项目中,当发生了任何修改之后我们都需要重新启动才能够正确的得到效果,这样会略显麻烦,Spring Boot 提供了热部署的方式,当发现任何类发生了改变,就会通过 JVM 类加载的方式,加载最新的类到虚拟机中,这样就不需要重新启动也能看到修改后的效果了。\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 做法也很简单,修改 pom.xml 即可!\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们往 pom.xml 中添加一个依赖就可以了:\r\n </p>\r\n<pre><span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.springframework.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>spring-boot-devtools<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">optional</span>></span>true<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">optional</span>></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- 这个需要为 true 热部署才有效 --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span></pre>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 重新启动 Spring Boot ,然后修改任意代码,就能观察到控制台的自动重启现象:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-cec869956c3cf158.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"500\" height=\"205\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <p style=\"font-size:15px;font-family:微软雅黑;\">\r\n 关于如何在 IDEA 中配置热部署:<a href=\"https://blog.csdn.net/xusheng_Mr/article/details/78771746\">传送门</a>\r\n </p>\r\n </blockquote>\r\n <hr />\r\n <h2 id=\"spring-boot-使用\" style=\"font-size:21px;color:#009688;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 使用\r\n </h2>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 上面已经完成了 Spring Boot 项目的简单搭建,我们仅仅需要进行一些简单的设置,写一个 HelloController 就能够直接运行了,不要太简单...接下来我们再深入了解一下 Spring Boot 的使用。\r\n </p>\r\n <h4 id=\"spring-boot-支持-jsp\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n Spring Boot 支持 JSP\r\n </h4>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n Spring Boot 的默认视图支持是 Thymeleaf 模板引擎,但是这个我们不熟悉啊,我们还是想要使用 JSP 怎么办呢?\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第一步:修改 pom.xml 增加对 JSP 文件的支持\r\n </li>\r\n </ul>\r\n </blockquote>\r\n<pre><span class=\"hljs-comment\" style=\"color:green;\"><!-- servlet依赖. --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>javax.servlet<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>javax.servlet-api<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">scope</span>></span>provided<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">scope</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>javax.servlet<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>jstl<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- tomcat的支持.--></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.apache.tomcat.embed<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>tomcat-embed-jasper<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">scope</span>></span>provided<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">scope</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span></pre>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第二步:配置试图重定向 JSP 文件的位置\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 修改 application.yml 文件,将我们的 JSP 文件重定向到 /WEB-INF/views/ 目录下:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-7c17f7e10cfb2629.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第三步:修改 HelloController\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 修改 @RestController 注解为 @Controller ,然后将 hello 方法修改为:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-2dc2c39cd962edc1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" width=\"50\" height=\"23\" title=\"\" align=\"\" alt=\"\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第四步:新建 hello.jsp 文件\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在【src/main】目录下依次创建 webapp、WEB-INF、views 目录,并创建一个 hello.jsp 文件:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-a180556d7ead9605.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第五步:刷新网页\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 因为我们部署了热部署功能,所以只需要等待控制台重启信息完成之后再刷新网页就可以看到正确效果了:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-cfd20f747ffca978.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <ul style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">\r\n <li>\r\n 关于 404,使用 spring-boot:run 运行项目可以解决:\r\n </li>\r\n </ul>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-27c1bf46487ba5eb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <h4 id=\"集成-mybatis\" style=\"color:#009688;font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n 集成 MyBatis\r\n </h4>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第一步:修改 pom.xml 增加对 MySql和 MyBatis 的支持\r\n </li>\r\n </ul>\r\n </blockquote>\r\n<pre><span class=\"hljs-comment\" style=\"color:green;\"><!-- mybatis --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>org.mybatis.spring.boot<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>mybatis-spring-boot-starter<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>1.1.1<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-comment\" style=\"color:green;\"><!-- mysql --></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">dependency</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">groupId</span>></span>mysql<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">groupId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">artifactId</span>></span>mysql-connector-java<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">artifactId</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">version</span>></span>5.1.21<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">version</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">dependency</span>></span></pre>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第二步:新增数据库链接参数\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 这里我们就直接使用之前创建好的 student 表了吧:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-1eda563cfdfbae65.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第三步:创建 Student 实体类和 StudentMapper 映射类\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在【cn.wmyskxz.springboot】下新建一个【pojo】包,然后在其下创建一个 Student 类:\r\n </p>\r\n<pre><span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> Student { <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> Integer id; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> Integer student_id; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> <span class=\"hljs-built_in\" style=\"color:#0000FF;\">String</span> name; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> Integer age; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> <span class=\"hljs-built_in\" style=\"color:#0000FF;\">String</span> sex; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">private</span> <span class=\"hljs-built_in\" style=\"color:#0000FF;\">Date</span> birthday;\r\n\r\n /* getter <span class=\"hljs-keyword\" style=\"color:#0000FF;\">and</span> setter */\r\n}</pre>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在【cn.wmyskxz.springboot】下新建一个【mapper】包,然后在其下创建一个 StudentMapper 映射类:\r\n </p>\r\n<pre><span class=\"hljs-keyword\" style=\"color:#0000FF;\">package</span> cn.wmyskxz.springboot.mapper; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> cn.wmyskxz.springboot.pojo.Student; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.apache.ibatis.annotations.Mapper; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.apache.ibatis.annotations.Select; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> java.util.List; <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Mapper</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">interface</span> <span class=\"hljs-title\" style=\"color:#A31515;\">StudentMapper</span> </span>{ <span class=\"hljs-meta\" style=\"color:#2B91AF;\">@Select</span>(<span class=\"hljs-string\" style=\"color:#A31515;\">\"SELECT * FROM student\"</span>) <span class=\"hljs-function\">List<Student> <span class=\"hljs-title\" style=\"color:#A31515;\">findAll</span><span class=\"hljs-params\">()</span></span>;\r\n}</pre>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第四步:编写 StudentController\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 在【cn.wmyskxz.springboot】下新建一个【controller】包,然后在其下创建一个 StudentController :\r\n </p>\r\n<pre>package cn.wmyskxz.springboot.controller; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> cn.wmyskxz.springboot.mapper.StudentMapper; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> cn.wmyskxz.springboot.pojo.Student; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.beans.factory.annotation.Autowired; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.stereotype.Controller; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.ui.Model; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> org.springframework.web.bind.annotation.RequestMapping; <span class=\"hljs-keyword\" style=\"color:#0000FF;\">import</span> java.util.List; <span class=\"hljs-comment\" style=\"color:green;\">/**\r\n * Student 控制器\r\n *\r\n * @author: @我没有三颗心脏\r\n * @create: 2018-05-08-下午 20:25\r\n */</span> @<span class=\"hljs-type\" style=\"color:#A31515;\">Controller</span> <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-class\"><span class=\"hljs-keyword\" style=\"color:#0000FF;\">class</span> <span class=\"hljs-title\" style=\"color:#A31515;\">StudentController</span> </span>{\r\n\r\n @<span class=\"hljs-type\" style=\"color:#A31515;\">Autowired</span> <span class=\"hljs-type\" style=\"color:#A31515;\">StudentMapper</span> studentMapper;\r\n\r\n @<span class=\"hljs-type\" style=\"color:#A31515;\">RequestMapping</span>(<span class=\"hljs-string\" style=\"color:#A31515;\">\"/listStudent\"</span>) <span class=\"hljs-keyword\" style=\"color:#0000FF;\">public</span> <span class=\"hljs-type\" style=\"color:#A31515;\">String</span> listStudent(<span class=\"hljs-type\" style=\"color:#A31515;\">Model</span> model) { <span class=\"hljs-type\" style=\"color:#A31515;\">List</span><<span class=\"hljs-type\" style=\"color:#A31515;\">Student</span>> students = studentMapper.findAll();\r\n model.addAttribute(<span class=\"hljs-string\" style=\"color:#A31515;\">\"students\"</span>, students); <span class=\"hljs-keyword\" style=\"color:#0000FF;\">return</span> <span class=\"hljs-string\" style=\"color:#A31515;\">\"listStudent\"</span>;\r\n }\r\n}</pre>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <p style=\"font-size:15px;font-family:微软雅黑;\">\r\n 第五步:编写 listStudent.jsp 文件\r\n </p>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 我们简化一下 JSP 的文件,仅显示两个字段的数据:\r\n </p>\r\n<pre><span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">%@</span> <span class=\"hljs-attr\" style=\"color:red;\">page</span> <span class=\"hljs-attr\" style=\"color:red;\">language</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"java\"</span> <span class=\"hljs-attr\" style=\"color:red;\">contentType</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"text/html; charset=UTF-8\"</span> <span class=\"hljs-attr\" style=\"color:red;\">pageEncoding</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"UTF-8\"</span>%></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">%@</span> <span class=\"hljs-attr\" style=\"color:red;\">taglib</span> <span class=\"hljs-attr\" style=\"color:red;\">uri</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"http://java.sun.com/jsp/jstl/core\"</span> <span class=\"hljs-attr\" style=\"color:red;\">prefix</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"c\"</span>%></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">table</span> <span class=\"hljs-attr\" style=\"color:red;\">align</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\'center\'</span> <span class=\"hljs-attr\" style=\"color:red;\">border</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\'1\'</span> <span class=\"hljs-attr\" style=\"color:red;\">cellspacing</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\'0\'</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">tr</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">td</span>></span>id<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">td</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">td</span>></span>name<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">td</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">tr</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">c:forEach</span> <span class=\"hljs-attr\" style=\"color:red;\">items</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"${students}\"</span> <span class=\"hljs-attr\" style=\"color:red;\">var</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"s\"</span> <span class=\"hljs-attr\" style=\"color:red;\">varStatus</span>=<span class=\"hljs-string\" style=\"color:#A31515;\">\"st\"</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">tr</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">td</span>></span>${s.id}<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">td</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"><<span class=\"hljs-name\">td</span>></span>${s.name}<span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">td</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">tr</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">c:forEach</span>></span> <span class=\"hljs-tag\" style=\"color:#0000FF;\"></<span class=\"hljs-name\">table</span>></span></pre>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <ul>\r\n <li>\r\n 第六步:重启服务器运行\r\n </li>\r\n </ul>\r\n </blockquote>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n 因为往 pom.xml 中新增加了依赖的包,所以自动重启服务器没有作用,我们需要手动重启一次,然后在地址输入:localhost:8080/listStudent 查看效果:\r\n </p>\r\n <p style=\"font-size:15px;color:#595959;font-family:微软雅黑;background-color:#FFFFFF;\">\r\n <img src=\"https://upload-images.jianshu.io/upload_images/7896890-5fd3c075d07b5840.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240\" style=\"height:auto;\" />\r\n </p>\r\n <blockquote style=\"background:none #FFFFFF;color:#777777;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;\">\r\n <p style=\"font-size:15px;font-family:微软雅黑;\">\r\n 以上。\r\n </p>\r\n </blockquote>\r\n</p>\r\n<p>\r\n <br />\r\n</p>', '23', '12', '2019-03-23 20:07:49', '2019-03-23 20:07:49', '2');
INSERT INTO `tb_blog` VALUES ('4', 'CentOS7.5 安装MySQL8 tar', null, '1、查看是否安装mariadb,执行命令:显示:2、卸载mariadb,执行命令:3、安装mysql 依赖包4、创建mysql 安装包上传路径\r\n5、创建mysql 安装目录6、安装目录赋权限:\r\n。。。。', '<p>\r\n <span><span><span><span>\r\n <div class=\"article-header-box\" style=\"margin:0px;padding:16px 0px 0px;background-color:#FFFFFF;color:#333333;font-family:"font-size:14px;\">\r\n <div class=\"article-header\" style=\"margin:0px;padding:0px;\">\r\n <div class=\"article-title-box\" style=\"margin:0px 0px 8px;padding:0px;\">\r\n <h1 class=\"title-article\" style=\"font-size:24px;\">\r\n CentOS7.5 安装MySQL8 tar\r\n </h1>\r\n </div>\r\n <div class=\"article-info-box\" style=\"margin:0px;padding:0px 0px 14px;\">\r\n <div class=\"article-bar-top\" style=\"margin:0px;padding:0px;color:#858585;\">\r\n <span class=\"time\">2018年07月08日 02:13:21</span> <a class=\"follow-nickName\" href=\"https://me.csdn.net/xintingandzhouyang\" target=\"_blank\">xintingandzhouyang</a> <span class=\"read-count\">阅读数:2584</span>\r\n </div>\r\n <div class=\"operating\" style=\"margin:0px;padding:0px;\">\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n <div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" style=\"margin:0px;padding:0px;\">\r\n <div class=\"htmledit_views\" id=\"content_views\" style=\"margin:0px;padding:0px;font-family:-apple-system, "\">\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t0\"></a>1、查看是否安装mariadb\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># rpm -qa | grep mariadb</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 显示:\r\n </p>\r\n<pre class=\"has\"><span class=\"hljs-selector-tag\" style=\"color:#E45649;\">mariadb-libs-5</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.5</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.56-2</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.el7</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.x86_64</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708015835414?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t1\"></a>2、卸载mariadb\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 执行命令:\r\n </p>\r\n<pre class=\"has\"><span class=\"hljs-selector-attr\" style=\"color:#986801;\">[root@mysql ~]</span># <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">rpm</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">-e</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">--nodeps</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">mariadb-libs-5</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.5</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.56-2</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.el7</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.x86_64</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020015419?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t2\"></a>3、安装mysql 依赖包\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql bin]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># yum install libaio</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020052616?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t3\"></a>4、创建mysql 安装包上传路径\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># mkdir /usr/soft</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 安装包上目录赋权限:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># chmod -R 777 /usr/soft</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 使用SSH工具上传mysql 安装包\r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t4\"></a>5、创建mysql 安装目录\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># mkdir /usr/local/mysql</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 创建mysql 数据存放目录,执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># mkdir /usr/local/mysql/mysqldb</span></pre>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t5\"></a>6、安装目录赋权限:\r\n </h3>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># chmod -R 777/usr/local/mysql/</span> [root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># chmod -R 777/usr/local/mysql/mysqldb/</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 解压mysql 安装包执行命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql ~]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cd /usr/soft/</span> [root@mysql soft]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># tar -xvf mysql-8.0.11-el7-x86_64.tar</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020307496?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <span style=\"color:#FF0000;\"><span style=\"font-weight:700;\">解压:mysql-8.0.11-el7-x86_64.tar.gz</span></span>\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\"><span class=\"hljs-selector-attr\" style=\"color:#986801;\">[root@mysql soft]</span># <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">tar</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">-xzvf</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">mysql-8</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.0</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.11-el7-x86_64</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.tar</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.gz</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 复制解压结果到mysql 安装目录:\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cp -rf /usr/soft/mysql-8.0.11-el7-x86_64/ /usr/local/mysql</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t6\"></a>7、创建MySQL 组:\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 创建mysql 组\r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># groupadd mysql</span> </pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 创建MySQL用户但该用户不能登陆(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限)\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># useradd -r -g mysql -s /bin/false mysql</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 把刚创建的mysql用户加入到mysql组下:\r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># chown-R mysql:mysql ./</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t7\"></a>8、创建mysql 安装初始化配置文件\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># vi /etc/my.cnf</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 添加下面这段命令后保存并退出:\r\n </p>\r\n<pre class=\"has\">[<span class=\"hljs-meta\" style=\"color:#4078F2;\">mysqld</span>] <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 设置3306端口</span> port=<span class=\"hljs-number\" style=\"color:#986801;\">3306</span> <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 设置mysql的安装目录</span> basedir=/usr/local/mysql <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 设置mysql数据库的数据的存放目录</span> datadir=/usr/local/mysql/mysqldb <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 允许最大连接数</span> max_connections=<span class=\"hljs-number\" style=\"color:#986801;\"><a href=\"https://www.baidu.com/s?wd=10000&tn=24004469_oem_dg&rsv_dl=gh_pl_sl_csd\" target=\"_blank\">10000</a></span> <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统</span> max_connect_errors=<span class=\"hljs-number\" style=\"color:#986801;\">10</span> <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 服务端使用的字符集默认为UTF8</span> character-<span class=\"hljs-keyword\" style=\"color:#A626A4;\">set</span>-server=utf8 <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 创建新表时将使用的默认存储引擎</span> <span class=\"hljs-keyword\" style=\"color:#A626A4;\">default</span>-storage-engine=INNODB <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 默认使用“mysql_native_password”插件认证</span> default_authentication_plugin=mysql_native_password\r\n[<span class=\"hljs-meta\" style=\"color:#4078F2;\">mysql</span>] <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 设置mysql客户端默认字符集</span> <span class=\"hljs-keyword\" style=\"color:#A626A4;\">default</span>-character-<span class=\"hljs-keyword\" style=\"color:#A626A4;\">set</span>=utf8\r\n[<span class=\"hljs-meta\" style=\"color:#4078F2;\">client</span>] <span class=\"hljs-meta\" style=\"color:#4078F2;\"># 设置mysql客户端连接服务端时默认使用的端口</span> port=<span class=\"hljs-number\" style=\"color:#986801;\">3306</span> <span class=\"hljs-keyword\" style=\"color:#A626A4;\">default</span>-character-<span class=\"hljs-keyword\" style=\"color:#A626A4;\">set</span>=utf8</pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020718697?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t8\"></a>9、安装mysql\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 进入mysql 安装目录下:\r\n </p>\r\n<pre class=\"has\">[root@mysql mysql-<span class=\"hljs-number\" style=\"color:#986801;\">8.0</span>.<span class=\"hljs-number\" style=\"color:#986801;\">11</span>-el7-x86_64]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cd/usr/local/mysql/bin/</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 安装MySQL,并记住随机命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql bin]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># ./mysqld --initialize --console</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020819400?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t9\"></a><span>10、启动MySQL服务:</span>\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\">[root@mysql mysql]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cd support-files/</span> [root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># ./mysql.server start</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 备注:当执行./mysql.server start命令报以下错误时:\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020908255?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 在mysql安装目录下重新授权后,再次自行启动MySQL命令:\r\n </p>\r\n<pre class=\"has\">[root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># chmod -R 777 /usr/local/mysql</span> [root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># ./mysql.server start</span></pre>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <span><img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708020956135?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" /></span>\r\n </h3>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t11\"></a><span>11、mysql加入系统进程中:</span>\r\n </h3>\r\n<pre class=\"has\">[root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cp mysql.server /etc/init.d/mysqld</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 重启MySQL服务:\r\n </p>\r\n<pre class=\"has\">[root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># service mysqld restart</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708021054154?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t12\"></a><span>12、修改随机登陆密码:</span>\r\n </h3>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n<pre class=\"has\">[root@mysql support-files]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cd ../</span> [root@mysql mysql]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># cd bin/</span> [root@mysql bin]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># ./mysql -u root –p</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708021139328?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 修改密码:\r\n </p>\r\n<pre class=\"has\">mysql> alter user <span class=\"hljs-string\" style=\"color:#50A14F;\">\'root\'</span>@<span class=\"hljs-string\" style=\"color:#50A14F;\">\'localhost\'</span> IDENTIFIED <span class=\"hljs-keyword\" style=\"color:#A626A4;\">WITH</span> mysql_native_password BY <span class=\"hljs-string\" style=\"color:#50A14F;\">\'root\'</span>;</pre>\r\n <h3 style=\"font-size:22px;font-family:"color:#4F4F4F;\">\r\n <a name=\"t13\"></a><span>13、设置允许远程登陆:</span>\r\n </h3>\r\n<pre class=\"has\">mysql> use mysql\r\nmysql> update user <span class=\"hljs-keyword\" style=\"color:#A626A4;\">set</span> user.Host=<span class=\"hljs-string\" style=\"color:#50A14F;\">\'%\'</span><span class=\"hljs-keyword\" style=\"color:#A626A4;\">where</span> user.User=<span class=\"hljs-string\" style=\"color:#50A14F;\">\'root\'</span>;\r\nmysql> flush privileges;\r\nQuery OK, <span class=\"hljs-number\" style=\"color:#986801;\">0</span> <span class=\"hljs-function\">rows <span class=\"hljs-title\" style=\"color:#4078F2;\">affected</span> (<span class=\"hljs-params\"><span class=\"hljs-number\" style=\"color:#986801;\">0.00</span> sec</span>)</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <img alt=\"\" class=\"has\" src=\"https://img-blog.csdn.net/20180708021223223?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnRpbmdhbmR6aG91eWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70\" />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n \r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n mysql> quit\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n Bye\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 重启mysql服务:\r\n </p>\r\n<pre class=\"has\">[root@mysql bin]<span class=\"hljs-comment\" style=\"color:#A0A1A7;font-style:italic;\"># service mysqld restart</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n <span style=\"font-weight:700;\">14、禁用防火墙</span>\r\n </p>\r\n<pre class=\"has\"><span class=\"hljs-selector-attr\" style=\"color:#986801;\">[root@mysql bin]</span># <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">systemctl</span> <span class=\"hljs-selector-tag\" style=\"color:#E45649;\">stopfirewalld</span><span class=\"hljs-selector-class\" style=\"color:#986801;\">.service</span></pre>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;\">\r\n 安装完成;\r\n </p>\r\n </div>\r\n </div>\r\n</span></span></span></span>\r\n</p>\r\n<p>\r\n <span><span><span><span></span></span></span></span> \r\n</p>', '12', '12', '2019-03-22 10:36:10', '2019-03-22 10:36:10', '7');
INSERT INTO `tb_blog` VALUES ('5', 'centos7 firewall-cmd查看端口是否开放及开放端口', null, '查询端口号80 是否开启:firewall-cmd --query-port=80/tcp\r\n\r\n\r\n\r\n永久开放80端口号:firewall-cmd --permanent --zone=public --add-port=80/tcp。。。', '<p>\r\n <div class=\"article-header-box\" style=\"margin:0px;padding:16px 0px 0px;background-color:#FFFFFF;\">\r\n <div class=\"article-header\" style=\"margin:0px;padding:0px;\">\r\n <div class=\"article-title-box\" style=\"margin:0px 0px 8px;padding:0px;\">\r\n <h1 class=\"title-article\" style=\"font-size:24px;font-family:"\">\r\n centos7 firewall-cmd查看端口是否开放及开放端口\r\n </h1>\r\n </div>\r\n <div class=\"article-info-box\" style=\"margin:0px;padding:0px 0px 14px;\">\r\n <div class=\"article-bar-top\" style=\"margin:0px;padding:0px;color:#858585;\">\r\n 2018年04月13日 09:44:43 <a class=\"follow-nickName\" href=\"https://me.csdn.net/tongdengquan\" target=\"_blank\">童大大</a> 阅读数:352更多\r\n <div class=\"tags-box space\" style=\"margin:6px 0px 0px;padding:0px;\">\r\n 个人分类: <a class=\"tag-link\" href=\"https://blog.csdn.net/tongdengquan/article/category/6470209\" target=\"_blank\">Linux</a>\r\n </div>\r\n </div>\r\n <div class=\"operating\" style=\"margin:0px;padding:0px;\">\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n <div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" style=\"margin:0px;padding:0px;\">\r\n <div class=\"htmledit_views\" id=\"content_views\" style=\"margin:0px;padding:0px;font-family:-apple-system, "\">\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n 文章出处 https://blog.csdn.net/y534560449/article/details/65629697\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <span style=\"font-family:"color:#333333;\">查询端口号80 是否开启:</span><span style=\"font-family:"color:#FF0000;\">firewall-cmd </span><span style=\"font-family:"color:#3333FF;\">--query-port</span><span style=\"font-family:"color:#FF0000;\">=</span><span style=\"font-family:"color:#33CC00;\">80</span><span style=\"font-family:"color:#FF0000;\">/</span><span style=\"font-family:"color:#33FF33;\">tcp</span>\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#333333;background-color:#FFFFFF;\">\r\n <br />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <span style=\"font-family:"color:#333333;\">永久开放80端口号:</span><span style=\"font-family:"color:#FF0000;\">firewall-cmd --permanent --zone=public </span><span style=\"font-family:"color:#3333FF;\">--add-port</span><span style=\"font-family:"color:#FF0000;\">=</span><span style=\"font-family:"color:#33CC00;\">80</span><span style=\"font-family:"color:#FF0000;\">/</span><span style=\"font-family:"color:#33CC00;\">tcp</span>\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <br />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n 移除80端口号:<span style=\"font-family:"color:#FF0000;\">firewall-cmd --permanent --zone=public</span><span style=\"font-family:"color:#3333FF;\"> --remove-port</span><span style=\"font-family:"color:#FF0000;\">=</span><span style=\"font-family:"color:#009900;\">80</span><span style=\"font-family:"color:#FF0000;\">/</span><span style=\"font-family:"color:#33CC00;\">tcp</span>\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <br />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <span style=\"font-family:"color:#333333;\">--zone #作用域<br />\r\n--add-port=80/tcp #添加端口,格式为:</span><span style=\"font-family:"color:#FF6666;\">端口/通讯协议</span><br />\r\n<span style=\"font-family:"color:#333333;\">--permanent #永久生效,没有此参数重启后失效</span>\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#333333;background-color:#FFFFFF;\">\r\n <br />\r\n </p>\r\n <p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <span style=\"font-family:"color:#333333;\">查看防火墙状态</span><br />\r\n<span style=\"font-family:"color:#FF0000;\">systemctl </span><span style=\"font-family:"color:#3333FF;\">status </span><span style=\"font-family:"color:#FF0000;\">firewalld.service</span><br />\r\n<span style=\"font-family:"color:#333333;\">启动|关闭|重新启动 防火墙</span><br />\r\n<span style=\"font-family:"color:#FF0000;\">systemctl </span><span style=\"font-family:"color:#3333FF;\">[</span><span style=\"font-family:"color:#009900;\">start</span><span style=\"font-family:"color:#3333FF;\">|</span><span style=\"font-family:"color:#009900;\">stop</span><span style=\"font-family:"color:#3333FF;\">|</span><span style=\"font-family:"color:#009900;\">restart</span><span style=\"font-family:"color:#3333FF;\">] </span><span style=\"font-family:"color:#FF0000;\">firewalld.service </span>\r\n </p>\r\n <div>\r\n <br />\r\n </div>\r\n </div>\r\n </div>\r\n</p>\r\n<p>\r\n <br />\r\n</p>', '45', '23', '2019-03-23 20:04:01', '2019-03-23 20:04:01', '7');
INSERT INTO `tb_blog` VALUES ('6', 'redis常用命令大全', null, '1.基于内存的key-value数据库\r\n2.基于c语言编写的,可以支持多种语言的api //set每秒11万次,取get 81000次\r\n3.支持数据持久化\r\n4.value可以是string,hash, list, set, sorted set。。。', '<span><span>\r\n<h1 class=\"postTitle\" style=\"font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n <a id=\"cb_post_title_url\" class=\"postTitle2\" href=\"https://www.cnblogs.com/cxxjohnson/p/9072383.html\">redis常用命令大全</a>\r\n</h1>\r\n<div class=\"clear\" style=\"margin:0px;padding:0px;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;background-color:#FFFFFF;\">\r\n</div>\r\n<div class=\"postBody\" style=\"margin:0px;padding:0px;color:#111111;font-size:13px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\r\n <div id=\"cnblogs_post_body\" class=\"blogpost-body\" style=\"margin:0px 0px 20px;padding:0px;\">\r\n <div class=\"cnblogs_code\" style=\"margin:5px 0px;padding:5px;background-color:#F5F5F5;border:1px solid #CCCCCC;color:#000000;font-family:"font-size:12px !important;\">\r\n <div class=\"cnblogs_code_toolbar\" style=\"margin:5px 0px 0px;padding:0px;\">\r\n <span class=\"cnblogs_code_copy\" style=\"line-height:1.5 !important;\"><a><img src=\"https://common.cnblogs.com/images/copycode.gif\" alt=\"复制代码\" style=\"height:auto;\" /></a></span>\r\n </div>\r\n<pre><span style=\"line-height:1.5 !important;\">1.基于内存的key-value数据库\r\n2.基于c语言编写的,可以支持多种语言的api //set每秒11万次,取get 81000次\r\n3.支持数据持久化\r\n4.value可以是string,hash, list, set, sorted set\r\n\r\n使用场景\r\n1. 去最新n个数据的操作\r\n2. 排行榜,取top n个数据 //最佳人气前10条\r\n3. 精确的设置过期时间\r\n4. 计数器\r\n5. 实时系统, 反垃圾系统\r\n6. pub, sub发布订阅构建实时消息系统\r\n7. 构建消息队列\r\n8. 缓存 <img src=\"https://img2018.cnblogs.com/blog/798174/201903/798174-20190321203330649-499029266.png\" alt=\"\" width=\"387\" height=\"257\" style=\"height:auto;\" /></span></pre>\r\n<pre><span style=\"line-height:1.5 !important;\">cmd访问redis\r\nredis-cli.exe -h 127.0.0.1 -p 6379\r\n\r\n\r\nkey\r\n keys * 获取所有的key\r\n select 0 选择第一个库\r\n move myString 1 将当前的数据库key移动到某个数据库,目标库有,则不能移动\r\n flush db 清除指定库\r\n randomkey 随机key\r\n type key 类型\r\n \r\n set key1 value1 设置key\r\n get key1 获取key\r\n mset key1 value1 key2 value2 key3 value3\r\n mget key1 key2 key3\r\n del key1 删除key\r\n exists key 判断是否存在key\r\n expire key 10 10过期\r\n pexpire key 1000 毫秒\r\n persist key 删除过期时间\r\n\r\nstring\r\n set name cxx\r\n get name\r\n getrange name 0 -1 字符串分段\r\n getset name new_cxx 设置值,返回旧值\r\n mset key1 key2 批量设置\r\n mget key1 key2 批量获取\r\n setnx key value 不存在就插入(not exists)\r\n setex key time value 过期时间(expire)\r\n setrange key index value 从index开始替换value\r\n incr age 递增\r\n incrby age 10 递增\r\n decr age 递减\r\n decrby age 10 递减\r\n incrbyfloat 增减浮点数\r\n append 追加\r\n strlen 长度\r\n getbit/setbit/bitcount/bitop 位操作\r\n \r\nhash\r\n hset myhash name cxx\r\n hget myhash name\r\n hmset myhash name cxx age 25 note \"i am notes\"\r\n hmget myhash name age note \r\n hgetall myhash 获取所有的\r\n hexists myhash name 是否存在\r\n hsetnx myhash score 100 设置不存在的\r\n hincrby myhash id 1 递增\r\n hdel myhash name 删除\r\n hkeys myhash 只取key\r\n hvals myhash 只取value\r\n hlen myhash 长度\r\n\r\nlist\r\n lpush mylist a b c 左插入\r\n rpush mylist x y z 右插入\r\n lrange mylist 0 -1 数据集合\r\n lpop mylist 弹出元素\r\n rpop mylist 弹出元素\r\n llen mylist 长度\r\n lrem mylist count value 删除\r\n lindex mylist 2 指定索引的值\r\n lset mylist 2 n 索引设值\r\n ltrim mylist 0 4 删除key\r\n linsert mylist before a 插入\r\n linsert mylist after a 插入\r\n rpoplpush list list2 转移列表的数据\r\n \r\nset\r\n sadd myset redis \r\n smembers myset 数据集合\r\n srem myset set1 删除\r\n sismember myset set1 判断元素是否在集合中\r\n scard key_name 个数\r\n sdiff | sinter | sunion 操作:集合间运算:差集 | 交集 | 并集\r\n srandmember 随机获取集合中的元素\r\n spop 从集合中弹出一个元素\r\n \r\nzset\r\n zadd zset 1 one\r\n zadd zset 2 two\r\n zadd zset 3 three\r\n zincrby zset 1 one 增长分数\r\n zscore zset two 获取分数\r\n zrange zset 0 -1 withscores 范围值\r\n zrangebyscore zset 10 25 withscores 指定范围的值\r\n zrangebyscore zset 10 25 withscores limit 1 2 分页\r\n Zrevrangebyscore zset 10 25 withscores 指定范围的值\r\n zcard zset 元素数量\r\n Zcount zset 获得指定分数范围内的元素个数\r\n Zrem zset one two 删除一个或多个元素\r\n Zremrangebyrank zset 0 1 按照排名范围删除元素\r\n Zremrangebyscore zset 0 1 按照分数范围删除元素\r\n Zrank zset 0 -1 分数最小的元素排名为0\r\n Zrevrank zset 0 -1 分数最大的元素排名为0\r\n Zinterstore\r\n zunionstore rank:last_week 7 rank:20150323 rank:20150324 rank:20150325 weights 1 1 1 1 1 1 1\r\n \r\n \r\n排序:\r\n sort mylist 排序\r\n sort mylist alpha desc limit 0 2 字母排序\r\n sort list by it:* desc by命令\r\n sort list by it:* desc get it:* get参数\r\n sort list by it:* desc get it:* store sorc:result sort命令之store参数:表示把sort查询的结果集保存起来\r\n\r\n订阅与发布:\r\n 订阅频道:subscribe chat1\r\n 发布消息:publish chat1 \"hell0 ni hao\"\r\n 查看频道:pubsub channels\r\n 查看某个频道的订阅者数量: pubsub numsub chat1\r\n 退订指定频道: unsubscrible chat1 , punsubscribe java.*\r\n 订阅一组频道: psubscribe java.*\r\n \r\nredis事物:\r\n 隔离性,原子性, \r\n 步骤: 开始事务,执行命令,提交事务\r\n multi //开启事务\r\n sadd myset a b c\r\n sadd myset e f g\r\n lpush mylist aa bb cc\r\n lpush mylist dd ff gg\r\n\r\n服务器管理\r\n dump.rdb\r\n appendonly.aof\r\n //BgRewriteAof 异步执行一个aop(appendOnly file)文件重写\r\n 会创建当前一个AOF文件体积的优化版本\r\n \r\n //BgSave 后台异步保存数据到磁盘,会在当前目录下创建文件dump.rdb\r\n //save同步保存数据到磁盘,会阻塞主进程,别的客户端无法连接\r\n \r\n //client kill 关闭客户端连接\r\n //client list 列出所有的客户端\r\n \r\n //给客户端设置一个名称\r\n client setname myclient1\r\n client getname\r\n \r\n config get port\r\n //configRewrite 对redis的配置文件进行改写 </span></pre>\r\n <p>\r\n rdb <br />\r\nsave 900 1<br />\r\nsave 300 10<br />\r\nsave 60 10000\r\n </p>\r\n<pre></pre>\r\n <p>\r\n aop备份处理<br />\r\nappendonly yes 开启持久化<br />\r\nappendfsync everysec 每秒备份一次\r\n </p>\r\n<pre></pre>\r\n <p>\r\n 命令:<br />\r\nbgsave异步保存数据到磁盘(快照保存)<br />\r\nlastsave返回上次成功保存到磁盘的unix的时间戳<br />\r\nshutdown同步保存到服务器并关闭redis服务器<br />\r\nbgrewriteaof文件压缩处理(命令)\r\n </p>\r\n </div>\r\n </div>\r\n</div>\r\n</span></span><span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span>', '43', '25', '2019-03-23 20:03:57', '2019-03-23 20:03:57', '4');
INSERT INTO `tb_blog` VALUES ('7', 'JAVA 安装与配置', null, 'JAVA 安装与配置\r\nJDK是整个java的核心,包括java的运行环境、java工具和java基础类库。。。', '<span><span><span><span>JAVA安装与配置JDK是整个Java的的核心,包括的Java的运行环境,JAVA工具和Java的基础类库。一,安装JDK获得JDK,登录甲骨文网站http://www.oracle.com/technetwork/java/javase /downloads/index.html下载并安装.1。双击下载的exe,如jdk-7u5-windows-i586.exe.2。进入安装向导.clip_image002 3.下一步,更改安装路径,选择安装所有组件clip_image004 4 。下一步,clip_image006 5.更改jre安装路径.clip_image008 6.下一步.clip_image010 7.完成.clip_image012二,设置环境变量1。</span><span>JAVA_HOME机子装JDK的目录。变量值:C:\\ Java \\ jdk1.7.0_09右键计算机=“属性=”高级系统设置=“环境变量=”系统变量=“新建系统变量clip_image014 2. PATH指定可执行程序的位置。变量值:例如:%JAVA_HOME%\\ bin; </span></span>\r\n<h1 class=\"postTitle\" style=\"font-size:14px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FEFEF2;\">\r\n <a id=\"cb_post_title_url\" class=\"postTitle2\" href=\"https://www.cnblogs.com/ottox/p/3313540.html\"><span><span>JAVA安装与配置</span></span></a>\r\n</h1>\r\n<div class=\"clear\" style=\"margin:0px;padding:0px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FEFEF2;\">\r\n</div>\r\n<div class=\"postBody\" style=\"margin:5px 0px 0px;padding:5px 2px 5px 5px;font-size:13px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FEFEF2;\">\r\n <div id=\"cnblogs_post_body\" class=\"blogpost-body\" style=\"margin:0px 0px 20px;padding:0px;\">\r\n <p>\r\n <span><span>JDK是整个Java的的核心,包括的Java的运行环境,JAVA工具和Java的基础类库。</span></span>\r\n </p>\r\n <p>\r\n <span><span>一,安装JDK</span></span>\r\n </p>\r\n <p>\r\n <span><span>获得JDK,登录甲骨文网站</span></span><a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\"><span><span>http://www.oracle.com/technetwork/java/javase/downloads/index.html</span></span></a>\r\n </p>\r\n <p>\r\n <span><span>下载并安装。</span></span>\r\n </p>\r\n <p>\r\n <span><span>1.双击下载的exe,如jdk-7u5-windows-i586.exe。</span></span>\r\n </p>\r\n <p>\r\n <span><span>2.进入安装向导。</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220507-cddc2b899aa5422bb4c40726179020bd.jpg\"><img title=\"clip_image002\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220507-3bac04dcf71e47908f217041c7e064a6.jpg\" alt=\"clip_image002\" width=\"244\" height=\"188\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>3.下一步,更改安装路径,选择安装所有组件</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220508-0aac0fe7fa3f40889aa6e2ecbc480d39.jpg\"><img title=\"clip_image004\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220508-a724e965b8b14ed2ae10c8badaedb24f.jpg\" alt=\"clip_image004\" width=\"244\" height=\"188\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>下一步,</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220508-191aee50838b42fc9128c1bc622bfdde.jpg\"><img title=\"clip_image006\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220509-9b2ab7eeb5e74a348f05be976f9d46d7.jpg\" alt=\"clip_image006\" width=\"244\" height=\"188\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>5.更改jre安装路径。</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220509-53a40e10610d41b5b8c142adea3f80b1.jpg\"><img title=\"clip_image008\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220510-6a7c00c2dbba41c0be9a34477ebca27b.jpg\" alt=\"clip_image008\" width=\"244\" height=\"187\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>6.下一步。</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220510-a3d93296ccc34e03ab45d5618a7efb16.jpg\"><img title=\"clip_image010\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220510-93b4e663678a48149642941674235de5.jpg\" alt=\"clip_image010\" width=\"244\" height=\"188\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>7.完成。</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220511-c1acceaa1c0b4762968fae393b01a09a.jpg\"><img title=\"clip_image012\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220511-9d84b651119f4471923e2a901a5c3a46.jpg\" alt=\"clip_image012\" width=\"244\" height=\"188\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>二,设置环境变量</span></span>\r\n </p>\r\n <p>\r\n <span><span>1. JAVA_HOME机子装JDK的目录。变量值:C:\\ Java \\ jdk1.7.0_09</span></span>\r\n </p>\r\n <p>\r\n <span><span>右键计算机=“属性=”高级系统设置=“环境变量=”系统变量=“新建系统变量</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220512-93af0c358a344c8c876b079a5f75b9a4.jpg\"><img title=\"clip_image014\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220512-d82c5212ffa24537a92d9aadf8de2036.jpg\" alt=\"clip_image014\" width=\"244\" height=\"111\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>2. PATH指定可执行程序的位置。变量值:例如:%JAVA_HOME%\\ bin;</span></span>\r\n </p>\r\n <p>\r\n <span><span>即“C:\\ PROGRAMFILES \\的Java \\ jdk1.7.0 \\ BIN; </span><span>”</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220512-333abd29876447959e4b0f7b1fc7d4b0.jpg\"><img title=\"clip_image015\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220513-93b7b25087c647ef98299da525e6a07f.jpg\" alt=\"clip_image015\" width=\"244\" height=\"101\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n <p>\r\n <span><span>说明:%..........%的意思是引用%JAVA_HOME%就是引用d:\\ java的\\ jdk1.7.0_03这个目录。</span></span>\r\n </p>\r\n <p>\r\n <span><span>3.配置好以后就要测试一下是否成功</span></span>\r\n </p>\r\n <p>\r\n <span><span>开始=“运行=”CMD回车在弹出的DOS窗口内</span></span>\r\n </p>\r\n <p>\r\n <span><span>输入:java -version会出现版本信息,</span></span>\r\n </p>\r\n <p>\r\n <span><span>输入:javac出现javac的用法信息</span></span>\r\n </p>\r\n <p>\r\n <span><span>如果如下图所示则表示配置成功,反之则配置失败</span></span>\r\n </p>\r\n <p>\r\n <a href=\"https://images0.cnblogs.com/blog/45031/201309/10220513-a31c68cec10e4c7d8c6b45881547f4a9.jpg\"><img title=\"clip_image017\" src=\"https://images0.cnblogs.com/blog/45031/201309/10220514-34fe4db0553146b6a19452cfb20a12da.jpg\" alt=\"clip_image017\" width=\"244\" height=\"160\" border=\"0\" style=\"height:auto;\" /></a>\r\n </p>\r\n </div>\r\n</div>\r\n</span><span><span><span></span></span></span></span>', '456', '123', '2019-03-23 20:03:53', '2019-03-23 20:03:53', '3');
INSERT INTO `tb_blog` VALUES ('8', 'Spring Security 简介', null, '在 Web 应用开发中,安全一直是非常重要的一个方面。安全虽然属于应用的非功能性需求,但是应该在应用开发的初期就考虑进来。如果在应用开发的后期才考虑安全的问题,就可能陷入一个两难的境地:一方面,应用存在严重的安全漏洞,无法满足用户的要求,并可能造成用户的隐私数据被攻击者窃取。。。', '<span><span>\r\n<p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n Spring Security 简介 <br />\r\nSpring 是一个非常流行和成功的 Java 应用开发框架。Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性的完整解决方案。一般来说,Web 应用的安全性包括用户认证(Authentication)和用户授权(Authorization)两个部分。用户认证指的是验证某个用户是否为系统中的合法主体,也就是说用户能否访问该系统。用户认证一般要求用户提供用户名和密码。系统通过校验用户名和密码来完成认证过程。用户授权指的是验证某个用户是否有权限执行某个操作。在一个系统中,不同用户所具有的权限是不同的。比如对一个文件来说,有的用户只能进行读取,而有的用户可以进行修改。一般来说,系统会为不同的用户分配不同的角色,而每个角色则对应一系列的权限。\r\n</p>\r\n<p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n 对于上面提到的两种应用情景,Spring Security 框架都有很好的支持。在用户认证方面,Spring Security 框架支持主流的认证方式,包括 HTTP 基本认证、HTTP 表单验证、HTTP 摘要认证、OpenID 和 LDAP 等。在用户授权方面,Spring Security 提供了基于角色的访问控制和访问控制列表(Access Control List,ACL),可以对应用中的领域对象进行细粒度的控制。\r\n</p>\r\n<p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n 本文将通过三个具体的示例来介绍 Spring Security 的使用。第一个示例是一个简单的企业员工管理系统。该系统中存在三类用户,分别是普通员工、经理和总裁。不同类别的用户所能访问的资源不同。对这些资源所能执行的操作也不相同。Spring Security 能帮助开发人员以简单的方式满足这些安全性相关的需求。第二个示例展示了如何与 LDAP <a href=\"https://www.baidu.com/s?wd=%E6%9C%8D%E5%8A%A1%E5%99%A8&tn=24004469_oem_dg&rsv_dl=gh_pl_sl_csd\" target=\"_blank\">服务器</a>进行集成。第三个示例展示了如何与 OAuth 进行集成。完整的示例代码见参考资料。下面首先介绍基本的用户认证和授权的实现。\r\n</p>\r\n<p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n 基本用户认证和授权 <br />\r\n本节从最基本的用户认证和授权开始对 Spring Security 进行介绍。一般来说,Web 应用都需要保存自己系统中的用户信息。这些信息一般保存在数据库中。用户可以注册自己的账号,或是由系统管理员统一进行分配。这些用户一般都有自己的角色,如普通用户和管理员之类的。某些页面只有特定角色的用户可以访问,比如只有管理员才可以访问 /admin 这样的网址。下面介绍如何使用 Spring Security 来满足这样基本的认证和授权的需求。\r\n</p>\r\n<br />\r\n</span></span><!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><!-- 加载配置文件 --><!-- spring security 的过滤器配置 --><!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><!-- Spring --><!-- Spring security --><span><span></span><span></span></span>', '56', '12', '2019-03-23 20:03:41', '2019-03-23 20:03:44', '5');
INSERT INTO `tb_blog` VALUES ('9', 'freemarker简介', null, ' FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写。FreeMarker被设计用来生成HTMLWeb页面,特别是基于MVC模式的应用程序。。。。', '<span><span> \r\n<p style=\"font-family:"font-size:16px;color:#4F4F4F;background-color:#FFFFFF;\">\r\n <span><span><span><span>Spring Security简介 </span></span></span></span><span><span> FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写.FreeMarker被设计用来生成HTMLWeb页面,特别是基于MVC模式的应用程序。</span></span><br />\r\n<br />\r\n<span><span> 所谓模板,就是一份已经写好了基本内容,有着固定格式的文档,其中空出或者用占位符标识</span><span>,由使用者来填充,不同的使用者给出的数据是不同</span><span>。在模板中的占位符,在模板运行时,由模板引入来解析模板,并采用动态数据替换占位符部分的内容.FreeMarker</span><span> 不是一个Web应用框架,而适合作为Web应用框架一个组件,FreeMarker与Web容器无关,即在Web运行时,它并不知道的Servlet或HTTP。它不仅可以用作表现层的实现</span><span>,而且还可以用于生成XML,JSP或Java的文件等。</span><span> 虽然FreeMarker的具有一些编程的能力,但通常由Java的程序准备要显示的数据,由FreeMarker的生成页面,通过模板显示准备的数据(如下 </span><span>图)</span><span>分离表现层状语从句:业务逻辑</span><span> 使用JSP开发过程中在页面中大量的</span><span>,使得页面内容凌乱,在后期大量的修改维护过程中</span><span>.FreeMarker根本不支持Java的脚本代码,而是使用EL表达式来输出展示数据.FreeMarker的设计初衷就是:模板+数据模型=输出,模板只负责数据在页面中的</span><span>,不涉及任何的逻辑代码,而所有的逻辑都是由数据模型来处理的。用户最终看到的输出是模板和</span><span>。</span><span>提高开发效率</span></span><span><span>在模板运行时,由模板引擎来解析模板,并采用动态数据替换占位符部分的内容。</span></span><br />\r\n<br />\r\n<span></span><br />\r\n<br />\r\n<span></span><br />\r\n<br />\r\n<br />\r\n<br />\r\n <br />\r\n<br />\r\n<span></span><br />\r\n<br />\r\n<span></span><br />\r\n<br />\r\n <br />\r\n<br />\r\n <br />\r\n<br />\r\n<span></span><br />\r\n<br />\r\n<span><span> 在我们以往的开发中,使用的都是JSP页面来展示数据的,即所谓的表现层。我们都知道,JSP在第一次执行的时候需要转换成</span><span>Servlet的类,开发阶段进行功能调适时,需要频繁的修改JSP,每次修改都要编译和转换,那么试想一天中我们浪费在程序编译的时间有多少</span><span>。相对于JSP来说,FreeMarker的模板技术不存在编译和转换的问题</span><span>,所以就不会存在上述问题。而且开发过程中,我们在不必在等待界面设计开发人员完成页面原形后</span><span>,我们再来开发程序。</span></span><br />\r\n<br />\r\n <br />\r\n<br />\r\n <br />\r\n<br />\r\n<span><span>分工明确</span></span><br />\r\n<br />\r\n<span><span> 以往用JSP展现数据时,程序员并不熟悉界面设计技术,反之界面开发人员,也并不熟悉程序语言协调工作很困难</span><span>,使用的FreeMarker后,作为界面开发人员,只专心创建HTML文件,图像以及网站页面的其他可视化方面,不用理会数据;而程序开发人员则专注于系统实现</span><span>,负责为页面准备要显示的数据</span></span><br />\r\n<!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><!-- 加载配置文件 --><!-- spring security 的过滤器配置 --><!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><!-- Spring --><!-- Spring security --><span><span></span><span></span></span>\r\n</p>\r\n</span></span>', '56', '25', '2019-03-23 20:05:49', '2019-03-23 20:05:51', '6');
INSERT INTO `tb_blog` VALUES ('26', '2019年清明节还在学校学习', null, '今天是2019年的4月5日,我国传统的节日清明节。昨天上午就已经放假了,可惜可悲,为了生活,还是要努力学习。学习了一天,没想到放假学习效率挺高的。英语四级没有过,上午做了一篇四级阅读。。。', '<p style=\"text-align:center;\">\n <strong><span style=\"font-size:32px;\">2019年清明节还在学校学习</span></strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><span style=\"font-size:32px;\"><span style=\"font-size:9px;\"><span style=\"font-size:10px;\"><span style=\"font-size:16px;\"> 今天是2019年的4月5日,我国传统的节日清明节。昨天上午就已经放假了,可惜可悲,为了生活,还是要努力学习。学习了一天,没想到放假学习效率挺高的。英语四级没有过,上午做了一篇四级阅读,记录了其中不知道的单词。然后在午饭前看了我的专业书,最近买了一本《图解TCP/IP协议》,今天看了一眼,讲的很好,通俗易懂,适合我这种菜鸟,哈哈哈。来爆一张我看书。</span></span></span></span></strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><span style=\"font-size:32px;\"><span style=\"font-size:12px;\"></span><img src=\"/blogManager/images/8BA94E29A5B02230CBAAE71D7A3D5064.jpg\" alt=\"\" width=\"483\" height=\"900\" title=\"\" align=\"\" /></span></strong>\n</p>\n<p style=\"text-align:left;\">\n <span style=\"font-size:16px;\"><b>因为现在我是大三下去的学生了,马上要毕业,今天准备把我买的java面试宝典看了看</b></span>\n</p>\n<p style=\"text-align:left;\">\n <span style=\"font-size:16px;\"><b><img src=\"/blogManager/images/93C82CF49E3A339F1FDF855599A5E48F.jpg\" alt=\"\" width=\"400\" height=\"745\" title=\"\" align=\"\" /><br />\n</b></span>\n</p>\n<p style=\"text-align:left;\">\n <span style=\"font-size:16px;\"><b>今天就做了这么几件事,哈哈哈,感觉还是挺充实的呀,再等几分钟,就去看电视去了,写完这篇博客就差不多了,最近喜欢上了腾讯视频的新版倚天屠龙记,感觉还是可以,因为小时候没有看懂。好了就到这里了,这怕是我第一次为我的网站写的博客吧,哈哈哈。好了去追剧去了,明天继续学习。。。。。</b></span>\n</p>\n<p style=\"text-align:left;\">\n <span style=\"font-size:32px;\"><b><br />\n</b></span>\n</p>', '10', '23', '2019-04-05 06:43:10', '2019-04-05 06:43:10', '17');
INSERT INTO `tb_blog` VALUES ('34', 'Java文件上传', '/title_pics/upload.png', '为什么需要文件上传? 在用户注册的时候,可能需要用户提交照片。那么这张照片就应该要进行保存。 上传组件(工具) 为什么我们要使用上传工具?', '<p style=\"text-align:center;\">\n <span style=\"font-size:18px;\"><strong></strong></span><span style=\"font-size:18px;\"><strong>Java文件上传细讲</strong></span> \n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">我们需要上传组件</span> \n</p>\n<p>\n <br />\n</p>\n<ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n <strong>FileUpload【操作比较复杂】</strong> \n </li>\n</ul>\n<ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n <strong>SamrtUpload【操作比较简单】</strong> \n </li>\n</ul>\n<p>\n <br />\n</p>\n<p>\n 主要讲解fileupload\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">要使用FileUpload组件,就需要导入两个jar包</span>\n</p>\n<p>\n <br />\n</p>\n<ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n <strong>commons-io</strong>\n </li>\n</ul>\n<ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n <strong>Commons-fileupload</strong>\n </li>\n</ul>\n<h2 id=\"articleHeader7\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;font-size:1.75em;background-color:#FFFFFF;\">\n 快速入门\n</h2>\n<pre class=\"prettyprint lang-java\"> try{\n \n //1.得到解析器工厂\n DiskFileItemFactory factory = new DiskFileItemFactory();\n \n //2.得到解析器\n ServletFileUpload upload = new ServletFileUpload(factory);\n \n //3.判断上传表单的类型\n if(!upload.isMultipartContent(request)){\n //上传表单为普通表单,则按照传统方式获取数据即可\n return;\n }\n \n //为上传表单,则调用解析器解析上传数据\n List<FileItem> list = upload.parseRequest(request); //FileItem\n \n //遍历list,得到用于封装第一个上传输入项数据fileItem对象\n for(FileItem item : list){\n \n if(item.isFormField()){\n //得到的是普通输入项\n String name = item.getFieldName(); //得到输入项的名称\n String value = item.getString();\n System.out.println(name + \"=\" + value);\n }else{\n //得到上传输入项\n String filename = item.getName(); //得到上传文件名 C:\\Documents and Settings\\ThinkPad\\桌面\\1.txt\n filename = filename.substring(filename.lastIndexOf(\"\\\\\")+1);\n InputStream in = item.getInputStream(); //得到上传数据\n int len = 0;\n byte buffer[]= new byte[1024];\n \n \n String savepath = this.getServletContext().getRealPath(\"/upload\");\n FileOutputStream out = new FileOutputStream(savepath + \"\\\\\" + filename); //向upload目录中写入文件\n while((len=in.read(buffer))>0){\n out.write(buffer, 0, len);\n }\n \n in.close();\n out.close();\n }\n }\n \n }catch (Exception e) {\n e.printStackTrace();\n }</pre>\n<h1 id=\"articleHeader12\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;background-color:#FFFFFF;\">\n 上传文件名的中文乱码和上传数据的中文乱码\n</h1>\n //设置upload的编码<br />\n fileUpload.setHeaderEncoding(\"UTF-8\");<br />\n<div>\n <br />\n String value = fileItem.getString(\"UTF-8\");<br />\n<br />\n</div>\n<h1 id=\"articleHeader16\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;background-color:#FFFFFF;\">\n 多个文件上传,动态添加上传控件\n</h1>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">假设我现在有多个文件要上传,而且要</span><strong>上传的个数是不确定的</strong><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">。那么我们要怎么办呢???</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\"><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">我们不可能列出很多很多个上传文件的控件在页面上,这样不美观。</span><br />\n</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">所以,我们想要动态地增添上传文件的控件,</span><strong>如果用户还想要上传文件,只需要动态地生成控件出来即可!</strong>\n</p>\n<p>\n <ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n 页面代码:\n </li>\n </ul>\n<pre class=\"prettyprint lang-html\">\n\n<table border=\"1px\">\n\n <tr>\n <td>上传用户:</td>\n <td><input type=\"text\" name=\"username\"></td>\n </tr>\n\n <tr>\n <td>添加上传文件</td>\n <td><input type=\"button\" value=\"添加上传文件\" onclick=\"addUploadFile()\"> </td>\n </tr>\n\n <tr>\n\n <td>\n <div id=\"file\">\n </div>\n </td>\n </tr>\n\n</table>\n</pre>\n <ul style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n <li>\n javaScript代码\n </li>\n </ul>\n<pre class=\"prettyprint lang-js\">\n <script type=\"text/javascript\">\n\n function addUploadFile() {\n\n //生成文件上传控件\n var input = document.createElement(\"input\");\n input.type = \'file\';\n input.name = \'fileName\';\n\n\n //生成删除按钮\n var del = document.createElement(\"input\");\n del.type = \'button\';\n del.value = \'删除\';\n\n //生成内部的div\n var innerDiv = document.createElement(\"div\");\n\n //将两个控件绑定到内部div上\n innerDiv.appendChild(input);\n innerDiv.appendChild(del);\n\n //得到外部div控件,并将内部div绑定到外部div上\n var outterDiv = document.getElementById(\"file\");\n outterDiv.appendChild(innerDiv);\n\n //为删除按钮绑定事件\n del.onclick = function dele() {\n\n //调用外界div的remove方法把内部的div干掉\n this.parentNode.parentNode.removeChild(this.parentNode);\n }\n\n }\n\n </script>\n</pre>\n <h1 id=\"articleHeader19\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;background-color:#FFFFFF;\">\n 文件上传细节\n </h1>\n<span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">如果</span>上传文件的大小大于我们设定文件的大小<span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">,那么文件在</span>上传的时候会使用临时文件保存上传数据<span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">。</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">在上传完毕后,我们</span>应该删除临时文件\n</p>\n<p>\n 上传文件的位置是不能在WEB服务器管理之下的,否则可能造成安全问题【其他人有可能通过手段来修改上传文件】\n</p>\n<p>\n <strong>如果上传文件名相同,那么就会把原本的上传文件覆盖掉</strong><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">。我们要生成一个独一无二的文件名。</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">如果用户量很大,上传文件非常多。那么我们</span><strong>不应该在一个目录保存所有的上传文件,</strong>\n</p>\n<p>\n <strong>这样很可能造成磁盘奔溃了</strong><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">。所以我们要</span><strong>把上传的文件打散到不同的目录下</strong><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">。</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\"><img src=\"/blogManager/images/fenxi.png\" alt=\"\" width=\"680\" height=\"265\" title=\"\" align=\"\" /><br />\n</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\"><span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">下面我们写一个比较完善的上传文件代码</span></span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\"><strong>hashCode算法来打散保存的目录</strong><br />\n</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">\n<pre class=\"prettyprint lang-java\">\n private String makeDirPath(String fileName, String path) {\n\n //通过文件名来算出一级目录和二级目录\n int hashCode = fileName.hashCode();\n int dir1 = hashCode & 0xf;\n int dir2 = (hashCode & 0xf0) >> 4;\n\n String dir = path + \"\\\\\" + dir1 + \"\\\\\" + dir2;\n\n //如果该目录不存在,就创建目录\n File file = new File(dir);\n if (!file.exists()) {\n\n file.mkdirs();\n }\n //返回全路径\n return dir;\n\n }</pre>\n<pre class=\"prettyprint lang-java\"><strong>生成独一无二的文件名</strong> \n<pre class=\"prettyprint lang-java\">\n\n private String makeFileName(String fileName) {\n\n //使用下划线把UUID和文件名分割开来,后面可能会解析文件名的。\n return UUID.randomUUID().toString() + \"_\"+ fileName;\n\n }</pre>\n上传的代码\n</pre>\n<pre class=\"prettyprint lang-java\">\n<pre class=\"prettyprint lang-java\">\n\n //创建工厂\n DiskFileItemFactory factory = new DiskFileItemFactory();\n\n //通过工厂创建解析器\n ServletFileUpload fileUpload = new ServletFileUpload(factory);\n\n //设置upload的编码\n fileUpload.setHeaderEncoding(\"UTF-8\");\n\n //判断上传表单的类型\n if(!fileUpload.isMultipartContent(request)){\n //上传表单为普通表单,则按照传统方式获取数据即可\n return;\n }\n\n try {\n\n //解析request对象,得到List【装载着上传的全部内容】\n List<FileItem> list = fileUpload.parseRequest(request);\n\n //遍历List,判断装载的内容是普通字段还是上传文件\n for (FileItem fileItem : list) {\n\n //如果是普通输入项\n if (fileItem.isFormField()) {\n\n //得到输入项的名称和值\n String name = fileItem.getFieldName();\n String value = fileItem.getString(\"UTF-8\");\n\n System.out.println(name + \" = \" + value);\n } else {\n\n //如果是上传文件\n\n //得到上传名称【包括路径名】\n String fileName = fileItem.getName();\n\n //截取文件名\n fileName = fileName.substring(fileName.lastIndexOf(\"\\\\\") + 1);\n\n //生成独一无二的文件名\n fileName = makeFileName(fileName);\n\n InputStream inputStream = fileItem.getInputStream();\n\n //得到项目的路径,把上传文件写到项目中\n String path = this.getServletContext().getRealPath(\"/WEB-INF/uploadFile\");\n\n //得到分散后的目录路径\n String realPath = makeDirPath(fileName, path);\n\n FileOutputStream outputStream = new FileOutputStream(realPath + \"\\\\\" + fileName);\n\n byte[] bytes = new byte[1024];\n int len = 0;\n while ((len = inputStream.read(bytes)) > 0) {\n outputStream.write(bytes, 0, len);\n }\n\n inputStream.close();\n outputStream.close();\n\n //删除临时文件的数据\n fileItem.delete();\n\n }\n }\n\n } catch (FileUploadException e) {\n e.printStackTrace();\n }\n</pre>\n<span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">把目录打散,文件名也是独一无二的了。</span><br />\n</pre>\n<img src=\"/blogManager/images/xg.png\" alt=\"\" /><br />\n</span>\n</p>\n<p>\n <span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\"><br />\n</span>\n</p>\n<p>\n <h1 id=\"articleHeader23\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;background-color:#FFFFFF;\">\n 列出上传目录下的文件,提供下载\n </h1>\n<img src=\"/blogManager/images/Q6Q9EBHSJG~64%}3$%6O]UO.png\" alt=\"\" /><img src=\"/blogManager/images/Q6Q9EBHSJG~64%}3$%6O]UO.png\" alt=\"\" /><img src=\"/blogManager/images/fx.png\" alt=\"\" width=\"680\" height=\"234\" title=\"\" align=\"\" />\n</p>\n<p>\n <h2 id=\"articleHeader25\" style=\"font-family:-apple-system, BlinkMacSystemFont, "font-weight:500;color:#333333;font-size:1.75em;background-color:#FFFFFF;\">\n 代码\n </h2>\n<strong>在WEB-INF/目录下的文件全部放在Map集合中</strong>\n</p>\n<p>\n<pre class=\"prettyprint lang-java\">\n\n protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\n\n //得到上传文件的目录\n String filePath = this.getServletContext().getRealPath(\"/WEB-INF/uploadFile\");\n\n Map map = new HashMap();\n\n //使用递归来得到所有的文件,并添加到Map集合中\n getAllFiles(new File(filePath), map);\n\n request.setAttribute(\"map\", map);\n request.getRequestDispatcher(\"/listFile.jsp\").forward(request, response);\n\n\n\n }\n\n private void getAllFiles(File filePath, Map map) {\n\n //如果不是文件,那么它就是文件夹\n if (!filePath.isFile()) {\n\n //列出文件夹下所有的文件(可能是文件,可能是文件夹)\n File[] files = filePath.listFiles();\n for (File file : files) {\n\n //得到的文件(或者是文件夹)再对其进行判断\n getAllFiles(file, map);\n }\n } else {\n //进入到else语句了,肯定是文件了\n\n //得到文件名\n String fileName = filePath.getName().substring(filePath.getName().lastIndexOf(\"_\") + 1);\n\n //我们将文件全名作为key,文件名作为value保存在map集合中\n map.put(filePath.getName(), fileName);\n\n }\n\n }\n</pre>\n<span style=\"color:#333333;font-family:-apple-system, BlinkMacSystemFont, "font-size:15px;background-color:#FFFFFF;\">JSP页面中显示可以下载的文件</span>\n</p>\n<p>\n<pre class=\"prettyprint lang-html\"><c:forEach items=\"${map}\" var=\"me\">\n\n <c:url var=\"url\" value=\"/DownFileServlet\">\n <c:param name=\"fileName\" value=\"${me.key}\"></c:param>\n </c:url>\n ${me.value}<a href=\"${url}\">下载!</a><br>\n\n</c:forEach></pre>\n实现下载的servlet\n</p>\n<p>\n<pre class=\"prettyprint lang-java\"> protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n\n //得到文件的全名\n String fileName = request.getParameter(\"fileName\");\n\n //如果是中文数据,需要转码。\n fileName = new String(fileName.getBytes(\"ISO8859-1\"), \"utf-8\");\n\n //得到保存文件的位置\n String path = this.getServletContext().getRealPath(\"/WEB-INF/uploadFile\");\n\n //文件是通过文件名进行hashCode打散保存的,通过文件名拿到文件绝对路径\n String fileRealPath = makeFilePath(fileName, path);\n System.out.println(fileRealPath);\n\n //判断文件是否存在\n File file = new File(fileRealPath);\n if (!file.exists()) {\n request.setAttribute(\"message\", \"您要下载的资源不存在了!\");\n request.getRequestDispatcher(\"/message.jsp\").forward(request, response);\n return ;\n }\n\n //存在\n\n //读取该文件并把数据写给浏览器\n FileInputStream inputStream = new FileInputStream(fileRealPath);\n byte[] bytes = new byte[1024];\n int len = 0;\n while ((len = inputStream.read(bytes)) > 0) {\n response.getOutputStream().write(bytes, 0, len);\n }\n\n inputStream.close();\n\n\n //设置消息头,告诉浏览器,这是下载的文件\n String name = fileName.substring(fileName.lastIndexOf(\"_\") + 1);\n response.setHeader(\"content-disposition\",\"attachment;filename=\" + URLEncoder.encode(name, \"UTF-8\"));\n\n }\n\n private String makeFilePath(String fileName, String path) {\n\n int hashCode = fileName.hashCode();\n\n int dir1 = hashCode & 0xf;\n int dir2 = (hashCode & 0xf0) >> 4;\n\n String dir = path + \"\\\\\" + dir1 + \"\\\\\" + dir2 +\"\\\\\"+ fileName;\n return dir;\n }\n</pre>\n</p>\n<p>\n <br />\n</p>', '111', '222', '2019-04-09 02:10:30', '2019-04-09 02:10:30', '18');
INSERT INTO `tb_blog` VALUES ('35', '验证码功能实现', '/title_pics/yanzm.png', '最近做了一个存jsp+servlet 的练习项目,旨在练习之前的知识,哈哈哈,就验证码功能实现,写一篇博客。 本文是一个很简单的向浏览器显示一个验证码的功能。比较简单,跟着代码看就能看懂,直接上代码。', '<p style=\"text-align:center;\">\n <span style=\"font-size:24px;\"><strong>验证码功能实现</strong></span>\n</p>\n<p>\n 最近做了一个存jsp+servlet 的练习项目,旨在练习之前的知识,哈哈哈,就验证码功能实现,写一篇博客。\n</p>\n<p>\n 本文是一个很简单的向浏览器显示一个验证码的功能。比较简单,跟着代码看就能看懂,直接上代码。\n</p>\n<p>\n<pre class=\"prettyprint lang-java\">package com.shop.controller;\n\nimport java.awt.Color;\nimport java.awt.Font;\nimport java.awt.Graphics;\nimport java.awt.image.BufferedImage;\nimport java.io.IOException;\nimport java.util.Random;\n\nimport javax.imageio.ImageIO;\nimport javax.servlet.ServletException;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\npublic class CheckCode extends HttpServlet {\n protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n //验证码随机产生源\n String code = \"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n Random random = new Random();\n StringBuffer sb = new StringBuffer();\n //随机生成6位校验码\n for(int i=0;i<6;i++) {\n int index = random.nextInt(code.length());\n sb.append(code.charAt(index));\n }\n String checkCode = sb.toString();\n //在内存中创建一副图像\n BufferedImage image = new BufferedImage(95, 35, BufferedImage.TYPE_INT_RGB);\n //得到图片\n Graphics g = image.getGraphics();\n //修改图片颜色\n g.setColor(Color.WHITE);\n g.fillRect(0, 0, 95, 35); \n //向图片写数据\n g.setColor(Color.BLUE);\n g.setFont(new Font(null,Font.HANGING_BASELINE,23));\n g.drawString(checkCode, 0,20); \n //随机画出干扰线\n \n for(int i=0;i<10;i++) {\n g.setColor(new Color(random.nextInt(255),random.nextInt(255), random.nextInt(255)));\n int x1 = random.nextInt(85);\n int y1 = random.nextInt(30);\n int x2 = random.nextInt(85);\n int y2 = random.nextInt(30);\n g.drawLine(x1, y1, x2, y2);\n }\n //将验证码存入session\n request.getSession().setAttribute(\"realCheckCode\",checkCode);\n \n //将图片写给浏览器\n ImageIO.write(image, \"jpeg\",response.getOutputStream());\n \n }\n\n protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n doGet(request, response);\n }\n\n}\n</pre>\n</p>\n<p>\n <br />\n</p>\n<p>\n</p>', '111', '111', '2019-04-15 06:35:30', '2019-04-15 06:35:30', '18');
INSERT INTO `tb_blog` VALUES ('44', 'CentOS7 64位下MySQL5.7安装与配置(YUM)', '/title_pics/centos.png', 'CentOS7 64位下MySQL5.7安装与配置(YUM)安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1、配置YUM源 在MySQL官网中下载YUM源rpm安装包', '<p style=\"text-align:center;\">\n <strong><span style=\"font-size:14px;\"></span><span style=\"font-size:14px;\"></span><span style=\"font-size:14px;\">CentOS7 64位下MySQL5.7安装与配置(YUM)</span></strong>\n</p>\n<p style=\"text-align:left;\">\n <strong></strong>\n</p>\n<h3 id=\"1配置yum源\" style=\"color:#333333;font-family:tahoma, 宋体;text-align:justify;background-color:#FAFAFC;\">\n <strong><span style=\"font-size:9px;\"><em>原文:</em></span><span style=\"font-size:9px;\"><em>https://www.linuxidc.com/Linux/2016-09/135288.htm</em></span></strong>\n</h3>\n<h3 id=\"1配置yum源\" style=\"color:#333333;font-family:tahoma, 宋体;text-align:justify;background-color:#FAFAFC;\">\n <strong><span style=\"font-size:14px;\">1、配置YUM源<u></u></span></strong>\n</h3>\n<h3 id=\"1配置yum源\" style=\"color:#333333;font-family:tahoma, 宋体;text-align:justify;background-color:#FAFAFC;\">\n <span style=\"font-size:9px;\"></span><span style=\"font-size:9px;\"></span>\n</h3>\n<h3 id=\"1配置yum源\" style=\"color:#333333;font-family:tahoma, 宋体;text-align:justify;background-color:#FAFAFC;\">\n <span style=\"font-size:14px;\"></span>\n</h3>\n在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ \n<p>\n <br />\n</p>\n<p style=\"text-align:left;\">\n <strong><img src=\"/content_pics/160918124758191.png\" alt=\"\" width=\"600\" height=\"151\" title=\"\" align=\"\" /><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n # 下载mysql源安装包<br />\nshell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm<br />\n# 安装mysql源<br />\nshell> yum localinstall mysql57-community-release-el7-8.noarch.rpm<br />\n检查mysql源是否安装成功<br />\n<br />\nshell> yum repolist enabled | grep \"mysql.*-community.*\"\n</p>\n<p style=\"text-align:left;\">\n 看到上图所示表示安装成功。 <br />\n可以修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。改完之后的效果如下所示:<strong> <br />\n<img src=\"/content_pics/160918124758197.jpg\" alt=\"\" width=\"600\" height=\"283\" title=\"\" align=\"\" /><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><span style=\"font-size:14px;\">2、安装MySQL</span><span style=\"font-size:14px;\"></span><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n shell> yum install mysql-community-server\n</p>\n<p style=\"text-align:left;\">\n <strong><span style=\"font-size:14px;\">3、启动MySQL服务</span></strong>\n</p>\n<p style=\"text-align:left;\">\n shell> systemctl start mysqld<br />\n查看MySQL的启动状态<br />\n<br />\nshell> systemctl status mysqld<br />\n● mysqld.service - MySQL Server<br />\n Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)<strong><br />\n </strong><br />\nActive: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago<br />\n Main PID: 2888 (mysqld)<br />\n CGroup: /system.slice/mysqld.service<br />\n └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid<br />\n<br />\n6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...<br />\n6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.<strong><br />\n<span style=\"font-size:14px;\">4、开机启动</span><br />\n</strong>shell> systemctl enable mysqld<br />\nshell> systemctl daemon-reload<strong><br />\n<span style=\"font-size:14px;\">5、修改root本地登录密码</span><br />\n</strong>mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:<br />\nshell> grep \'temporary password\' /var/log/mysqld.lo<img src=\"http://www.htjava.top/content_pics/160918124758193.png\" alt=\"\" /><strong>g</strong>\n</p>\n<p style=\"text-align:left;\">\n shell> mysql -uroot -p<br />\nmysql> ALTER USER \'root\'@\'localhost\' IDENTIFIED BY \'MyNewPass4!\'; <br />\n或者<br />\n<br />\nmysql> set password for \'root\'@\'localhost\'=password(\'MyNewPass4!\'); <br />\n注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:\n</p>\n<p style=\"text-align:left;\">\n 通过msyql环境变量可以查看密码策略的相关信息:<br />\nmysql> show variables like \'%password%<strong>\';<br />\n<img src=\"/content_pics/160918124758195.png\" alt=\"\" /><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n validate_password_policy:密码策略,默认为MEDIUM策略 <br />\nvalidate_password_dictionary_file:密码策略文件,策略为STRONG才需要 <br />\nvalidate_password_length:密码最少长度 <br />\nvalidate_password_mixed_case_count:大小写字符长度,至少1个 <br />\nvalidate_password_number_count :数字至少1个 <br />\nvalidate_password_special_char_count:特殊字符至少1个 <br />\n上述参数是默认策略MEDIUM的密码检查规则。<br />\n<br />\n共有以下几种密码策略:<br />\n<br />\n策略<span> </span>检查规则<br />\n0 or LOW<span> </span>Length<br />\n1 or MEDIUM<span> </span>Length; numeric, lowercase/uppercase, and special characters<br />\n2 or STRONG<span> </span>Length; numeric, lowercase/uppercase, and special characters; dictionary file<br />\nMySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy<br />\n<br />\n修改密码策略<br />\n在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略<br />\n<br />\n# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件<br />\nvalidate_password_policy=0<br />\n如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:<br />\n<br />\nvalidate_password = off<br />\n重新启动mysql服务使配置生效:<br />\n<br />\nsystemctl restart mysqld<strong><br />\n<span style=\"font-size:14px;\">6、添加远程登录用户</span><br />\n</strong><br />\n<span style=\"font-size:14px;\"></span><br />\n默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:<br />\n<br />\nmysql> GRANT ALL PRIVILEGES ON *.* TO \'yangxin\'@\'%\' IDENTIFIED BY \'Yangxin0917!\' WITH GRANT OPTION;<strong><br />\n<span style=\"font-size:14px;\">7、配置默认编码为utf8</span><br />\n</strong><br />\n<span style=\"font-size:14px;\"></span><br />\n修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:<br />\n<br />\n[mysqld]<br />\ncharacter_set_server=utf8<br />\ninit_connect=\'SET NAMES utf8\'<br />\n重新启动mysql服务,查看数据库默认编码如下所示<strong>:<br />\n<img src=\"/content_pics/160918124758196.png\" alt=\"\" /><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><u></u><br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n <strong>默认配置文件路径: <br />\n配置文件:/etc/my.cnf <br />\n日志文件:/var/log//var/log/mysqld.log <br />\n服务启动脚本:/usr/lib/systemd/system/mysqld.service <br />\nsocket文件:/var/run/mysqld/mysqld.pid<br />\n<br />\n</strong>\n</p>\n<p style=\"text-align:left;\">\n <strong><br />\n</strong>\n</p>', '1', '1', '2019-05-18 07:57:31', '2019-05-18 07:57:31', '7');
INSERT INTO `tb_blog` VALUES ('45', '[CentOS_7.4]Linux编译安装ffmpeg', '/title_pics/centos.png', '[CentOS_7.4]Linux编译安装ffmpeg 安装过程: 下载安装源,配置,编译,安装,设置环境变量。', '<p>\n <strong></strong>\n</p>\n<h1 class=\"postTitle\" style=\"text-align:center;font-size:28px;font-weight:400;color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:#FFFFFF;\">\n <strong><span style=\"font-size:16px;\">[CentOS_7.4]Linux编译安装ffmpeg</span></strong>\n</h1>\n<strong></strong>原文:https://www.cnblogs.com/miaosha5s/p/7670447.html\n<p>\n <br />\n</p>\n<p>\n <strong>安装过程</strong><span style=\"color:#333333;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:#FFFFFF;\">: 下载安装源,配置,编译,安装,设置环境变量。</span>\n</p>\n<p>\n<pre class=\"prettyprint lang-bsh\"># wget http://www.ffmpeg.org/releases/ffmpeg-3.1.tar.gz\n# tar -zxvf ffmpeg-3.1.tar.gz\n# cd ffmpeg-3.1\n# ./configure --prefix=/usr/local/ffmpeg\n# make && make install\n \n等待安装完成...\n \n# vi /etc/profile\n在最后PATH添加环境变量:\nPATH=$PATH:/usr/local/ffmpeg/bin\nexport PATH\n保存退出\n \n# source /ect/profile 设置生效\n# ffmpeg -version 查看版本</pre>\n<strong>注意:</strong><br />\n<br />\n若安装过程中出现以下错误:<br />\n<br />\nyasm/nasm not found or too old. Use –disable-yasm for a crippled build.<br />\n<br />\nIf you think configure made a mistake, make sure you are using the latest<br />\nversion from Git. If the latest version fails, report the problem to the<br />\n[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.<br />\nInclude the log file “config.log” produced by configure as this will help<br />\nsolve the problem.<br />\n<br />\n <br />\n<br />\n<strong>需要安装yasm</strong><br />\n<pre class=\"prettyprint lang-bsh\"># wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz\n# tar -zxvf yasm-1.3.0.tar.gz\n# cd yasm-1.3.0\n# ./configure\n# make && make install</pre>\n结束!\n</p>\n<p>\n <br />\n</p>\n<p>\n <br />\n</p>', '12', '12', '2019-05-18 08:04:44', '2019-05-18 08:04:44', '7');
INSERT INTO `tb_blog` VALUES ('50', '解决MongoDB远程访问失败的问题', '/title_pics/default.jpg', '我在连接远程连接MongoDB时,输入对方的IP地址加端口号一直访问失败,用localhost与127.0.0.1都行,就是ip地址不行。。。', '<p>\n <strong>我在连接远程连接MongoDB时,输入对方的IP地址加端口号一直访问失败,用localhost与127.0.0.1都行,就是ip地址不行。</strong>\n</p>\n<p>\n <strong>网上查阅资料发现mongodb数据库启动后,默认只能在本地使用,端口为27017。<span style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;background-color:#FEFEF2;\">那么如何设置让它可以远程访问呢?</span></strong>\n</p>\n<p>\n <strong><span style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;background-color:#FEFEF2;\">修改配置文件mongodb.conf</span></strong>\n</p>\n<p>\n <strong>添加 </strong>\n</p>\n<p>\n <strong><span style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;background-color:#FEFEF2;\">bind_ip=0.0.0.0</span></strong>\n</p>\n<p>\n <strong><span style=\"font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;background-color:#FEFEF2;\">然后我就解决了。。。。</span></strong>\n</p>\n<p>\n <strong></strong>\n</p>\n<p>\n <strong></strong>\n</p>', '12', '23', '2019-07-29 10:02:23', '2019-07-29 10:02:23', '21');
INSERT INTO `tb_blog` VALUES ('51', 'Git HEAD detached from XXX (git HEAD 游离) 解决办法', '/title_pics/default.jpg', 'HEAD 处于游离状态时,我们可以很方便地在历史版本之间互相切换,比如需要回到某次提交,直接 checkout 对应的 commit id 或者 tag 名即可', '<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">1.git branch -v 查看当前领先多少 </span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><img src=\"/content_pics/1.png\" alt=\"\" /><br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">4449a91 指向的是 dev1 的最后一次提交</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">2.新建一个 temp 分支,把当前提交的代码放到整个分支<br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><img src=\"/content_pics/2.png\" alt=\"\" /><br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">3.checkout 出要回到的那个分支,这里是 dev1<br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><img src=\"/content_pics/3.png\" alt=\"\" /><br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">4.然后 merge 刚才创建的临时分支,把那些代码拿回来</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><img src=\"/content_pics/4.png\" alt=\"\" /></span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">5.git status 查看下合并结果,有冲突就解决<br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><img src=\"/content_pics/5.png\" alt=\"\" /><br />\n</span></strong>\n</p>\n<p>\n <strong><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\"><span style=\"color:rgba(0, 0, 0, 0.75);font-family:"font-size:16px;background-color:#FFFFFF;\">合并 OK 后就提交到远端 </span><br />\n</span></strong>\n</p>', '123', '123', '2019-07-30 22:56:57', '2019-07-30 22:56:57', '22');
INSERT INTO `tb_blog` VALUES ('52', 'fastdfs安装教程', '/title_pics/default.jpg', 'FastDFS(Fast Distributed File System)是一款开源轻量级分布式文件系统,本文不讲解原理和架构,只是在个人使用部署过程中耗费了好长时间和精力,遇到了很多的坑,于是总结成了一篇详细的部署文档分享给大家', '<h4 id=\"toc_1\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">\n <h4 id=\"toc_1\" style=\"text-align:center;font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\"><span style=\"color:#CCCCCC;\">原文链接:</span><a href=\"https://www.cnblogs.com/handsomeye/p/9451568.html\"><span style=\"color:#CCCCCC;\">https://www.cnblogs.com/handsomeye/p/9451568.html</span></a><span style=\"color:#CCCCCC;\"></span></span>\n </h4>\n <h4 id=\"toc_1\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">安装libfastcommon</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">获取libfastcommon安装包:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">wget <span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\">https:</span><span class=\"hljs-comment\" style=\"color:#008000;line-height:1.5;\"><span class=\"hljs-comment\" style=\"line-height:1.5;\">//github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz</span> </span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">解压安装包:tar -zxvf V1.0.38.tar.gz</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">进入目录:cd libfastcommon-1.0.38</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">执行编译:./make.sh</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">安装:./make.sh install</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337305933144.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201417899-464673029.jpg\" alt=\"\" width=\"743\" height=\"135\" style=\"height:auto;\" /></span>\n </p>\n </li>\n </ol>\n <blockquote style=\"background:url("color:#333333;font-family:verdana, "font-size:13px;\">\n <p style=\"color:#000000;\">\n <span style=\"line-height:1.5;font-size:14px;\">可能遇到的问题:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">-</span><span class=\"ruby\" style=\"line-height:1.5;\"><span class=\"hljs-symbol\" style=\"color:#00B0E8;line-height:1.5;\"><span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">bash</span>: <span class=\"hljs-symbol\" style=\"line-height:1.5;\"><span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">make</span>: command <span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">not found <span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">-</span><span class=\"ruby\" style=\"line-height:1.5;\"><span class=\"hljs-symbol\" style=\"color:#00B0E8;line-height:1.5;\"><span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">bash</span>: <span class=\"hljs-symbol\" style=\"line-height:1.5;\"><span class=\"hljs-attribute\" style=\"color:#A31515;line-height:1.5;\">gcc</span>: command <span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">not found\n\n解决方案: </span></span></span></span></span></span></span></span></span></pre>\n<pre><span style=\"line-height:1.5;font-size:14px;\">debian通过apt-<span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\">get install gcc <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">make</span>安装\ncentos通过yum -<span class=\"hljs-keyword\" style=\"line-height:1.5;\">y install gcc <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">make</span>安装</span></span></span></span></span></pre>\n </blockquote>\n <h4 id=\"toc_2\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">安装FastDFS</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">获取fdfs安装包:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">wget <span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\">https:</span><span class=\"hljs-comment\" style=\"color:#008000;line-height:1.5;\"><span class=\"hljs-comment\" style=\"line-height:1.5;\">//github.com/happyfish100/fastdfs/archive/V5.11.tar.gz</span> </span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">解压安装包:tar -zxvf V5.11.tar.gz</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">进入目录:cd fastdfs-5.11</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">执行编译:./make.sh</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">安装:./make.sh install</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337308994594.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201558576-1766872984.jpg\" alt=\"\" width=\"573\" height=\"211\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看可执行命令:ls -la /usr/bin/fdfs*</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337309199921.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201650045-2014679422.jpg\" alt=\"\" width=\"443\" height=\"184\" style=\"height:auto;\" /></span>\n </p>\n </li>\n </ol>\n <h4 id=\"toc_3\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">配置Tracker服务</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <span style=\"line-height:1.5;font-size:14px;\">进入/etc/fdfs目录,有三个.sample后缀的文件(自动生成的fdfs模板配置文件),通过cp命令拷贝tracker.conf.sample,删除.sample后缀作为正式文件:</span><br />\n<span class=\"Apple-converted-space\" style=\"line-height:1.5;font-size:14px;\"> <img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15336945272527.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201733659-143141345.jpg\" alt=\"\" width=\"576\" height=\"103\" style=\"height:auto;\" /></span>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">编辑tracker.conf:vi tracker.conf,修改相关参数</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">base_path=/home/mm/fastdfs/tracker <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#tracker存储data和<span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\">log</span>的跟路径,必须提前创建好\nport=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">23000</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#tracker默认<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">23000</span> http.server_port=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">80</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#http端口,需要和nginx相同 </span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">启动tracker(支持start|stop|restart):</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>bin<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs_trackerd /</span>etc<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs/</span>tracker.conf start </span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看tracker启动日志:进入刚刚指定的base_path(/home/mm/fastdfs/tracker)中有个logs目录,查看tracker.log文件</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337310825651.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201823407-1669604672.jpg\" alt=\"\" width=\"734\" height=\"78\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看端口情况:netstat -apn|grep fdfs</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337310995196.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201847657-2001149194.jpg\" alt=\"\" width=\"675\" height=\"31\" style=\"height:auto;\" /></span>\n </p>\n </li>\n </ol>\n <blockquote style=\"background:url("color:#333333;font-family:verdana, "font-size:13px;\">\n <p style=\"color:#000000;\">\n <span style=\"line-height:1.5;font-size:14px;\">可能遇到的报错:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">/usr/bin/fdfs_trackerd: <span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\"><span class=\"hljs-literal\" style=\"color:#A31515;line-height:1.5;\">error</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">while</span> loading <span class=\"hljs-keyword\" style=\"line-height:1.5;\">shared</span> libraries: libfastcommon.<span class=\"hljs-keyword\" style=\"line-height:1.5;\">so: cannot <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">open</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\">shared</span> object <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">file</span>: <span class=\"hljs-keyword\" style=\"line-height:1.5;\">No such <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">file</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\">or</span> directory </span></span></span></span></span></span></span></span> <span style=\"line-height:1.5;font-size:14px;\">解决方案:建立libfastcommon.so软链接</span></pre>\n<pre><span style=\"line-height:1.5;font-size:14px;\">ln -s <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>lib64<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/libfastcommon.so /</span>usr<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/local/</span><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">lib/<span class=\"hljs-title\" style=\"color:#A31515;line-height:1.5;\">libfastcommon.<span class=\"hljs-title\" style=\"line-height:1.5;\">so\nln -s <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>lib64<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/libfastcommon.so /</span>usr<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/</span><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">lib/</span><span class=\"hljs-title\" style=\"color:#A31515;line-height:1.5;\">libfastcommon.<span class=\"hljs-title\" style=\"line-height:1.5;\">so</span></span></span></span></span></span></span></span></span></pre>\n </blockquote>\n <h4 id=\"toc_4\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">配置Storage服务</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <span style=\"line-height:1.5;font-size:14px;\">进入/etc/fdfs目录,有cp命令拷贝storage.conf.sample,删除.sample后缀作为正式文件;</span>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">编辑storage.conf:vi storage.conf,修改相关参数:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">base_path=/home/mm/fastdfs/storage <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#storage存储data和<span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\">log</span>的跟路径,必须提前创建好\nport=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">23000</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#storge默认<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">23000</span>,同一个组的storage端口号必须一致\ngroup_name=group1 <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#默认组名,根据实际情况修改\nstore_path_count=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">1</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#存储路径个数,需要和store_path个数匹配\nstore_path0=/home/mm/fastdfs/storage <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#如果为空,则使用base_path\ntracker_server=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">10.122</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">.149</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">.211</span>:<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">22122</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#配置该storage监听的tracker的ip和port </span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">启动storage(支持start|stop|restart):</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>bin<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs_storaged /</span>etc<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs/</span>storage.conf start </span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看storage启动日志:进入刚刚指定的base_path(/home/mm/fastdfs/storage)中有个logs目录,查看storage.log文件</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337313133469.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201921189-16317155.jpg\" alt=\"\" width=\"711\" height=\"145\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">此时再查看tracker日志:发现已经开始选举,并且作为唯一的一个tracker,被选举为leader</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337312505783.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809201950722-1959554309.jpg\" alt=\"\" width=\"721\" height=\"95\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看端口情况:netstat -apn|grep fdfs</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337313336921.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202028138-670884814.jpg\" alt=\"\" width=\"723\" height=\"74\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">通过monitor来查看storage是否成功绑定:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>bin<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs_monitor /</span>etc<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fdfs/</span>storage.conf </span></span></span></span></pre>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337856394714.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202102192-1479269612.jpg\" alt=\"\" width=\"707\" height=\"401\" style=\"height:auto;\" /></span>\n </p>\n </li>\n </ol>\n <h4 id=\"toc_5\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">安装Nginx和fastdfs-nginx-module模块</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">下载Nginx安装包</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">wget <span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\">http:</span><span class=\"hljs-comment\" style=\"color:#008000;line-height:1.5;\"><span class=\"hljs-comment\" style=\"line-height:1.5;\">//nginx.org/download/nginx-1.15.2.tar.gz</span> </span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">下载fastdfs-nginx-module安装包</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">wget <span class=\"hljs-symbol\" style=\"color:#00B0E8;line-height:1.5;\"><span class=\"hljs-symbol\" style=\"line-height:1.5;\">https:</span>/<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/github.com/happyfish</span>10<span class=\"hljs-number\" style=\"line-height:1.5;\">0</span>/fastdfs-nginx-<span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\"><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">module</span>/</span><span class=\"hljs-title\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-title\" style=\"line-height:1.5;\">archive</span>/</span><span class=\"hljs-title\" style=\"line-height:1.5;\"><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-title\" style=\"line-height:1.5;\">V1</span>.20.</span><span class=\"hljs-title\" style=\"line-height:1.5;\"><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-title\" style=\"line-height:1.5;\">tar</span>.</span><span class=\"hljs-title\" style=\"line-height:1.5;\"><span class=\"hljs-class\" style=\"line-height:1.5;\"><span class=\"hljs-title\" style=\"line-height:1.5;\">gz</span></span> </span></span></span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">解压nginx:tar -zxvf nginx-1.15.2.tar.gz</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">解压fastdfs-nginx-module:tar -xvf V1.20.tar.gz</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">进入nginx目录:cd nginx-1.10.1</span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">安装依赖的库</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">apt-<span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\">get <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">update</span> apt-<span class=\"hljs-built_in\" style=\"line-height:1.5;\"><span class=\"hljs-keyword\" style=\"line-height:1.5;\">get</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\">install</span> libpcre3 libpcre3-<span class=\"hljs-built_in\" style=\"line-height:1.5;\">dev openssl libssl-<span class=\"hljs-built_in\" style=\"line-height:1.5;\">dev libperl-<span class=\"hljs-built_in\" style=\"line-height:1.5;\">dev </span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">配置,并加载fastdfs-nginx-module模块:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">.<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/configure --prefix=/</span>usr<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/local/</span>nginx --add-module=<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span>local<span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/src/</span>fastdfs-nginx-module<span class=\"hljs-number\" style=\"line-height:1.5;\">-</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">1.20</span><span class=\"hljs-regexp\" style=\"line-height:1.5;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/src/</span> </span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">编译安装:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">make</span> <span class=\"hljs-built_in\" style=\"line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">make</span> install </span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看安装路径:whereis nginx</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337133899604.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202137626-1411197392.jpg\" alt=\"\" width=\"512\" height=\"32\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">启动、停止:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-built_in\" style=\"color:#0000FF;line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">cd</span> /usr/<span class=\"hljs-built_in\" style=\"line-height:1.5;\"><span class=\"hljs-built_in\" style=\"line-height:1.5;\">local</span>/nginx/sbin/\n./nginx \n./nginx <span class=\"hljs-operator\" style=\"line-height:1.5;\">-s stop <span class=\"hljs-comment\" style=\"color:#008000;line-height:1.5;\"><span class=\"hljs-comment\" style=\"line-height:1.5;\">#此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程</span> ./nginx <span class=\"hljs-operator\" style=\"line-height:1.5;\">-s quit <span class=\"hljs-comment\" style=\"line-height:1.5;\"><span class=\"hljs-comment\" style=\"line-height:1.5;\">#此方式停止步骤是待nginx进程处理任务完毕进行停止</span> ./nginx <span class=\"hljs-operator\" style=\"line-height:1.5;\">-s reload </span></span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">验证启动状态:wget \"<a href=\"http://127.0.0.1/\">http://127.0.0.1</a>\"</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337136494427.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202214623-946184752.jpg\" alt=\"\" width=\"775\" height=\"113\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">查看此时的nginx版本:发现fastdfs模块已经安装好了</span><br />\n<span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337338955675.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202240570-1449488718.jpg\" alt=\"\" width=\"648\" height=\"52\" style=\"height:auto;\" /></span>\n </p>\n </li>\n </ol>\n <blockquote style=\"background:url("color:#333333;font-family:verdana, "font-size:13px;\">\n <p style=\"color:#000000;\">\n <span style=\"line-height:1.5;font-size:14px;\">可能的报错:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">include<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/fastdfs/</span>fdfs_define.<span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\">h:</span><span class=\"hljs-number\" style=\"line-height:1.5;\">15</span>:<span class=\"hljs-number\" style=\"line-height:1.5;\">27</span>: fatal <span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\">error:</span> common_define.<span class=\"hljs-keyword\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\">h:</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\">No such <span class=\"hljs-keyword\" style=\"line-height:1.5;\">file or directory </span></span></span></span></span></span></span> <span style=\"line-height:1.5;font-size:14px;\">解决方案:修改fastdfs-nginx-module-1.20/src/config文件,然后重新第7步开始</span></pre>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-setting\" style=\"line-height:1.5;\"><span class=\"hljs-attr\" style=\"color:#FF0000;line-height:1.5;\">ngx_module_incs</span>=<span class=\"hljs-value\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\">\"/usr/include/fastdfs /usr/include/fastcommon/\"</span> <span class=\"hljs-setting\" style=\"line-height:1.5;\"><span class=\"hljs-attr\" style=\"color:#FF0000;line-height:1.5;\">CORE_INCS</span>=<span class=\"hljs-value\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\"><span class=\"hljs-string\" style=\"line-height:1.5;\">\"$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/\"</span></span></span></span></span></span></span></span></pre>\n </blockquote>\n <h4 id=\"toc_5\" style=\"font-size:14px;color:#333333;font-family:verdana, "background-color:#FFFFFF;\">\n <span style=\"line-height:1.5;font-size:16px;\">配置Nginx和fastdfs-nginx-module模块</span>\n </h4>\n <ol style=\"font-family:verdana, "font-size:13px;background-color:#FFFFFF;\">\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">配置mod-fastdfs.conf,并拷贝到/etc/fdfs文件目录下</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">cd fastdfs-nginx-module<span class=\"hljs-number\" style=\"line-height:1.5;\">-</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">1.20</span><span class=\"hljs-regexp\" style=\"line-height:1.5;\">/src/</span> <span class=\"hljs-keyword\" style=\"line-height:1.5;\">cp mod_fastdfs.<span class=\"hljs-keyword\" style=\"line-height:1.5;\">conf <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/etc/</span>fdfs </span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">进入/etc/fdfs修改mod-fastdfs.conf:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\">base_path=/home/mm/fastdfs\ntracker_server=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">10.122</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">.149</span><span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">.211</span>:<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">22122</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#tracker的地址\nurl_have_group_name=<span class=\"hljs-literal\" style=\"color:#A31515;line-height:1.5;\"><span class=\"hljs-literal\" style=\"line-height:1.5;\">true</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#url是否包含group名称\nstorage_server_port=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">23000</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#需要和storage配置的相同\nstore_path_count=<span class=\"hljs-number\" style=\"line-height:1.5;\"><span class=\"hljs-number\" style=\"line-height:1.5;\">1</span> <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#存储路径个数,需要和store_path个数匹配\nstore_path0=/home/mm/fastdfs/storage <span class=\"hljs-preprocessor\" style=\"line-height:1.5;\">#文件存储的位置 </span></span></span></span></span></span></span></span></span></span></span></span></span></pre>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">配置nginx,80端口server增加location如图:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">cd <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span><span class=\"hljs-keyword\" style=\"line-height:1.5;\">local<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/nginx/</span><span class=\"hljs-keyword\" style=\"line-height:1.5;\">conf/\nvi nginx.<span class=\"hljs-keyword\" style=\"line-height:1.5;\">conf </span></span></span></span></span></pre>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\"><img src=\"https://www.cnblogs.com/handsomeye/p/media/15336343653165/15337371363160.jpg\" alt=\"\" style=\"height:auto;\" /><img src=\"https://images2018.cnblogs.com/blog/872887/201808/872887-20180809202311512-242475061.jpg\" alt=\"\" width=\"349\" height=\"67\" style=\"height:auto;\" /></span>\n </p>\n </li>\n <li>\n <p>\n <span style=\"line-height:1.5;font-size:14px;\">最后需要拷贝fastdfs解压目录中的http.conf和mime.types:</span>\n </p>\n<pre><span style=\"line-height:1.5;font-size:14px;\"><span class=\"hljs-keyword\" style=\"color:#0000FF;line-height:1.5;\">cd <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/usr/</span><span class=\"hljs-keyword\" style=\"line-height:1.5;\">local<span class=\"hljs-regexp\" style=\"line-height:1.5;\">/src/</span>fastdfs<span class=\"hljs-number\" style=\"line-height:1.5;\">-5.11</span>/<span class=\"hljs-keyword\" style=\"line-height:1.5;\">conf\ncp mime.types http.<span class=\"hljs-keyword\" style=\"line-height:1.5;\">conf <span class=\"hljs-regexp\" style=\"line-height:1.5;\">/etc/</span>fdfs/</span></span></span></span></span></pre>\n </li>\n </ol>\n</span>\n</h4>\n<br />', '12', '23', '2020-02-15 01:30:12', '2020-02-15 01:30:12', '18');
-- ----------------------------
-- Table structure for tb_blogtype
-- ----------------------------
DROP TABLE IF EXISTS `tb_blogtype`;
CREATE TABLE `tb_blogtype` (
`typeId` int(11) NOT NULL AUTO_INCREMENT,
`typeName` varchar(255) NOT NULL,
`typeOrder` int(11) NOT NULL,
PRIMARY KEY (`typeId`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_blogtype
-- ----------------------------
INSERT INTO `tb_blogtype` VALUES ('1', '生活', '1');
INSERT INTO `tb_blogtype` VALUES ('2', 'spring boot', '2');
INSERT INTO `tb_blogtype` VALUES ('3', 'java基础', '3');
INSERT INTO `tb_blogtype` VALUES ('4', 'redis', '4');
INSERT INTO `tb_blogtype` VALUES ('5', 'spring security', '5');
INSERT INTO `tb_blogtype` VALUES ('6', 'freemarker', '6');
INSERT INTO `tb_blogtype` VALUES ('7', 'linux', '7');
INSERT INTO `tb_blogtype` VALUES ('17', '个人随笔', '1');
INSERT INTO `tb_blogtype` VALUES ('18', 'javaweb', '4');
INSERT INTO `tb_blogtype` VALUES ('21', 'MongoDB', '5');
INSERT INTO `tb_blogtype` VALUES ('22', 'git', '10');
-- ----------------------------
-- Table structure for tb_comment
-- ----------------------------
DROP TABLE IF EXISTS `tb_comment`;
CREATE TABLE `tb_comment` (
`comment_id` int(11) NOT NULL AUTO_INCREMENT,
`userId` varchar(255) DEFAULT NULL,
`blog_id` int(11) NOT NULL,
`content` text NOT NULL,
`commentDate` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
`status` int(11) NOT NULL,
PRIMARY KEY (`comment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_comment
-- ----------------------------
-- ----------------------------
-- Table structure for tb_navigation
-- ----------------------------
DROP TABLE IF EXISTS `tb_navigation`;
CREATE TABLE `tb_navigation` (
`navigationId` int(11) NOT NULL AUTO_INCREMENT,
`navigationName` varchar(50) DEFAULT NULL,
PRIMARY KEY (`navigationId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_navigation
-- ----------------------------
INSERT INTO `tb_navigation` VALUES ('1', '关于博主');
INSERT INTO `tb_navigation` VALUES ('2', '干货资源下载');
INSERT INTO `tb_navigation` VALUES ('3', '本网站源码下载');
INSERT INTO `tb_navigation` VALUES ('4', '111');
SET FOREIGN_KEY_CHECKS=1;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。