数据库接口说明

陈志锴

一、t_user数据表:

用户id、用户名、密码、信誉分、邮箱、电话、上次访问时间、上次访问的ip地址、用户头像、用户标签、用户简介、买家评价、卖家评价

TUser类及其属性:

 1 public class TUser {
 2     private String userId;
 3     private String password;
 4     private String userName;
 5     private int credits;
 6     private String email;
 7     private String mobile;
 8     private String lastVisit;
 9     private String lastIp;
10     private Image image;
11     private String lable;
12     private String introduction;
13     private String buyerComment;
14     private String sellerComment;
15     /*
16     ...
17     */
18 }

 

数据库接口方法:

 1 public interface TUserMapper {
 2     /**
 3      * This method was generated by MyBatis Generator.
 4      * This method corresponds to the database table t_user
 5      *
 6      * @mbggenerated Sat May 05 16:02:56 CST 2018
 7      */
 8     public int insertUser(TUser record) throws Exception;
 9 
10     public TUser findUserById(String id) throws Exception;
11 
12     public TUser findUserByName(String name) throws Exception;
13 
14     public int deleteUser(String id) throws Exception;
15 
16     List<TUser> selectAll();
17 }

1. TUser insertUser(TUser record):参数:Tuser类,返回1说明插入成功

使用方法:此接口仅用于注册,插入一个用户,先new一个TUser类sysRole,再设置其id、name、email、password(必须的步骤),最后调用insertUser接口插入用户sysRole;大致步骤如下图所示

2.TUser findUserById(String  id):通过用户Id查找用户,参数:字符串id,返回要查找的用户类

使用方法:具体见下述第二行代码,括号内参数为需要搜索的id

3.TUser findUserByName(String  name):通过用户名查找用户,参数:字符串名,返回要查找的用户类

方法基本同上,区别就是把传入参数改成用户名

4.deleteUser:通过用户Id删除用户,参数:字符串id,返回1说明删除成功

方法基本同上,区别就是把传入参数改成id,操作结果即为删除了该用户

5.List<TUser>  selectAll( ):返回所有用户信息存储在列表中,无参数

二、books数据表

商品信息

Books类、属性、构造方法:

public class Books {
    private String ownerId;
    private String bookName;
    private String edition;
    private String author;
    private String press;
    private String introduction;
    private String operation;
    private String link;
    private String comment;
    private String bookId;

    public Books(String ownerId, String bookName, String edition, String author, String press, String introduction, String operation, String link, String comment) {
        this.ownerId = ownerId;
        this.bookName = bookName;
        this.edition = edition;
        this.author = author;
        this.press = press;
        this.introduction = introduction;
        this.operation = operation;
        this.link = link;
        this.comment = comment;
        this.bookId = bookId;
    }

    /*
    ...
    */
}

 

数据库接口方法:

 1 public interface BooksMapper {
 2     int insertBook(Books record);
 3 
 4     int insertSelective(Books record);
 5 
 6     int deleteBook(String id);
 7 
 8     public Books findBookById(String id) throws Exception;
 9 
10     public  List<Books> findBookByName(String name) throws Exception;
11 
12     public  List<Books> findBookByAuthor(String author) throws Exception;
13 
14     public  List<Books> findBookByPress(String press) throws Exception;
15     
16     public  List<Books> findBookByOwner(String id) throws Exception;
17 }

1.insertBook:须插入所有属性,不建议使用

2.int insertSelective(Books record):参数:Books类,返回1说明插入成功

使用方法:与插入用户基本类似,必须插入的信息有书名book_name、操作方法operation。

3.int deleteBook(String id):参数:字符串id、返回1说明删除成功

4.5.6.7均为查找书目的接口

 

备注:总结一下插入的简单步骤,就是创建对象(类),用set方法设置对象的属性,再把对象作为参数调用接口 

posted @ 2018-07-29 22:40  DeltaFish  阅读(810)  评论(0编辑  收藏  举报