/imooc-springboot-starter/src/main/resources/application.properties
#關閉緩存, 即時刷新 #spring.freemarker.cache=false spring.thymeleaf.cache=true#熱部署生效 spring.devtools.restart.enabled=true #設置重啟的目錄,添加那個目錄的文件需要restart spring.devtools.restart.additional-paths=src/main/java # 為mybatis設置, 生產環境可刪除 #restart.include.mapper=/mapper-[\\w-\\.]+jar #restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar #排除那個目錄的文件不需要restart spring.devtools.restart.exclude=static/**,public/**,WEB-INF/** #classpath目錄下的WEB-INF文件夾內容修改不重啟 #spring.devtools.restart.exclude=WEB-INF/**
/imooc-springboot-starter/pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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>com.imooc</groupId><artifactId>imooc-springboot-starter</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>imooc-springboot-starter</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- 熱部署 --><!-- devtools可以實現頁面熱部署(即頁面修改后會立即生效,這個可以直接在application.properties文件中配置spring.thymeleaf.cache=false來實現) --><!-- 實現類文件熱部署(類文件修改后不會立即生效),實現對屬性文件的熱部署。 --><!-- 即devtools會監聽classpath下的文件變動,并且會立即重啟應用(發生在保存時機),注意:因為其采用的虛擬機機制,該項重啟是很快的 --><!-- (1)base classloader (Base類加載器):加載不改變的Class,例如:第三方提供的jar包。 --><!-- (2)restart classloader(Restart類加載器):加載正在開發的Class。 --><!-- 為什么重啟很快,因為重啟的時候只是加載了在開發的Class,沒有重新加載第三方的jar包。 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional><!-- optional=true, 依賴不會傳遞, 該項目依賴devtools;之后依賴boot項目的項目如果想要使用devtools, 需要重新引入 --></dependency> </dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
/imooc-springboot-starter/src/main/java/com/imooc/controller/UserController.java
package com.imooc.controller;import java.util.Date;//import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; //import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;import com.imooc.pojo.LeeJSONResult; import com.imooc.pojo.User;//@Controller @RestController // @RestControler = @Controller + @ResponseBody @RequestMapping("/user") public class UserController {//@RequestMapping("/hello")@RequestMapping("/getUser")//@ResponseBodypublic User hello() {//public User getUser() { User u = new User();u.setName("imooc");u.setAge(18);u.setBirthday(new Date());u.setPassword("imooc");//u.setDesc(null);u.setDesc("hello imooc~~");return u;}@RequestMapping("/getUserJson")//@ResponseBodypublic LeeJSONResult hello1() {//public LeeJsonResult getUserJson() { User u = new User();//u.setName("imooc");u.setName("imooc1");u.setAge(18);u.setBirthday(new Date());u.setPassword("imooc");//u.setDesc(null);//u.setDesc("hello imooc~~");u.setDesc("hello imooc1~~");return LeeJSONResult.ok(u);} }
/imooc-springboot-starter/src/main/java/com/imooc/controller/UserController.java
package com.imooc.controller;import java.util.Date;//import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; //import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController;import com.imooc.pojo.LeeJSONResult; import com.imooc.pojo.User;//@Controller @RestController // @RestControler = @Controller + @ResponseBody @RequestMapping("/user") public class UserController {//@RequestMapping("/hello")@RequestMapping("/getUser")//@ResponseBodypublic User hello() {//public User getUser() { User u = new User();//u.setName("imooc");u.setName("imooc1");u.setAge(18);u.setBirthday(new Date());//u.setPassword("imooc");u.setPassword("imooc1");//u.setDesc(null);//u.setDesc("hello imooc~~");u.setDesc("hello imooc1~~");return u;}@RequestMapping("/getUserJson")//@ResponseBodypublic LeeJSONResult hello1() {//public LeeJsonResult getUserJson() { User u = new User();//u.setName("imooc");u.setName("imooc1");u.setAge(18);u.setBirthday(new Date());u.setPassword("imooc");//u.setDesc(null);//u.setDesc("hello imooc~~");u.setDesc("hello imooc1~~");return LeeJSONResult.ok(u);} }
?