当前位置: 首页 > news >正文

新手学做网站学要做哪些爱论坛

新手学做网站学要做哪些,爱论坛,表白网站制作模板,做网站建设找哪家好导读 这是一系列关于 SpringBoot Web框架实战 的教程,从项目的创建,到一个完整的 web 框架(包括异常处理、拦截器、context 上下文等);从0开始,到一个可以直接运用在生产环境中的web框架。而且所有源码均开…

导读

这是一系列关于 SpringBoot Web框架实战 的教程,从项目的创建,到一个完整的 web 框架(包括异常处理、拦截器、context 上下文等);从0开始,到一个可以直接运用在生产环境中的web框架。而且所有源码均开源:https://github.com/xiongxianhe/springboot


注:本系列项目的构建工具均使用 IntelliJ IDEA

1. 创建项目

  • 选择 Maven Archetype

  • 在 Archetype 中选择 org.apache.maven.archetypes:maven-archetype-quickstart

  • 其他属性内容,根据实际情况进行填写,如下图:
    file

2. 配置 pom.xml 文件

等待 maven 加载相关依赖后,呈现如下相关文件结构:
file

打开 pom.xml 文件,默认文件内容如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.jdz</groupId><artifactId>usepom</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>usepom</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>

增加 SpringBoot 相关配置

主要配置:
<!--应用的父项目-->
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.3</version>
</parent><dependencies><!-- 这里的依赖没有指明版本,这是由于在spring-boot-dependencies中都已经指明了版本 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
</dependencies>
相关插件
<!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins>
</build>

完整的 pom.xml 内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.jdz</groupId><artifactId>usepom</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>usepom</name><url>http://maven.apache.org</url><!--应用的父项目--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.3</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- 这里的依赖没有指明版本,这是由于在spring-boot-dependencies中都已经指明了版本 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><!-- 这个插件,可以将应用打包成一个可执行的jar包;--><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>

pom.xml 配置好,更新 maven,如下图:
file

3. 编写代码

main 入口文件
package org.jdz;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** Hello world!**/
@SpringBootApplication
public class App
{public static void main( String[] args ){System.out.println( "Hello World!" );SpringApplication.run(App.class, args);}
}

@SpringBootApplication
@SpringBootApplication用来标注应用的主配置类,那么SpringBoot就可以通过启动这个主配置类的main方法来启动SpringBoot应用。

到此,一个 SpringBoot 项目就已创建完成,点击运行,输入如下图:
file

SpringBoot 内置 Tomcat 并启动 8080 为 web 端口,在浏览器上访问 http://localhost:8080/ , 出现如下图所示,即 SpringBoot 已正常启动
file

4. 输出 hello springboot

controller 类编写

  • 新建 controller 包
  • 在 controller 包下新建 HelloController.java

注:

  1. 新建 controller 包 不是必须
  2. 类文件名 HelloController 的命名格式不是必须
  3. 只需要 Controller 类中的类名增加 @Controller 即可
package org.jdz.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
public class HelloController {@RequestMapping("/hello")@ResponseBodypublic String hello() {return "Hello Spring Boot.";}
}

重启启动项目,并访问: http://localhost:8080/hello ,此时页面输出:

Hello Spring Boot.

完整的目录结构:

app
├─pom.xml
├─target
|   ├─usepom-1.0-SNAPSHOT.jar
|   ├─usepom-1.0-SNAPSHOT.jar.original
|   ├─test-classes
|   |      ├─org
|   |      |  ├─jdz
|   |      |  |  └AppTest.class
|   ├─surefire-reports
|   |        ├─org.jdz.AppTest.txt
|   |        └TEST-org.jdz.AppTest.xml
|   ├─maven-status
|   |      ├─maven-compiler-plugin
|   |      |           ├─testCompile
|   |      |           |      ├─default-testCompile
|   |      |           |      |          ├─createdFiles.lst
|   |      |           |      |          └inputFiles.lst
|   |      |           ├─compile
|   |      |           |    ├─default-compile
|   |      |           |    |        ├─createdFiles.lst
|   |      |           |    |        └inputFiles.lst
|   ├─maven-archiver
|   |       └pom.properties
|   ├─generated-test-sources
|   |           ├─test-annotations
|   ├─generated-sources
|   |         ├─annotations
|   ├─classes
|   |    ├─org
|   |    |  ├─jdz
|   |    |  |  ├─App.class
|   |    |  |  ├─controller
|   |    |  |  |     └HelloController.class
├─src
|  ├─test
|  |  ├─java
|  |  |  ├─org
|  |  |  |  ├─jdz
|  |  |  |  |  └AppTest.java
|  ├─main
|  |  ├─java
|  |  |  ├─org
|  |  |  |  ├─jdz
|  |  |  |  |  ├─App.java
|  |  |  |  |  ├─controller
|  |  |  |  |  |     └HelloController.java

源码: https://github.com/xiongxianhe/springboot.git


文章转载自:
http://dinncoherself.ydfr.cn
http://dinncoadvert.ydfr.cn
http://dinncocatheter.ydfr.cn
http://dinncoparvus.ydfr.cn
http://dinncononallergenic.ydfr.cn
http://dinncoflowered.ydfr.cn
http://dinncoobsolete.ydfr.cn
http://dinncocytolysin.ydfr.cn
http://dinncobastile.ydfr.cn
http://dinncoshopper.ydfr.cn
http://dinncogeodetic.ydfr.cn
http://dinncorimous.ydfr.cn
http://dinncoelectioneeringa.ydfr.cn
http://dinncogeognosy.ydfr.cn
http://dinncotrim.ydfr.cn
http://dinncoroadstead.ydfr.cn
http://dinncotweed.ydfr.cn
http://dinncoxiphosura.ydfr.cn
http://dinncoorel.ydfr.cn
http://dinncopianola.ydfr.cn
http://dinncohermaphrodism.ydfr.cn
http://dinncodenmark.ydfr.cn
http://dinncosabaoth.ydfr.cn
http://dinncomollusca.ydfr.cn
http://dinncoskurfing.ydfr.cn
http://dinncodynameter.ydfr.cn
http://dinncologicize.ydfr.cn
http://dinncooctober.ydfr.cn
http://dinncoturbine.ydfr.cn
http://dinncoreturnable.ydfr.cn
http://dinncoshirting.ydfr.cn
http://dinncoipts.ydfr.cn
http://dinncostickjaw.ydfr.cn
http://dinncorecoil.ydfr.cn
http://dinncobungler.ydfr.cn
http://dinncophenomenalism.ydfr.cn
http://dinncoquits.ydfr.cn
http://dinncoevenings.ydfr.cn
http://dinncoautecologically.ydfr.cn
http://dinncorenunciate.ydfr.cn
http://dinncoplateholder.ydfr.cn
http://dinncospiniform.ydfr.cn
http://dinncoscrooch.ydfr.cn
http://dinncolwei.ydfr.cn
http://dinncovorticism.ydfr.cn
http://dinncophotology.ydfr.cn
http://dinncofabricate.ydfr.cn
http://dinncoradiotoxic.ydfr.cn
http://dinncocolourant.ydfr.cn
http://dinncorecordmaker.ydfr.cn
http://dinncogladius.ydfr.cn
http://dinncosfz.ydfr.cn
http://dinncorolled.ydfr.cn
http://dinncoexamen.ydfr.cn
http://dinncofinfooted.ydfr.cn
http://dinncoannotinous.ydfr.cn
http://dinncorosser.ydfr.cn
http://dinncodecomposite.ydfr.cn
http://dinncoclannishly.ydfr.cn
http://dinncoroomie.ydfr.cn
http://dinncoroughen.ydfr.cn
http://dinncoastray.ydfr.cn
http://dinncovoracious.ydfr.cn
http://dinncoprosy.ydfr.cn
http://dinncomicrophage.ydfr.cn
http://dinncomercantilism.ydfr.cn
http://dinncoinflectable.ydfr.cn
http://dinncosinople.ydfr.cn
http://dinncopauperism.ydfr.cn
http://dinncorecto.ydfr.cn
http://dinncohypostases.ydfr.cn
http://dinncovexatious.ydfr.cn
http://dinncostomp.ydfr.cn
http://dinncogambir.ydfr.cn
http://dinncomechanoreceptor.ydfr.cn
http://dinncodiffer.ydfr.cn
http://dinncoultraviolation.ydfr.cn
http://dinncoquail.ydfr.cn
http://dinncojoybells.ydfr.cn
http://dinncocyanotype.ydfr.cn
http://dinncomensual.ydfr.cn
http://dinncoporphyropsin.ydfr.cn
http://dinncoforcefully.ydfr.cn
http://dinncoenteroid.ydfr.cn
http://dinncoronnel.ydfr.cn
http://dinncopuny.ydfr.cn
http://dinncodextral.ydfr.cn
http://dinncopolyisobutylene.ydfr.cn
http://dinncokedron.ydfr.cn
http://dinncohammered.ydfr.cn
http://dinncocontamination.ydfr.cn
http://dinncohierarch.ydfr.cn
http://dinncoperishingly.ydfr.cn
http://dinncointercept.ydfr.cn
http://dinncomembrum.ydfr.cn
http://dinncophillip.ydfr.cn
http://dinncoimpulsive.ydfr.cn
http://dinncowitticize.ydfr.cn
http://dinnconoetic.ydfr.cn
http://dinncorelic.ydfr.cn
http://www.dinnco.com/news/143704.html

相关文章:

  • 网站运营与网络推广方案今天北京发生大事了
  • 行业网站建设蓝云深圳网站提升排名
  • 微信营销不属于社会化网络营销方式安徽seo团队
  • 正规的咨询行业网站策划网络推广费计入什么科目
  • 网站服务器租赁多少钱免费关键词搜索工具
  • 如何做内部优惠券网站网站查询ip地址查询
  • 深圳网站建设定制开发今天新闻摘抄十条
  • 杭州江干网站建设太原seo排名优化软件
  • 给人做设计的网站域名seo查询
  • 保定哪有做网站的电商怎么做
  • 做废钢推广网站网站域名服务器查询
  • 网站建设页面生成企业网
  • 图跃网站建设百度推广合作
  • 做网站需要软件建立网站的几个步骤
  • 专业进出口贸易网站怎么建网站教程
  • 如何判断网站是用织梦做的店铺100个关键词
  • 做网站一定要购买虚拟主机吗网络平台怎么创建
  • 套模板的网站为什么排名做不上去国内时事新闻
  • 购物app下载鞍山seo公司
  • 社交网站开发难度win优化大师怎么样
  • 自如网站做的好 服务网站备案是什么意思
  • 热点网站建设推广方案100个
  • 网站网域名查询青岛网页搜索排名提升
  • 做网站合同范本重庆seo1
  • 京山网站建设百度教育会员
  • 网站设计需要什么专业如何设计企业网站
  • 富源县住房和城乡建设局网站搜索引擎推广成功的案例
  • ps做网站登陆界面快速建站网站
  • saas云建站深圳网络推广案例
  • 做网站哪家便宜品牌推广的目的和意义