4.0.0
com.jmxk
SpringBoot-Start
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-freemarker
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-maven-plugin
true
注意:springBoot必须放在Controller包的顶层
package com.jmxk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBoot_Start {
public static void main(String[] args) {
SpringApplication.run(SpringBoot_Start.class, args);
}
}
package com.jmxk.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//@RestController = @Conctroller + @ResponseBody
@RestController
public class HelloController {
@RequestMapping("/helloIndex")
public String HelloIndex() {
return "欢迎使用springBoot2.0!";
}
}
控制信息出现Spring图标样式并且程序一直在运行没报错则表示启动成功!
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
2019-08-15 11:25:58.306 INFO 15224 --- [ restartedMain] com.jmxk.SpringBoot_Start : Starting SpringBoot_Start on DESKTOP-A9VMB8N with PID 15224 (F:\Eclipse-WorkSpace\JavaEE\SpringBoot_Start\target\classes started by com in F:\Eclipse-WorkSpace\JavaEE\SpringBoot_Start)
2019-08-15 11:25:58.309 INFO 15224 --- [ restartedMain] com.jmxk.SpringBoot_Start : No active profile set, falling back to default profiles: default
2019-08-15 11:25:58.357 INFO 15224 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-08-15 11:25:58.357 INFO 15224 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-08-15 11:25:59.419 INFO 15224 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-15 11:25:59.441 INFO 15224 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-15 11:25:59.441 INFO 15224 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2019-08-15 11:25:59.449 INFO 15224 --- [ restartedMain] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk1.8/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8/bin/../jre/bin;C:/Program Files/Java/jdk1.8/bin/../jre/lib/amd64;C:\Python27\;C:\Python27\Scripts;C:\Python\Python37\Scripts\;C:\Python\Python37\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.8\bin;MYSQL_HOME%\bin;D:\Maven\apache-maven-3.6.0\bin;D:\Node\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\TortoiseGit\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\TXsoft\Git\cmd;C:\Users\com\AppData\Local\Microsoft\WindowsApps;D:\Node\nodejs\node_global;;D:\JetBrains\IntelliJ IDEA 2019.1\bin;;D:\JetBrains\WebStorm 2019.1\bin;;C:\WINDOWS\system32;;.]
2019-08-15 11:25:59.522 INFO 15224 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-15 11:25:59.523 INFO 15224 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1165 ms
2019-08-15 11:25:59.725 INFO 15224 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-15 11:25:59.806 INFO 15224 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2019-08-15 11:25:59.905 INFO 15224 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-08-15 11:25:59.954 INFO 15224 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-15 11:25:59.958 INFO 15224 --- [ restartedMain] com.jmxk.SpringBoot_Start : Started SpringBoot_Start in 1.936 seconds (JVM running for 3.838)
springboot不需要输入项目名称,输入格式是本地IP地址+端口号+请求路径
本地IP地址:localhost或者127.0.0.1
端口号默认:8080
请求路径为Controller类中注解@RequestMapping("/helloIndex")自定义的值
org.springframework.boot
spring-boot-starter-freemarker
Spring整合FreeMarker!
${map.id}
${map.name}
${map.sex}
${map.age}
package com.jmxk.controller;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class FTLController {
@RequestMapping("/index")
public String index(Map map,HttpServletRequest request) {
map.put("id", 1);
map.put("name","李白");
map.put("age",20);
map.put("sex","男");
request.setAttribute("map", map);
return "index";
}
}