Passing value from controller to html in spring

前端 未结 3 832
挽巷
挽巷 2021-01-20 07:24

Hello I have a simple web page where I have a button and a text near to button. I need to change text when button clicked and get the new text from code.

This is con

3条回答
  •  星月不相逢
    2021-01-20 08:10

    Change

    ?????

    To

    ${stream}

    OR

    How it is working?

    You can access variables value by ${key}.

    Example

    model.addAttribute("key", value);   
    

    Get value by ${key} in HTML

    In Thymeleaf, these model attributes (or context variables in Thymeleaf jargon) can be accessed with the following syntax: ${attributeName}, where attributeName in our case is stream. This is a Spring EL expression. In short, Spring EL (Spring Expression Language) is a language that supports querying and manipulating an object graph at runtime.

    UPDATE

    The th:field attribute can be used on input, select, or, textarea.

    Replace

    ?????

    with

    
    

    OR

    `
    

    OR

    
    

    Also try

    [[${stream}]]

    ;

    />

    Thymeleaf Document Thymeleaf Document Inputs


    UPDATE 2

    Get value from Thymeleaf to Spring Boot

    @GetMapping("/send") public String send(@RequestParam(name="doc", required = false) String doc) { //change required = false as per requirement System.out.println("Doc: "+doc); return "textarea-input"; }

    Note: use "th:field" for Entity/Model

提交回复
热议问题