ruyujiexys
微笑的萌新
2018-12-24 18:53

javaEE连接mysql数据库,然后通过映射把数据显示到网页上,可是没报错却网页没有内容。

5
  • mysql
  • java-ee
<div>
    <ul>
        <li th:each="subject:${subjects}">
            <span th:text="${subject.kc_name}"></span>
            <span th:text="${subject.kc_teach}"></span>
            <span th:text="${subject.begin_sj}"></span>
        </li>
    </ul>
</div>
//这个是要显示的网页
```//显示所有学生信息的请求
    @RequestMapping("/query_subject")
    public String querySubject(Model model){
        List<Subject> subjects = null;
        LSubject subject = new LSubject();
        String sqlTxt = "select * from subject_info";
        try {
            subjects = subject.querySubject(sqlTxt);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        model.addAttribute("subjects", subjects);
        return "subject_info";
    }//这个是请求;

//向数据库查询教师课程数据,并返回list格式类型的数据。
public List querySubject(String sqlTxt)
throws ClassNotFoundException {
List subjects = new ArrayList();
JdbcTemplate jdbcTemplate = new JdbcTemplate();
DbManage db = new DbManage();
jdbcTemplate.setDataSource(db.getDataSource());
List> list = jdbcTemplate.queryForList(sqlTxt);
for(Map map : list){
Subject subject = new Subject();
subject.setKc_name(map.get("kc_name").toString());
subject.setKc_teach(map.get("kc_teach").toString());
subject.setBegin_sj(map.get("begin_sj").toString());
}
return subjects;
}//这个处理器,负责处理


//这个是类似超链接一样的,点击“我教的课”就处理请求
<li><a href="/query_subject"><i class="icon-briefcase"></i>我教的课</a></li>


//这个是要显示的网页
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>Insert title here</title>
</head>
<body>
<h2>我教的课</h2>
<div>
    <ul>
        <li  th:each="subject:${subjects}">
            <span th:text="${subject.kc_name}"></span>
            <span th:text="${subject.kc_teach}"></span>
            <span th:text="${subject.begin_sj}"></span>
        </li>
    </ul>
</div>
</body>
</html>```
//还有Subject这个文件没有打出来,大致是

package student.stusys.entity;

public class Subject {
    private String kc_name;
    private String kc_teach;
    private String begin_sj;


    public String getKc_name() {
        return kc_name;
    }

    public void setKc_name(String kc_name) {
        this.kc_name = kc_name;
    }
    public Subject(String kc_name, String kc_teach,String begin_sj) {
        this.kc_name = kc_name;
        this.kc_teach = kc_teach;
        this.begin_sj = begin_sj;
    }

    public Subject() {
    }
    public String getKc_teach() {
        return kc_teach;
    }

    public void setKc_teach(String kc_teach) {
        this.kc_teach = kc_teach;
    }

    public String getBegin_sj() {
        return begin_sj;
    }

    public void setBegin_sj(String begin_sj) {
        this.begin_sj = begin_sj;
    }
}


运行以后发现网页上只显示了subject_info.html上面的“我教的课”四个字,其他都没显示出来,还有数据库里面有subject_info这个表,包括kc_name,kc_teach,begin_sj三个字段,希望有会的朋友告诉我解决的方法,谢谢!


用的软件是IDEA。
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐