java版spring cloud+spring boot+redis多租户社交电子商务平台(二十)处理表单提交

这篇文件主要介绍通过springboot 去创建和提交一个表单。

创建工程

涉及了 web,加上spring-boot-starter-web和spring-boot-starter-thymeleaf的起步依赖。


        
            org.springframework.boot
            spring-boot-starter-web
        
 
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
 
 
            
                org.springframework.boot
                spring-boot-starter-thymeleaf
            
 
    

创建实体
代码清单如下:

public class Greeting {
 
    private long id;
    private String content;
 
    public long getId() {
        return id;
    }
 
    public void setId(long id) {
        this.id = id;
    }
 
    public String getContent() {
        return content;
    }
 
    public void setContent(String content) {
        this.content = content;
    }
 
}

创建Controller

@Controller
public class GreetingController {
 
    @GetMapping("/greeting")
    public String greetingForm(Model model) {
        model.addAttribute("greeting", new Greeting());
        return "greeting";
    }
 
    @PostMapping("/greeting")
    public String greetingSubmit(@ModelAttribute Greeting greeting) {
        return "result";
    }
 
}

页面展示层
src/main/resources/templates/greeting.html




    Getting Started: Handling Form Submission
    


    

Form

Id:

Message:

需要JAVASpring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六

你可能感兴趣的:(java版spring cloud+spring boot+redis多租户社交电子商务平台(二十)处理表单提交)