Giter VIP home page Giter VIP logo

demo's Introduction

IndexController

@GetMapping("/index2")
public String doGet(Model model) {
    model.addAttribute("sr", new StudentRequest());
    return "index.html";
}

@PostMapping("/index2")
public String doPost(Model model, @ModelAttribute("sr") StudentRequest sr) {
    studentService.saveStudent(sr);
    model.addAttribute("name", sr.name);
    return "output.html";
}

Student

grade 추가 및 Setter 수동 추가 버그 고쳤으므로 Setter로 처리

private String name;
private int grade;

public void setName(String name){
    this.name = name;
}

public void setGrade(int grade){
    this.grade = grade;
}

StudentRequest

Getter, Setter, 변수 grade 추가 -> 얘네는 수동으로 잡아줘야 가능

public int grade;

public String getName(){
    return name;
}
public int getGrade(){
    return grade;
}
public void setName(String name){
    this.name = name;
}
public void setGrade(int grade){
    this.grade = grade;
}

index.html 수정

StudentRequest 받은 것을 th:object="${sr}" 로 추가 -> Request 이름 변경시 object 내용수정
input의 name 대신 th:field="*{Request의 변수명}" 형태로 작성

<form th:object="${sr}" method="post" action="index2">
    이름 <input th:field="*{name}">
    학년 <input th:field="*{grade}">
    <button>전달</button>
</form>

demo's People

Contributors

hideyoshi515 avatar glrln avatar

Watchers

 avatar

Forkers

glrln

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.