《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx

上传人:夺命阿水 文档编号:1216718 上传时间:2024-04-02 格式:DOCX 页数:39 大小:168.34KB
返回 下载 相关 举报
《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx_第1页
第1页 / 共39页
《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx_第2页
第2页 / 共39页
《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx_第3页
第3页 / 共39页
《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx_第4页
第4页 / 共39页
《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx_第5页
第5页 / 共39页
点击查看更多>>
资源描述

《《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx》由会员分享,可在线阅读,更多相关《《数据采集技术(初级)》实验手册项目9:创建SpringBoot项目.docx(39页珍藏版)》请在课桌文档上搜索。

1、项目九:创建SpringBoot项目浪潮:2020年7月作者版本时间审核备注王健2.02020-7-13主要内容:1、创建SPringBOot项目.(1)通过多种不同的形式创建SPringBOot项目。2、配置SPringBOOt的日志。(1)配置IogbaCk日志系统。3、将SpringBoot项目发布到LinUX服务器上去。(1)安装JDK。(2)配置JDK,并发布SpringBoot项目到LinUX上去。通过nohug启动SPringbOOt项目。一、创建SPringBoot项目的方法创建SPringBoOt项目的方法有很多种,目前比较流行的为两大种:1、在线创建 在线通过start.s

2、pring.io创建SpringBoot项目,在创建完成以后,再导入lDE中开发。2、使用IDE创建 在IDE中直接使用SpringInit直接创建SPringBOot项目。IDE可以是STS也可以是IDEA03、集成开发工具介绍 开发SpringBoot项目,建议使用STS或IDEA. 在使用之前,请给STS或IDEA安装Lombok插件。 安装maven,并配置环境变量。(.m2/SeHingS.xml配置细节)Maven/gradle如果要开发任可java项目,Java项目依赖很多的其他的第三方的库。第三方的库,你可以手工的放到项目中。不要。Maven-在STS、IDEA里面,都自带了。

3、问题:如果使用自带的,将会所有依赖下载到Suser.m2repository-30G+建议大家还要是自己安装一个maven:1:下载Maven.apache.org2:解压Mavenisdistributedinseveralformatsforyourconvenience.Simplypickaready-madebinarydistributionarchiveandfollowinstallationinstructions.UseasourcearchiveifyouintendtobuildMavenyourself.Inordertoguardagainstrrupteddown

4、loads/installations,itishighlyremmendedtoverifythesignatureofthereleasebundlesagainstthepublicKEYSusedbytheApacheMavendevelopers.LinkChecksumsSignatureBinarytar.gzarchiveapache-maven-3.6.3-bin.tar.gzapache-maven-3.6.3-bin.tar.gz.sha512apache-maven-3.6.3-bin.tar.gz.ascBinaryziparchiveapache-maven-3.6

5、.3-bin.zipapache-maven-3.6.3-bin.zip.sha512apache-maven-3.6.3-bin.zip.三Sourcetar.gzarchiveapache-maven-3.6.3-src.tar.gzapache-maven-3.6.3-src.tar.g乙sha512apache-maven-3.6.3-src.tar.gz.ascSourceziparchiveapache-maven-3.6.3-src.zipapache-maven-3.6.3-src.zip.sha512apache-maven-3.6.3-src.zlp.sRaIaaAaNtA

6、此电脑Data(D:)programapache-maven-3.6.3名称可binbootconflibLICENSEIIOadSNOTICEr_allHREADMEtxt配置:M2HoME=安装目录PATH=%M2-H0ME%binC:Userswangjianmvn-versionApacheMaven3.6.3(cecedd343002696d0abb50b32b541b8a6ba2883f)Mavenhome:D:programapache-maven_3.6.3bin.Javaversion:11.0.7,vendor:OracleCorporation,runtime:D:pro

7、gramjdk-ll.0.7Defaultlocale:zh_CN,platformencoding:GBKOSname:windows10,version:10.0”,arch:amd64,family:windows”配置仓库:个Data(D:)programapache-maven-3.6.3confI/b.名称logging修改日期2020/6/14settings.xml2019/11/72019/11/7-toolchains.xml主页共享查看快速访问I桌面此电脑Windows(C:)用户wangjian.m2vQQ搜索.m2名称修汉日期类型大小:图片downf C :Users

8、wangjian.m2settings.xml - Notepad+ +话单文件(E)编指搜索视图W 编码(N)语言CL)设置(D IM(Q)宏(M)运行(B)插件(E) fi 1耳胃心硼*酶胤nell 7I国剧士 X廉国园N囹回圉圃eH settings. Xmldj H virus. Iogt3 H id rsa. pubt3 日 settings, xnl此电脑I 3DI蜩名片0台L下载音乐I施Windc,-Data (新加卷464743495051525354555657585960616263settings XInlnS=I,http: / /maven.apauhe.og/SET

9、T工NGS/1.0.01,xmlns:xsi=,http: www.w3.ora2001XMLSChemaTnstancexsi:SChemaLoCatiOn=http:/maven.apauhe.orqSETTINGS/1.0.0 http:/maven.aaau】 !- IocalRepositoryI The path to the local repository maven will use to store artifacts.II Default: $user.home/.m2/repositorypathtolocalrepoE:/cache/.m2repository !-

10、InteractiveModeI This will determine whether maven prompts you when it needs input. If set to fals( I maven will use a sensible default value, perhaps based on some other setting, for I the parameter in question.II Default: truetruesettings.ml2020/6/1413:29XMLg11KB二、创建SPringbOOt项目1、在线创建步1、打开start.sp

11、ring.io输入项目名称,选择版本:(对每一项目做细节说明)springinitializrProjectLanguageMavenProjectOGradleProjectJavaOKotlinOGroovyVzVSpringBootO2.4.0(SNAPSHOT)O2.4.0(M1)O2.3.2(SNAPSHOT)2.3JO2.2.9(SNAPSHOT)O2.2.8Q2.1.16(SNAPSHOT)O2.1.15ProjectMetadataGroupcn.inspurzArtifactbt-demoZNameboot-demoDescription第一zTsSpringBOotgl页目

12、Packagenamecn.inspurYZZZPackagingjOWarJavaO14O11”1 :maven为所使用的依赖工具。2 :Java为开发语言.3 :2.3.1为目前Release版本。4 :GrOUP为项目的包名。5 :Artifact为项目的名称。击忝加依赖:Dependenciesadddependencies.ctrl+B1.ombokJavaannotationlibrarywhichhelpstoreduceboilerplatecode.SpringBootDevTooIsDEVELOPERTOOLSDEVELOPERTOOLSProvidesfastapplic

13、ationrestarts,LiveReIoad,andconfigurationsforenhanceddevelopmentexperience.SpringConfigurationProcessorDEVELOPERTLSGeneratemetadatafordeveloperstooffercontextualhelpandcodecompletionwhenworkingwithcustomconfigurationkeys(ex.application.properties.ymlfiles).SpringWebWEBBuildweb,includingRESTfuI,appli

14、cationsusingSpringMVC.UsesApacheTomcatasthedefaultembeddedcontainer.ThymeleafTEMPLATEENGINESAmodernSQrVQFSidQJavatemplateengineforbothwebandstandaloneenvironments.AllowsHTMLtobecorrectlydisplayedinbrowsersandasstaticprototypes.SpringBootActuatorOPSSupportsbuiltinrcustom)endpointsthatletyoumonitorand

15、manageyourapplication-suchasapplicationhealth,metrics,sessions,etc.ValidationI/OJSR-3O3validationwithHibernatevalidator.对每一N三做说明:1:LOmbok用于简化开发。2 :bootdev为开发选项.3 :Config用于读取配置时的选项。4 :Web网络开发组件。5 :ThymeIeaf模板。6 :Actuator健康检杳。7 :JSR303期正。步2、下载并导入GENERATECTRL+0iboot-demo.zip导入到IDE中去,如STS/Eclipse中去:选择导入

16、的项目类型:ImportSelectImportexistingMavenprojectsSelectanimportwizard:typefiltertext &Install aJavaEEVaMavenCheCkOUtMaVenPrOieCtSfroynSCMITEXiStingMaVenProjeCtS,InstallordeployanartifacttoaMavenrepositoryMaterializeMavenBinaryProject同MaterializeMavenProjectsfromSCM&PlUg-inDevelopment选择已经解压好的项目:ImportMav

17、enProjectsMavenProjectsSelectMavenprojectsRootDirectory:E:downloadsboot-demo、Browse.Projects:Qpom.xmlCn.inspw:boot-demo:0.0.1-SNAPSHOT:jarSelectAllDeselectAllSelectTreeDeselectTreeRefresh0Addproject(s)toworkingsetboot-demoAdyanced等待更新完成:HProblemsJavadocDeclarationConsole=yProgressXImportingMavenproj

18、ects231KB849KB(27%)https:/repo.maven.apache.Org/maven2/org/thymeleaf/thymeleaf/3.0.11.RELEASEthymeleaf-3.0.11.RELEASEjar可选的添加aliyunmaven仓库:centralpubliccentralpublic步3、配置V器boot-demobootdevtoolsOsrc/main/javaQsrc/main/resourcesstaticetemplatesapplication.properties配置的内容如下:server.port=8888spring.appli

19、cation.name=boot-demoserver.servlet.encoding.charset=UTF-8spring.messages.encoding=UTF-8spring.thymeleaf.cache=falsespring.thymeleaf.encoding=UTF-8springjackson.time-zone=GMT+8spring.jackson.date-format=yyyy-MM-ddHH:mm:ssIoggingJeveI.root=infologging.file.name=logsSspring.application.name.log具体含义说明.

20、略。步4、开发1、开发index.htmlP(3src/main/resources&staticVCtemPlateSindex.htmlInserttitlehereHello这是主页2、配置index.html配置index.html如下:packagecn.inspur.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.ViewControllerRegistry;importorg.sprin

21、gframework.web.servlet.config.annotation.WebMvcConfigurer;ConfigurationpublicclassWebMvcConfigimplementsWebMvcConfigurer(三)OverridepublicvoidaddViewControllers(ViewControllerRegistryregistry)registry.addViewControllerCindex).setViewName(index);registry.addViewControlIer(V-).SetViewNamefindex);regist

22、ry.addViewController(-).setViewName(index);)启动:审boot-demobootdevtoolsv(3src/main/javav由cn.inspur1.LBootDemoAppIicationjava/W/一(_)()一I_I,-lI_/JIW_)lL)lIIIIIl(_lI)I_I._l_lLLIL一I/=I_I=I/=/_/_/_/:SpringBoot:(v2.3.!.RELEASE)访问测试:CIocaIhost:8888/indexHello这是主页停止项目。3、开发HelloControIIerpackagecn.inspur.api.h

23、ello.controller;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.RequestMapping;importlombok.extern.slf4j.Slf4j;ReqUeStMaPPing(hello)ControllerSlMjpublicclassHelloControIIerGetMapping(hi)publicStrin

24、ghi()Xo.info(ehello.Hi.);returnhello/hi;添加超连接:InserttitlehereHello这是主页Hello/hi添加hi.html页面:/atemplatesV&hellohi.htmlInserttitlehere这是把页面启动项目,并测试访问:,Clocalhost:8888/hello/hi这是hi页面4、显示数据Y耕boot-demobootdevtoolsv(3src/main/javaY田cn.inspurv田api.hellovtcontroller 团HelloControIIerjavaV田service 团HelloService

25、Java由VO 团Helldiavapackagecn.inspur.api.hello.vo;importlombok.Getter;importlombok.Setter;GetterSetterpublicclassHelloprivateStringname;privateintage;privateStringaddress;publicHello()publicHello(Stringname,intage,Stringaddress)this.name=name;this.age=age;this.address=address;)packagecn.inspur.api.hel

26、lo.service;importjava.util.ArrayList;importjava.util.List;importjava.util.Random;importorg.springframework.stereotype.Service;importcn.inspur.api.hello.vo.Hello;ServicepublicclassHeIIoServicepublicListquery()Randomr=newRandom();1.istlist=newArrayList();inta=r.nextlnt(2);for(inti=O;ia;i+)list.add(new

27、HelIo(Jack+i,i*4,北京+i);)returnlist;)packagecn.inspur.api.hello.controller;importjava.util.List;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.GetMapping;impo

28、rtorg.springframework.web.bind.annotation.RequestMapping;importcn.inspur.api.hello.service.HelloService;importcn.inspur.api.hello.vo.Hello;importlombok.extern.slf4j.Slf4j;ReqUeStMaPPing(hellcf)ControllerSlf4jpublicclassHelIoCOntrolIerAutowiredprivateHeIIoServicehelloService;GetMaPPing(hi)publicStrin

29、ghi(Modelmodel)Zinfo(hello.Hi.);1.istlist=helloService.queryO;model.addAttribute(datasJist);returnhello/hi;)运彳裙果:Clocalhost:8888/hello/hi这是hi页面Name;ageaddressjackof1111辰丁厂I北京IJaCk2I仃漏Jack312!北京3IJaCk416北京4步5、添加bootstr叩样式1、下载样式文件,Door-aemodooijaevoosjnspurmaserj图src/main/javav蝎srcmainresourcesv?stati

30、cvbootstrap2cssjs意jquery.min.js,ViiPminic2、添加静态文件配置packagecn.inspurconfig;importorg.springframework.Contextannotation.Configuration;importorg.springframework.web.servlet.config.annotation.ResourceHandIerRegistry;importorg.springframework.web.servlet.config.annotation.ViewControllerRegistry;importorg

31、.springframework.web.servlet.config.annotation.WebMvcConfigurer;ConfigurationpublicclassWebMvcConfigimplementsWebMvcConfigurerOverridepublicvoidaddViewControllers(ViewControllerRegistryregistry)registry.addViewController(index).setViewName(index);registry.addViewController(7).setViewName(index);regi

32、stry.addViewController(,).setViewName(index);)OverridePUbIiCVOidaddResourceHandlers(ResourceHandlerRegistryregistry)registry.addResourceHandlerC7static*l*).addResourceLocations(dasspath:/StatiC/);3、在页面上引用Inserttitleheredivclass=containerHello-这页Hello/hi4、查看结果0Inserttitlehere+CIocaIhost:8888/1ndexHeI

33、I。-这是主页Hello/hihere+ IoCalhOSt:8888/hell0/hi列表显示结果NameageaddressJackO0北京OJaCkl4北京1步6、使用vuef11后分离技术展示数据htmlXmlnslh=http:WWW.thymeleaf.orgInserttitleheremessagedivclass=row、增力口刷新序号Nameageaddress0trv-for=(h,index)inIisCindex+1h.nameh.ageh.address无数据Name:Age:Address:S(function()varlayerindex=-1;varapp=n

34、ewVue(el:#app,data:message:使用VUE显示数据,list:,hello:name:,age:O,address:),methods:refresh:function(e)oad();,add:function()layerindex=layer.open(type:1,title:增加,content:$(#addDiv);,save:function()varparam=S.param(app.hello);S.post(7hellosaven,param,function(resp)app.list.push(Object.assign(,resp.data);a

35、lert(layerlndex);IayencIose(IayerIndex);););functionload()$.post(/hello/hi2,function(data)app.list=data.data;1.json);oad(););2、使用STS创建SpringBoot项目选择创建SpringStarterProject:NewSpringStarterProjectContactingwebserviceandbuildinguimodel.ServiceURLhttps:/start.spring.ioNocontentavailable.输入项目的GAV:NewSpringStarte

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 在线阅读 > 生活休闲


备案号:宁ICP备20000045号-1

经营许可证:宁B2-20210002

宁公网安备 64010402000986号