idea+Spring Boot+freemarkerは勉強すればすぐできます.
3126 ワード
1.idea 2018,1バージョン-file-new-project
2.
3.
4.pomファイルの設定
10.ブラウザにlocal hostを入力する:10001/index/test/ 効果を表示
11.最終ファイルディレクトリ構造
成功したらいいですね.
2.
3.
4.pomファイルの設定
4.0.0
com.King
testSpringBoot
1.0-SNAPSHOT
org.springframework.boot
spring-boot
2.0.1.RELEASE
org.springframework.boot
spring-boot-starter-web
2.0.1.RELEASE
org.springframework.boot
spring-boot-starter-freemarker
2.0.1.RELEASE
org.springframework.boot
spring-boot-starter-test
2.0.1.RELEASE
test
5.レスポンスディレクトリの下にwebappディレクトリとappration.ymlファイルをそれぞれ追加します.server:
port: 10001
spring:
profiles: default
freemarker:
template-loader-path: classpath:/webapp/WEB-INF/ftl/
cache: true
check-template-location: true
content-type: text/html; charset=UTF-8
expose-request-attributes: true
expose-session-attributes: true
request-context-attribute: request
suffix: .ftl
6.パッケージディレクトリを作成し、該当するクラスを作成するpackage com.king.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* create by wu 2018/5/29
*/
@Controller
@RequestMapping("/index/")
public class IndexController {
@RequestMapping(value = "test/")
public String test(Model model){
String s= "this is from Server";
model.addAttribute("str",s);
return "index";
}
}
7.webディレクトリの下でspringboot起動類を新規作成するpackage com.king.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* create by wu 2018/5/29
*/
@SpringBootApplication
public class WebIndexApplication {
public static void main(String[] args){
SpringApplication.run(WebIndexApplication.class,args);
}
}
8.webappディレクトリの下で、WEB-INFディレクトリとサブディレクトリftlを新規作成します. ftlディレクトリの下でindex.ftlファイルを新規作成します.
Title
${str}
9.springbootアプリケーションを起動する10.ブラウザにlocal hostを入力する:10001/index/test/ 効果を表示
11.最終ファイルディレクトリ構造
成功したらいいですね.