使用bootstrap-table,bootstrap,以及MyBatis框架链接数据库

1 school的index页面




    
    Student

    
    


    

2  操作school index页面的js代码  注意!!!!!!!其中$('#tabList')这个标签选择器中的id是table标签中的id

 url: 'school/getData '  所指的是controller中的@RequestMapping("/getData")

3 使用Mybatis框架将数据库中的数据在网页中显示

MyBatis框架的步骤!!!!!!!!!!!!!!!!!!!!!!!!!

1.写实体类School

package com.stu.frame.myspringboot.model;

public class MySchool {

    private Integer id;

    private String seq;

    private String score;

    private String name;

    private String level;

    private String remark;

    @Override
    public String toString() {
        return "MySchool{" +
                "id=" + id +
                ", seq='" + seq + '\'' +
                ", score='" + score + '\'' +
                ", name='" + name + '\'' +
                ", level='" + level + '\'' +
                ", remark='" + remark + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSeq() {
        return seq;
    }

    public void setSeq(String seq) {
        this.seq = seq;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}

 2.写SchoolMapper接口,并在接口中定义方法,由于该类为接口所以无需实现方法。

package com.stu.frame.myspringboot.dao;

import com.stu.frame.myspringboot.model.MySchool;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MySchoolMapper {

    List selSchool();
}

3.写SchoolService类  使用@Service注解表示该类为service层  @Autowired注解是将UserMapper 加载到该类中相当与new UserMapper 。

package com.stu.frame.myspringboot.service;

import com.stu.frame.myspringboot.dao.UserMapper;
import com.stu.frame.myspringboot.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public User selByName(String name){
        return userMapper.selByName(name);
    }
}

4.写SchoolMapper.xml配置文件 用于操作数据库

注意!!!!!!!!!!

其中Mapper标签中的 namespace属性的值是 SchoolMapper接口的全路径

select标签中id属性的值是SchoolMapper接口中定义的方法名,切记一定要与方法名一样,建议直接复制,resultType属性的值是School实体类的全路径




    

5.conterller层代码

package com.stu.frame.myspringboot.controller;

import com.stu.frame.myspringboot.common.BootstrapTable;
import com.stu.frame.myspringboot.common.QueryParam;
import com.stu.frame.myspringboot.common.TestData;
import com.stu.frame.myspringboot.model.MySchool;
import com.stu.frame.myspringboot.model.School;
import com.stu.frame.myspringboot.service.ISchoolService;
import com.stu.frame.myspringboot.service.MySchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/school")
public class SchoolController {

    @Autowired
    MySchoolService mySchoolService;

    @RequestMapping({"/index", ""})
    public String getLogin(Model model) {
        return "school/index";
    }


    @RequestMapping("/getData")
    @ResponseBody
    public BootstrapTable getData() {

        List list = mySchoolService.selSchool();

        return new BootstrapTable(30, list);
    }

}

 

你可能感兴趣的:(使用bootstrap-table,bootstrap,以及MyBatis框架链接数据库)