How do I populate a drop down with a list using thymeleaf and spring

前端 未结 5 1913
天涯浪人
天涯浪人 2020-11-29 06:26

I need to populate a drop down with all the values within a list of strings.

Controller Class

@RequestMapping(value = \"/generateIds\", method = Requ         


        
5条回答
  •  一向
    一向 (楼主)
    2020-11-29 07:20

    This is how I populate the drop down list.I think it may help to you get some idea about it.

    Controller

    List operators =  operatorService.getAllOperaors()
    model.addAttribute("operators", operators);
    

    Model

      @Entity
      @Table(name = "operator")
      public class Operator {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "id")
        @JsonIgnore
        private Long id;
    
        @NotBlank(message="operator Name cannot be empty")
        @Column(name = "operator_name", nullable = false)
        private String operatorName;
    
        getters and setters ...
    
    }   
    

    View

提交回复
热议问题