版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
工具:myeclispse
maven添加parent父依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.0.RELEASE</version> </parent>
添加dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
注意:如出现jar引入问题,右键项目—>maven—>update project…
新建controller包
App.java
package controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.socket.server.standard.ServerEndpointExporter; @SpringBootApplication // Spring Boot项目的核心注解,主要目的是开启自动配置 @ComponentScan(basePackages = "controller") @EnableAutoConfiguration public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
测试类
package controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorld { @RequestMapping("/hello.do") public String hello() { return "idaobin.com"; } }
地址栏访问:localhost:8080/hello.do
注意:对于后缀jsp页面不友好
html文件夹存入webapp里;css,js等静态文件存在resources/static/文件夹里,新建static文件夹
关于css,js,html中文乱码的解决方案
在resources文件夹里新建application.properties文件
spring.http.encoding.force=true spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true server.tomcat.uri-encoding=UTF-8
原文链接:https://www.idaobin.com/archives/2252.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告