新建一个类写入一下内容(其中定义的需要和数据表中的相对应):
import java.util.Date;
public class User {
/**
* bigint > Long
*/
private Long id;
private String name;
private String passwd;
private String sex;
private String phoneNum;
private Date create_time;
private Date update_time;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public Date getCreate_time() {
return create_time;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getUpdate_time() {
return update_time;
}
public void setUpdate_time(Date update_time) {
this.update_time = update_time;
}
}
在UserController
中新建一个方法
@RequestMapping("/user")
public User user(Long id){
return userMapper.selectUserById(id);
}
在UserMapper
中加入以下内容:
@Select("SELECT * FROM user WHERE id = #{id}")
User selectUserById(Long id);
在application.yml
中顶格加入
mybatis:
config-location:
map-underscore-to-camel-case: true
然后访问http://127.0.0.1:8080/user?id=1可获取数据库中id为1的整条数据
版权属于:kenvie
本文链接:https://cloud.tencent.com/developer/article/1937671
商业转载请联系作者获得授权,非商业转载请注明出处。