quiz.jsp
~ play.jsp
에 링크가 있습니다. 그리고 play.jsp
에서 퀴즈 질문과 답변을 데이터베이스에서 표시하고 싶었지만 얻지 못했습니다. 도움이된다면 매우 감사 할 것입니다.봄에 원하는 출력을 얻지 못했습니다
Quiz.java
public class Quiz {
private int id;
private String question;
private String ans1;
private String ans2;
private String ans3;
// getters and setters here
}
QuizRowMapper.java
public class QuizRowMapper implements RowMapper {
public Quiz mapRow(ResultSet rs, int row) throws SQLException {
Quiz quiz = new Quiz();
quiz.setId(rs.getInt("idquestion"));
quiz.setQuestion(rs.getString("question"));
quiz.setAns1(rs.getString("ans1"));
quiz.setAns2(rs.getString("ans2"));
quiz.setAns3(rs.getString("ans3"));
return quiz;
}
}
QuizDaoImpl.java
public class QuizDaoImpl implements QuizDao {
private JdbcTemplate template;
@Autowired
DataSource dataSource;
public void setTemplate (JdbcTemplate template){
this.template = template;
}
public List<Quiz> getQuestion() {
List questionList = new ArrayList();
String sql = "select * from question";
JdbcTemplate template = new JdbcTemplate(dataSource);
questionList = template.query(sql, new QuizRowMapper());
return questionList;
}
public void insertQuestion() {
// TODO Auto-generated method stub
}
}
HomePageController.java
@Controller
public class HomePageController {
@Autowired
UserDaoImpl userDaoImpl;
@Autowired
QuizDaoImpl quizDaoImpl;
@RequestMapping("/register")
public ModelAndView registerUser(@ModelAttribute user use){
return new ModelAndView("register");
}
@RequestMapping("/insert")
public ModelAndView successMessage(@ModelAttribute user use){
if(use != null){
userDaoImpl.insertData(use);
}
return new ModelAndView("success" ,"name", use.getuName());
}
@RequestMapping("/login")
public ModelAndView getUserList(@ModelAttribute user u){
List<user> userList = userDaoImpl.getData();
int len = userList.size();
for(int i = 0;i< len ; i++){
String userr = userList.get(i).getuName();
if(userr.equals(u.getuName())){
return new ModelAndView("quiz","name", u.getuName());
}
}
return new ModelAndView("register");
}
@RequestMapping("/userSign")
public ModelAndView getUser(String name){
List<user> userList = userDaoImpl.getData();
int len = userList.size();
for(int i = 0;i<len ; i++){
String userr = userList.get(i).getuName();
if(userr.equals(name)){
return new ModelAndView("quiz","name", name);
}
}
return new ModelAndView("error","name",name);
}
@RequestMapping(value="/play.jsp")
public ModelAndView getQuestion(){
List<Quiz> quiz= quizDaoImpl.getQuestion();
return new ModelAndView("play", "quiz", quiz);
}
}
01,235,
quiz.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>play quiz</title>
</head>
<body>
Welcome ${name}
<a href="play.jsp">quizz</a>
</body>
</html>
play.jsp 당신의 play.jsp에서
<html>
<head>
<title>Being Java Guys | quiz </title>
</head>
<body>
<center>
<br /> <br /> <br /> <b>User
List | Being Java Guys </b><br /> <br />
<p>Question</p>
<p> ${quiz.id}</p>
<p>{quiz.question}</p><br>
<c:forEach items="${quiz}" var="qz">
<p> ${qz.id}</p>
<p>{qz.question}</p><br>
<p>${qz.ans1}</p>
<p> ${qz.ans2} </p>
<p>${qz.ans3} </p>
</c:forEach>
</center>
</body>
</html>
"의미하는 바는 * 원하는 출력 *과 현재 무슨 일이 일어나고 있는지입니다. – BackSlash
@BackSlash 'play.jsp'에 데이터베이스에 질문을 표시하고 싶지만받지 못했습니다. 고맙습니다. –
play.jsp 페이지에 질문 목록을 표시하려고하지만 그 목록을 탐색하는 데 실패하고 있다고 생각합니다. 퀴즈 개체는 하나가 아닌 완전한 목록입니다. foreach 태그 또는 동등한 것을 사용해야합니다. httwww://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/ – RubioRic