700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > spring-boot web 简单的搭建

spring-boot web 简单的搭建

时间:2023-10-20 23:06:25

相关推荐

spring-boot  web 简单的搭建

pom.xml

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.8.RELEASE</version></parent><dependencies><!--web依赖开始 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>

启动类建议放在根目录下

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.servlet.config.annotation.EnableWebMvc;/*** @Author sunli* @Date /8/15 10:51*/@SpringBootApplication@EnableWebMvc//开启webpublic class Starter {public static void main(String[] args) {SpringApplication.run(Starter.class,args);}}控制层controller类package .sddz.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/*** @Author sunli* @Date /8/15 10:55*/@RestControllerpublic class TestController { //解决乱码的一种方式@RequestMapping(value = "/test" ,produces="application/json;charset=UTF-8")public String home() {System.out.println("springboot项目启动成功!");return "springboot项目启动成功!";}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。