用Eclipse创建一个spring boot(创建,并配好controller)
Spring Boot
- 1、建立文件
- 2、创建Controller
- 3、打开页面尝试
1、建立文件
打开eclipse ->上面一栏file ->new ->Spring Starter project
然后next
只勾选Spring Web ->Finish
2、创建Controller
在demo文件夹下创建文件夹controller
在controller文件夹下,建立文件testController.class文件
代码如下:
package com.example.demo.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class testController {@RequestMapping("/hello")public String hello() {return "Hello Spring Boot!";}
}
打开demo下的文件 DidididiApplication
右键->run as ->Spring boot App
在浏览器上输入:http://127.0.0.1:8080/hello
配置成功。
3、打开页面尝试
在pom.xml添加thymeleaf依赖
<!--使用thymeleaf所需依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>
ps:在<dependencies> </dependencies>
内部加入
创建一个新的controller,起名helloController
代码:
package com.example.demo.controller;import java.util.HashMap;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class indexController {@RequestMapping("/index")public String getIndex(HashMap<String,Object> map,Model model) {model.addAttribute("hello", "你好小明");map.put("name", "小明");map.put("password", "1234");return "hello";}
}
创建一个html文件(起名hello.html,与helloController中return对应):
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><div><p th:text='${name}'></p><p th:text='${password}'></p><p th:text='${hello}'></p></div>
</body>
</html>
重新启动服务器,用浏览器打开:http://localhost:8080/index。
用Eclipse创建一个spring boot(创建,并配好controller)相关推荐
- eclipse创建springboot项目_创建一个 Spring Boot 项目,你会几种方法?
我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...
- 创建一个Spring Boot项目
文章目录 Spring Boot的功能 Spring Boot的优点 Spring Boot 的三种创建方式 在线创建 使用开发工具创建 IntelliJ IDEA Maven 创建 项目结构 修改T ...
- 用Eclipse创建一个spring boot(连接mysql,简单使用mybatis)
Spring boot 1.连接mysql(用的mybaits) (1)配置pom.xml依赖 (2)配置application.properties (3)创建实体类 (4)写mapper的配置文件 ...
- 使用 SAP BTP 创建一个 Spring Boot Java 应用
Fullstack 类型的开发空间带有几个开箱即用的扩展,这些扩展被用来开发 CAP 应用程序,比如内置了 CDS 工具. 打开一个新的 terminal 窗口: 输入命令 cd projects/: ...
- 菜鸟教程 | IDEA创建一个spring boot项目的详细过程
目录 1.新建项目 2.选择项目所需依赖 3.手动导入部分依赖 创建spring项目的详细过程~ 1.新建项目 file --> new --> project groupid 和 ar ...
- 创建一个 Spring Boot 项目的4种方法,你会几种?- 第396篇
相关历史文章(阅读本文前,您可能需要先看下之前的系列
- 创建并运行一个 Spring Boot 项目
创建并运行一个 Spring Boot 项目 引言 第一个 Spring Boot 项目 1. 创建一个 spring boot 项目 第一步 第二步 第三步 第四步 2. 验证 第一步 第二步 3. ...
- spring cloud教程之使用spring boot创建一个应用
<7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...
- spring boot创建一个应用
Spring Boot是Spring团队推出的新框架,它所使用的核心技术还是Spring框架,主要是Spring 4.x,所以如果熟悉spring 4的人,能够更快的接受和学会这个框架.Spring ...
最新文章
- iOS 计算两个日期之间的差值
- “此iPhone不能使用,因为Apple Mobile Device服务没有启动”解决办法
- 影响网站转化率的10大误区(上)
- 【推荐】LSI(latent semantic indexing) 完美教程
- 养成这8个好习惯 开车会很安全的
- linux下的C语言开发(网络编程)
- atomic与nonatomic的区别
- python求立方尾不变_蓝桥杯—立方尾不变,有些数字的立方的末尾正好是该数字本身...
- SCI 文章的DOI查询以及搜索
- 硬件第二节 MOS管电路工作原理及详解
- Cisco路由器配置动态路由rip
- Model-based evolutionary algorithms: a short survey 阅读笔记
- web前端工程师的分工安排
- Dbeaver基本使用
- 既有内网又有外网的网络如何设置路由器模式
- win10创建Ubuntu16.04子系统,安装常用软件以及图形界面(包括win10远程桌面连接Ubuntu)
- 系统常见错误的解决方法
- 用c语言画一个字母金字塔,( ) 什么字母似“金字塔”? A.D B.A C.E D.F ——青夏教育精英家教网——...
- CSS 盒子模型(border、padding、margin)
- 优达数据分析课程免费分享