Main concept of this is: I want to have 2 radio button list. One with trainers and other with trainer's activities. I have two problems:
How can I get 2 radio button list with data retrieved from mysql db.
@Entity @Table(name = "trainers") public class Trainer { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "name") private String name; @Column(name = "pt_done") private Integer personalTraining; @Column(name = "target") private Integer target; @Column(name = "sale") private Integer sale; @Column(name = "steps") private Integer steps; public Trainer() {} //+getters and setters }
public interface TrainerRepository extends JpaRepository < Trainer, Integer > { @Query(value = "select name from trainers", nativeQuery = true) List < Trainer > findByName() @Service public class TrainerServiceImplementation implements TrainerService { private TrainerRepository trainerRepository; @Override public List < Trainer > findByName() { return trainerRepository.findByName(); } @Controller @RequestMapping("/gym") public class TrainerController { @Autowired private TrainerRepository trainerRepository; @Autowired private TrainerService trainerService; @RequestMapping("/hello") public String viewHomePage(Model theModel) { theModel.addAttribute("trainers", trainerRepository.findByName()); return "welcome"; } } } }
welcome.jsp
<form:form action="nextpage" modelAttribute = "trainers" method="POST"> <input type="radio" name="name" value="${trainers}"/> John Simson
I have no idea how i can retrieve data from db to radiobutton list. I have four trainers.
I have to check one of points from first radio button list and one of points from second radio button list. And after I chose 2 options I will redirect to new JSP Page (If checked personal training -> redirect to personaltraining.jsp, etc.)
How can I pass data to mysql table, e.g. I chose John Simson and Personal Training, I will fill next jsp page personaltraining.jsp and when i fill and send, I want to save it in db.