ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:3.49MB ,
资源ID:20339519      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/20339519.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Spring boot基础文档Word格式文档下载.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Spring boot基础文档Word格式文档下载.docx

1、下面,让我们来建立这四个包吧在com.example这个包上右键,然后new一个包出来。如图所示:我这里创建好包名后,目录结构是这样的:好了,到这一步,我们终于可以开始写代码啦在本文里,我们将不会用到service、model、repository,只会用到controller来写一个简单的Hello World。让我们开始写吧:首先,在controller这个包上点击右键,新建一个class,名字就叫nana,如下图所示:建立好文件后,我们在这个文件里输入以下的代码:【注意,如果没有严格按照前面的教程来,你的包名可能和我的不一样,所以这个代码复制过去后,请自己检查一遍!】packagecom

2、.example.controller;importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;org.springframework.web.bind.annotation.RequestMapping;org.springframework.web.bind.annotation.RequestMethod;org.springframework.web.bind.annotation.RestController;/*Createdbylongge93on16/4/14.*/RestControllerEn

3、ableAutoConfigurationpublicclassnanaRequestMapping(value=/,method=RequestMethod.GET)Stringindex()returnHelloWorld;然后我们来运行以下我们的工程,运行方法如下图所示:如上图所示,点击那个三角形,就可以运行我们的工程了。不过,所有写代码的过程都是不顺利的虽然我们点了运行,但是下面的控制台里却提示我们运行失败了,从上图的下面看出,是hibernate出错了。为什么呢?因为我们在Maven里包含了MySQL的jar包,但是却没有配置数据库连接需要的账号和密码等信息。所以hibernate会

4、报错因为我们这篇文章里,只是为了输出hello world,用不着数据库。所以我们先去pom文件里注释掉数据库相关的jar包应该就OK了。我注释完后,我的pom文件是这样的,请仔细检查:projectxmlns=http:/maven.apache.org/POM/4.0.0xmlns:xsi=/www.w3.org/2001/XMLSchema-instancexsi:schemaLocation=/maven.apache.org/POM/4.0.0/maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0groupIdcom.exampl

5、eartifactIddemoversion0.0.1-SNAPSHOTpackagingjarname/namedescriptionDemoforSpringBootparentorg.springframework.bootspring-boot-starter-parent1.3.3.RELEASE!-lookupparentfromrepository-/parentpropertiesproject.build.sourceEncodingUTF-8java.version1.8/propertiesdependenciesdependencyspring-boot-starter

6、-aop-spring-boot-starter-data-jpaspring-boot-starter-jdbcspring-boot-starter-redisorg.springframework.sessionspring-sessionspring-boot-starter-thymeleafspring-boot-starter-webmysqlmysql-connector-javaruntimespring-boot-starter-testtestbuildpluginspluginspring-boot-maven-plugin/plugins/build/project此

7、时,依然报错:Cannot determine embedded database driver class for database type NONE解决办法:注释掉pom文件中jap和session,在完成以后,pom配置如下 /project.reporting.outputEncoding 然后我们再点击那个三角形运行,你会发现运行成功啦如下图所示:因为Springboot其实已经自带Tomcat了,所以当我们把这个工程跑起来后,其实就相当于跑起来一个网站。现在让我们去网页里看看我们的Hello World有没有正常工作吧在浏览器里,打开http:/localhost:8080,你会

8、发现输出了Hello World来源:Spring boot在Spring mvc下接入微信 在我们搭建好Spring boot环境后,可以很容易的使用Spring mvc,不需要复杂的配置,只需要做一些基本的注解就行了。这一章讲述如何在Spring mvc下去接入微信。一、接入微信需要一个公网IP,这里我们使用的是ngrock内网穿透工具。运行-cmd,进入ngrock解压目录,输入命令ngrok -subdomainyxpeng-config=ngrok.cfg8080 其中yxpeng是可以自己配置的子域名,8080端口通常设置为你的项目运行的端口,因为我这边默认的是8080,所以我设置

9、成了8080.二、与用servlet接入微信一样的,我们需要接受到微信后台通过get请求传过来的几个参数。 首先,写了一个model,其中封装了这四个参数。com.example.model; * 微信接入校验信息model * Created by Administrator on 2016/11/8 0008. */public class CheckModel private String signature; private Long timestamp; private Long nonce; private String echostr; public String getSign

10、ature() return signature;public void setSignature(String signature) this.signature= signature;public Long getTimestamp() return timestamp;public void setTimestamp(Long timestamp) this.timestamp= timestamp;public Long getNonce() return nonce;public void setNonce(Long nonce) this.nonce= nonce;public S

11、tring getEchostr() return echostr;public void setEchostr(String echostr) this.echostr= echostr; 创建一个controller类,其中添加一个validate方法,用来接收这个model并进行处理package com.example.controller;import com.example.model.webModel.User;import com.example.service.UserService;import org.springframework.beans.factory.annot

12、ation.Autowired;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.b

13、ind.annotation.RestController; * Created by Administrator on 2016/11/9 0009.RequestMapping(/userpublic class UserController Autowiredprivate UserServiceuserService;/check/namepublic ResponseBodyString addUser(PathVariable(name) String name) User user = new User();user.setUserName(name);user.setPassw

14、ord(123);user.setRealName(喻学鹏userService.saveUser(user); return user.getUserName();/find/namepublic ResponseBodyString findUserByName(PathVariable( User u = null;u = userService.findByUserName(name); if(u != null)return u.getRealName();elsereturn 未找到 在tokenService中,分离出这四个参数,然后对token,timestamp和nonce这

15、三个参数进行字典排序,然后进行SHA1加密,将密文与signature对比,如果相同就返回echostr.package com.example.service;import com.example.model.CheckModel;import com.example.util.EncoderHandler;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import java.util.Arrays;Servicepub

16、lic class TokenService * 微信接入数据验证 * paramwxToken* paramtokenModel* returnTransactionalpublic String validate(String wxToken, CheckModeltokenModel) String signature = tokenModel.getSignature();Long timestamp = tokenModel.getTimestamp();Long nonce =tokenModel.getNonce();String echostr = tokenModel.getEchostr(

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1