Spring boot 初心者调查用资料

开发传统Java WEB工程时,我们可以使用JSP页面模板语言,但是在SpringBoot中已经不推荐使用了。SpringBoot支持如下页面模板语言

  • Thymeleaf
  • FreeMarker
  • Velocity
  • Groovy
  • JSP

其中Thymeleaf是SpringBoot官方所推荐使用的,下面来谈谈Thymeleaf一些常用的语法规则。

@ModelAttribute

@Controller
public class FormatterController
{
    @RequestMapping(value = "/getForm", method = RequestMethod.POST)
    public String test(@ModelAttribute User user,Model model)
    {
        model.addAttribute("user", user);
        return "success";
    }

//Cjsp
@Controller
@RequestMapping(value = "/user")
public class FormatterController
{
    @RequestMapping(value = "/getForm", method = RequestMethod.POST)
    public String test(@ModelAttribute User user,Model model)
    {
        model.addAttribute("user", user);
        return "success";
    }

//V侧
<form:form modelAttribute="user" method="post" action="getForm">
    <form:input path="birthday"/>

<form role="form" action="/simple/confirm" th:action="@{/simple/confirm}" th:object="${simpleForm}" method="post">

资源文件中定义了内容welcome.msg=欢迎{0}光临!。可以这样子在页面中将其显示
<h2 th:text="#{welcome.msg('admin')}"/>
th:utext和th:text的区别是:
   th:text会对<和>进行转义,
   而th:utext不会转义。

 

关于“${属性}”和“{属性}”的区别?

${}访问完整信息,而{}访问指定对象中的属性内容, 如果访问的只是普通的内容两者没有区别;

<div>
    <p th:text="'用户编号:' + ${member.uid}"/>
    <p th:text="'用户姓名:' + ${member.name}"/>
    <p th:text="'用户年龄:' + ${member.age}"/>
    <p th:text="'用户工资:' + ${member.salary}"/>
    <p th:text="'出生日期:' + ${member.birthday}"/>
    <p th:text="'出生日期:' + ${#dates.format(member.birthday,'yyyy-MM-dd')}"/>
</div>

<hr/>
<div th:object="${member}">
    <p th:text="'用户编号:' + *{uid}"/>
    <p th:text="'用户姓名:' + *{name}"/>
    <p th:text="'用户年龄:' + *{age}"/>
    <p th:text="'用户工资:' + *{salary}"/>
    <p th:text="'出生日期:' + *{birthday}"/>
    <p th:text="'出生日期:' + *{#dates.format(birthday,'yyyy-MM-dd')}"/>
</div>

 

//各种controller方法例子

    @RequestMapping(value="/result", method=RequestMethod.POST)
    public String indexFormSubmit(@ModelAttribute IndexForm indexForm, Model model) {
        if (indexForm.getId() == 1) {
            indexForm.setContent("お前がナンバーワンだ!");
        }
        model.addAttribute("indexForm", indexForm);
        return "result";
    }

//提交的form数据从indexForm取得, 返回数据用model

 

 

 

推荐★★★ 项目详解
qiita.com/opengl-8080/items/05d9490d6f0544e2351a

 

 

项目目录 qiita.com/NariseT/items/172ca093364aa9391989
spring-boot-example1
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
├── spring-boot-example1.iml
└── src
    ├── main
    │   ├── java
    │   │   └── org
    │   │       └── mygroup
    │   │           └── webapp
    │   │               └── SpringBootExample1Application.java
    │   └── resources
    │       └── application.properties 
    │       └── templates
    │           └── index.html
    └── test
        └── java
            └── org
                └── mygroup
                    └── webapp
                        └── SpringBootExample1ApplicationTests.java

 

 

 

 

 

 

参考 

www.jianshu.com/p/a842e5b5012e
SpringBoot Thymeleaf
页面显示语法

qiita.com/NariseT/items/172ca093364aa9391989
项目目录

itsakura.com/java-springboot-submit
Java Spring Boot form 传值的例子
  参数以REST形式取得的时候。

 

qiita.com/opengl-8080/items/05d9490d6f0544e2351a
项目详解

srping boot annotation 注解一览

qiita.com/TEBASAKI/items/267c261db17f178e33eb
连载 Spring Boot解说第18回

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章