前言
eclipes软件:
连接数据库、写接口返回给vue,vue代理使用接口数据,并且渲染
提示:以下是本篇文章正文内容,下面案例可供参考
一、mysql
创建表:保存名:registerdb名 | 类型 |
---|---|
registerdbid | int |
realname | varchar |
nickname | varchar |
gender | varchar |
job | varchar |
organqy | varchar |
organtype | varchar |
papersid | varchar |
papersimg | varchar |
二、springboot
1.配置目录
主要看蓝色框
启动文件:springboot项目
(Application.java)
(RegisterdbController.java)
(Registerdb.java)
(RegisterdbMapper.java)
(RegisterdbMapper.xml)
(RegisterdbService.java)
(RegisterdbServiceimpl.java)
(application.properties)
(pom.xml)
2.源代码
代码如下(示例):
package indi.chq;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan(basePackages ={
"indi.chq.mapper"})
//说明:启动运行文件
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
package indi.chq.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import indi.chq.entity.Registerdb;
import indi.chq.service.RegisterdbService;
@RestController
//接口:访问地址/NAMS_mobile/getRegisterdb.do
@RequestMapping(value = "/NAMS_mobile")
public class RegisterdbController {
@Autowired
private RegisterdbService registerdbService;
@RequestMapping("/getRegisterdb.do")
public List<Registerdb> getRegisterdb() {
return registerdbService.getquery();
}
}
package indi.chq.entity;
//格式化:ctrl + shift + f
//创建构造函数的快捷键:alt + shift + s 在按o
//创建toString的快捷键:alt + shift + s 长按s
//创建get/set的快捷键:alt + shift + s 选择getters and setters
//实体类
public class Registerdb {
private int registerdbid;
private String realname;
private String nickname;
private String gender;
private String job;
private String organqy;
private String organtype;
private String papersid;
private String papersimg;
public Registerdb(int registerdbid, String realname, String nickname, String gender, String job, String organqy,
String organtype, String papersid, String papersimg) {
super();
this.registerdbid = registerdbid;
this.realname = realname;
this.nickname = nickname;
this.gender = gender;
this.job = job;
this.organqy = organqy;
this.organtype = organtype;
this.papersid = papersid;
this.papersimg = papersimg;
}
public Registerdb() {
super();
}
@Override
public String toString() {
return "Registerdb [registerdbid=" + registerdbid + ", realname=" + realname + ", nickname=" + nickname
+ ", gender=" + gender + ", job=" + job + ", organqy=" + organqy + ", organtype=" + organtype
+ ", papersid=" + papersid + ", papersimg=" + papersimg + "]";
}
public int getRegisterdbid() {
return registerdbid;
}
public void setRegisterdbid(int registerdbid) {
this.registerdbid = registerdbid;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nicknam