• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

微信小程序简单的数据表格及查询功能

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

简介:

此项目是一个前后端分离的小demo,

开发工具:idea+微信小程序开发工具

前端:界面布局样式和js的跳转

后端:依靠SpringBoot的业务逻辑层

项目的码云地址:

 https://gitee.com/zhege/WebChatDemoJava

微信开发工具的使用和代码的结构及其含义参考

https://developers.weixin.qq.com/miniprogram/dev/api/

 

后端业务逻辑的完成

1.数据库的创建

 工具:Navicat

 

2. dao层及其方法的实现

1>bookinfo的实例化,利用@Entity完成映射

@Entity
@Table(name = "bookinfo")
public class BookinfoEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int bookId;
    @Column
    private String bookType;
    @Column
    private String bookName;
    @Column
    private int bookNum;
    @Column
    private int bookState;

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    public String getBookType() {
        return bookType;
    }

    public void setBookType(String bookType) {
        this.bookType = bookType;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public int getBookNum() {
        return bookNum;
    }

    public void setBookNum(int bookNum) {
        this.bookNum = bookNum;
    }

    public int getBookState() {
        return bookState;
    }

    public void setBookState(int bookState) {
        this.bookState = bookState;
    }
}
bookinfoentity

2>bookstate的实例化

@Entity
@Table(name = "bookstate")
public class BookstateEntity {
    @Id
    private int bookState;
    @Column
    private String bookStateinfo;

    public int getBookState() {
        return bookState;
    }

    public void setBookState(int bookState) {
        this.bookState = bookState;
    }

    public String getBookStateinfo() {
        return bookStateinfo;
    }

    public void setBookStateinfo(String bookStateinfo) {
        this.bookStateinfo = bookStateinfo;
    }
}
bookstateEntity

3>利用repository实现对对象的持久化操作,是OO的真正实现

@Repository
public interface BookInfoRepository extends JpaRepository<BookinfoEntity,Integer> {
}
@Repository
public interface BookstateRepository extends JpaRepository<BookstateEntity,Integer> {
}

 

3.service层的实现、

 3.1  BookinfoService接口

package com.example.demo.service;


import com.example.demo.vo.BookinfoVo;

import java.util.List;

/**
 * Author: wuhen
 * Date: 2018/10/9
 * Time: 20:40
 */
public interface BookinfoService {

    //查询书籍
    BookinfoVo findbookOne(Integer bookId);

    //查询所有书籍
   List<BookinfoVo> findbookAll();

}
BookinfoService

3.2   接口的实现

package com.example.demo.service.impl;


import com.example.demo.entity.BookinfoEntity;
import com.example.demo.entity.BookstateEntity;
import com.example.demo.repository.BookinfoRepository;
import com.example.demo.repository.BookstateRepository;
import com.example.demo.service.BookinfoService;
import com.example.demo.util.BookConverter;
import com.example.demo.vo.BookinfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * Author: wuhen
 * Date: 2018/10/9
 * Time: 20:48
 */
@Service
public class BookinfoServiceImpl implements BookinfoService {
    @Autowired
    private BookinfoRepository bookinfoRepository;
    @Autowired
    private BookstateRepository bookstateRepository;
    BookConverter bookConverter=new BookConverter();
    @Override
    public BookinfoVo findbookOne(Integer bookId) {

        BookinfoEntity bookinfoEntity= bookinfoRepository.findById(bookId).get();
        BookstateEntity bookstateEntity = bookstateRepository.findById(bookinfoEntity.getBookState()).get();
        BookinfoVo bookinfoVo;
        bookinfoVo = bookConverter.convert(bookinfoEntity, BookinfoVo.class);
        bookinfoVo.setBookStateinfo(bookstateEntity.getBookStateinfo());
        return bookinfoVo;
    }

    @Override
    public List<BookinfoVo> findbookAll() {
        List<BookinfoEntity> bookinfoEntitys=bookinfoRepository.findAll();
        List<BookinfoVo> bookinfoVos=new ArrayList<>();

        for (BookinfoEntity bookinfoEntity:bookinfoEntitys)
        {
            BookinfoVo bookinfoVo;
            BookstateEntity bookstateEntity= bookstateRepository.findById(bookinfoEntity.getBookState()).get();
            bookinfoVo=bookConverter.convert(bookinfoEntity,BookinfoVo.class);
            bookinfoVo.setBookStateinfo(bookstateEntity.getBookStateinfo());
            bookinfoVos.add(bookinfoVo);
        }

       return bookinfoVos;
    }
}
BookinfoServiceImpl

 

4. controller层的实现

package com.example.demo.controller;



import com.example.demo.service.BookinfoService;
import com.example.demo.util.ResultVOUtil;
import com.example.demo.vo.BookinfoVo;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: wuhen
 * Date: 2018/10/9
 * Time: 20:55
 */
@RestController
@RequestMapping("/book")
public class BookinfoController {
    @Autowired
    private BookinfoService bookinfoService;
    //查询单个
    @GetMapping("/findOne")
    public ResultVO<BookinfoVo> findbookOne(@RequestParam(value = "bookId") Integer bookId){
               BookinfoVo bookinfoVo= bookinfoService.findbookOne(bookId);
               return ResultVOUtil.success(bookinfoVo);
    }
    //查询所有
    @GetMapping("/findAll") public ResultVO<BookinfoVo> findbookAll(){
       List <BookinfoVo> bookinfoVo= bookinfoService.findbookAll();
       return ResultVOUtil.success(bookinfoVo);
   }
}
BookinfoController

 

5. 请求返回json数据

{
    "code": 0,
    "msg": "成功",
    "data": [
        {
            "bookId": 1,
            "bookType": "数学",
            "bookName": "大数宣讲",
            "bookNum": 20,
            "bookStateinfo": "在架"
        },
        {
            "bookId": 2,
            "bookType": "语文",
            "bookName": "国语",
            "bookNum": 30,
            "bookStateinfo": "在架"
        },
        {
            "bookId": 3,
            "bookType": "英语",
            "bookName": "四六级",
            "bookNum": 45,
            "bookStateinfo": "在架"
        },
        {
            "bookId": 4,
            "bookType": "科技",
            "bookName": "天眼",
            "bookNum": 12,
            "bookStateinfo": "在架"
        }
    ]
}
{
    "code": 0,
    "msg": "成功",
    "data": {
        "bookId": 2,
        "bookType": "语文",
        "bookName": "国语",
        "bookNum": 30,
        "bookStateinfo": "在架"
    }
}

 前端业务逻辑的完成

1.效果

2.结构布局

具体代码参考源代码

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap