Home > Enterprise >  JSP Hibernate print "count tuple" result in a local page?
JSP Hibernate print "count tuple" result in a local page?

Time:12-05

I'm so new to this that I can't tell if the question makes sense.

I'm trying to print a "count tuple" on a local page(localhost:8080) using jsp if possible?

StudentEntity

@Id
@Column(name="SNO")
private Integer sno;
@Column(name="PNO")
private Integer pno;

@Column(name="SNAME")
private String sname;

@Column(name="YEAR")
private Integer year;

@Column(name="DEPT")
private String dept;

StudentRepository

I believe this is where the query should go? Added codes below.

@Override
@Query(
        value = "SELECT * FROM STUDENT",
        nativeQuery = true
)
List<StudentEntity> findAll();

@Modifying
@Transactional
@Query(
        value  = "INSERT INTO STUDENT(SNO, PNO, SNAME, YEAR, DEPT, //COUNT(SNO)) "  
                "VALUES (:sno, :pno, :sname, :year, :dept, //:countTuple)",
        nativeQuery = true
)
void saveOne(
        @Param("sno") Integer sno,
        @Param("pno") Integer pno,
        @Param("sname") String sname,
        @Param("year") Integer year,
        @Param("dept") String dept
//@Param("dept") Integer countTuple
);

StudentService

public List<StudentEntity> findAll() {
    return studentRepository.findAll();
}

public StudentEntity save(StudentEntity studentEntity){
    studentRepository.saveOne(
            studentEntity.getSno(),
            studentEntity.getPno(),
            studentEntity.getSname(),
            studentEntity.getYear(),
            studentEntity.getDept()
//studentEntity.getCountTuple()
    );
    return studentEntity;

DatabaseController

@GetMapping(value = "/student")
public ModelAndView stu() {
    ModelAndView modelAndView = new ModelAndView("selectTest");

    List<StudentEntity> students = studentService.findAll();

    modelAndView.addObject("students", students);

    return modelAndView;
}

selectTest.jsp

    <c:forEach items="${students}" var="student">
        <tr>
            <td width="100">${student.getSno()}</td>
            <td width="100">${student.getPno()}</td>
            <td width="100">${student.getSname()}</td>
            <td width="100">${student.getYear()}</td>
            <td width="100">${student.getDept()}</td>
<!--<td width="100">$(student.getCountTuple()}</td>-->
        </tr>
    </c:forEach>

CodePudding user response:

There are couple of things to fix.

  1. Use direct field names instead of getter methods in JSP.

    ${student.sno}

  2. Add countTuple field in entity class with getter setters.

  3. Remove small bracket and put curly brace from the current code.

    ${student.countTuple}

  • Related