java springcloud版b2b2c社交电商spring cloud分布式微服务 (二十)处理表单提交

这篇文件主要介绍通过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:

电子商务社交平台源码请加企鹅求求:叁五叁六贰四柒贰五九

你可能感兴趣的:(springcloud,b2b2c,java电子商务)