1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Springboot 整合微信小程序?qū)崿F(xiàn)登錄與增刪改查

        共 23434字,需瀏覽 47分鐘

         ·

        2020-08-06 11:10

        作者:安詳?shù)目喽〔?br>鏈接:https://www.cnblogs.com/ckfeng/p/12812214.html

        粉絲福利:已經(jīng)絕版的《數(shù)據(jù)結(jié)構(gòu)和算法(第二版)》高清電子書(shū)!我搞到了!

        項(xiàng)目描述:在微信小程序中通過(guò)與Springboot操作數(shù)據(jù)庫(kù)實(shí)現(xiàn)簡(jiǎn)單的增刪改查,其中我是用springboot整合mybatis-plus 和mysql使用的

        1. 開(kāi)發(fā)前準(zhǔn)備

        1.1 前置知識(shí)

        • java基礎(chǔ)
        • SpringBoot簡(jiǎn)單基礎(chǔ)知識(shí)

        1.2 環(huán)境參數(shù)

        • 開(kāi)發(fā)工具:IDEA
        • 基礎(chǔ)環(huán)境:Maven+JDK8
        • 主要技術(shù):SpringBoot、lombok、mybatis-plus、mysql 、微信小程序
        • SpringBoot版本:2.2.6
        2.開(kāi)發(fā)者服務(wù)器

        項(xiàng)目結(jié)構(gòu):

        48ab8bdf36320842c045216b7599cd5e.webp

        2.1 初始配置

        (1)pom.xml配置

         <dependencies>
                <dependency>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-webartifactId>
                dependency>

                <dependency>
                    <groupId>org.mybatis.spring.bootgroupId>
                    <artifactId>mybatis-spring-boot-starterartifactId>
                    <version>2.1.1version>
                dependency>

                
                <dependency>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-thymeleafartifactId>
                dependency>

                
                <dependency>
                    <groupId>com.alibabagroupId>
                    <artifactId>druidartifactId>
                    <version>1.1.14version>
                dependency>

                
                <dependency>
                    <groupId>mysqlgroupId>
                    <artifactId>mysql-connector-javaartifactId>
                    <version>5.1.42version>
                    <scope>runtimescope>
                dependency>

                
                <dependency>
                    <groupId>com.baomidougroupId>
                    <artifactId>mybatis-plus-boot-starterartifactId>
                    <version>3.1.0version>
                dependency>

                
                <dependency>
                    <groupId>org.projectlombokgroupId>
                    <artifactId>lombokartifactId>
                    <optional>trueoptional>
                dependency>

                
                <dependency>
                    <groupId>com.github.pagehelpergroupId>
                    <artifactId>pagehelper-spring-boot-starterartifactId>
                    <version>1.2.5version>
                dependency>

                
                <dependency>
                    <groupId>junitgroupId>
                    <artifactId>junitartifactId>
                    <scope>testscope>
                dependency>

                <dependency>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-testartifactId>
                    <scope>testscope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.junit.vintagegroupId>
                            <artifactId>junit-vintage-engineartifactId>
                        exclusion>
                    exclusions>
                dependency>
            dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.bootgroupId>
                        <artifactId>spring-boot-maven-pluginartifactId>
                    plugin>
                plugins>
            build>

        project>

        (2)application.yml

        # Spring Boot 的數(shù)據(jù)源配置
        spring:
          datasource:
            name: wx
            url: jdbc:mysql://localhost:3306/wx_mini_program?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
         username: root
            password: root
            # 使用druid數(shù)據(jù)源
            type: com.alibaba.druid.pool.DruidDataSource
            driver-class-name: com.mysql.jdbc.Driver
            filters: stat
            maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 maxOpenPreparedStatements: 20 # mybatis-plus相關(guān)配置
        mybatis-plus:
          # xml掃描,多個(gè)目錄用逗號(hào)或者分號(hào)分隔(告訴 Mapper 所對(duì)應(yīng)的 XML 文件位置)
          mapper-locations: classpath:mapper/*.xml
          # 以下配置均有默認(rèn)值,可以不設(shè)置
          global-config:
            db-config:
              #主鍵類(lèi)型 AUTO:"數(shù)據(jù)庫(kù)ID自增" INPUT:"用戶(hù)輸入ID",ID_WORKER:"全局唯一ID (數(shù)字類(lèi)型唯一ID)", UUID:"全局唯一ID UUID";
              id-type: auto
              #字段策略 IGNORED:"忽略判斷"  NOT_NULL:"非 NULL 判斷")  NOT_EMPTY:"非空判斷"
              field-strategy: NOT_EMPTY
              #數(shù)據(jù)庫(kù)類(lèi)型
              db-type: MYSQL

          # 指定實(shí)體類(lèi)的包
          type-aliases-package: com.ckf.login_wx.entity
          configuration:
            # 是否開(kāi)啟自動(dòng)駝峰命名規(guī)則映射:從數(shù)據(jù)庫(kù)列名到Java屬性駝峰命名的類(lèi)似映射
            map-underscore-to-camel-case: true
            # 如果查詢(xún)結(jié)果中包含空值的列,則 MyBatis 在映射的時(shí)候,不會(huì)映射這個(gè)字段
            call-setters-on-nulls: true
            # 這個(gè)配置會(huì)將執(zhí)行的sql打印出來(lái),在開(kāi)發(fā)或測(cè)試的時(shí)候可以用
            log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

        # PageHelper分頁(yè)插件
        pagehelper:
          helperDialect: mysql
          reasonable: true
          supportMethodsArguments: true
          params: count=countSql

        2.2 小程序用戶(hù)表


        CREATE table users(
         id int not null PRIMARY key auto_increment,
         name varchar(255not null,
         age int not null );

        insert into users value(null,'陳克鋒',18);
        insert into users value(null,'陳克帥',11);
        insert into users value(null,'陳克兵',14); select * from users;

        2.3 pojo

        d02023191c80c8bfa5f630c108cef12d.webp

        2.4 mapper

        57ef0377b7ace73da30f86ab54ca207c.webp

        2.5 service

        dd2b8d8cbbd61e023ffbd9d89c428b10.webp

        2.5 serviceImpl

        bd6058be57bd9d788afe9afa91bb805c.webp

        配置SpringBoot掃描mapper

        caf632731d49b389c3d847aec39e0408.webp

        2.6 controller

        LoginController


        package com.ckf.login_wx.controller;

        import org.springframework.web.bind.annotation.PostMapping;
        import org.springframework.web.bind.annotation.RestController;

        import java.util.HashMap;
        import java.util.Map; /**
         * @author 安詳?shù)目喽〔?br> * @date 2020/4/30 11:46 */
         @RestController public class LoginController /**
             * 登錄
             * @param phone
             * @param password
             * @return */
         @PostMapping("/doLogin"public Map doLogin(String phone, String password){
                Map map = new HashMap(); if ((phone.equals("10086")&& password.equals("123456"))){
                    map.put("code",200);
                    map.put("result","登錄成功");
                    System.out.println("登錄成功");
                }else {
                    map.put("result","no");
                } return map;
            }

        }

        UserController


        package com.ckf.login_wx.controller;

        import com.ckf.login_wx.entity.User;
        import com.ckf.login_wx.servic.UserService;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.*; /**
         * @author 安詳?shù)目喽〔?br> * @date 2020/4/30 13:39 */
         @RestController
        @RequestMapping("/test"public class UserController {

            @Autowired private UserService userService; /**
             * 查詢(xún)?nèi)?br>     * @return */
         @GetMapping("/list"public Object list(){
                System.out.println("查詢(xún)成功"); return userService.list();
            } /**
             * 根據(jù)id刪除
             * @param id
             * @return */
         @GetMapping("/delete"public boolean delete(Integer id){
                System.out.println("刪除成功"); return userService.removeById(id);
            } /**
             *  根據(jù)id查詢(xún)
              * @param id
             * @return */
         @GetMapping("/byid"public Object byid(Integer id){
                System.out.println("查詢(xún)成功"); return userService.getById(id);
            } /**
             *  修改
             * @param user
             * @return */
         @PostMapping("/update"public boolean update(@RequestBody User user){
                System.out.println("修改成功"); return userService.updateById(user);
            } /**
             * 添加
             * @param user
             * @return */
         @PostMapping("/add"public boolean add(@RequestBody User user){
                System.out.println("添加成功"); return userService.save(user);
            }

        }
        3. 微信小程序

        項(xiàng)目結(jié)構(gòu):

        82152f2b38af8939c1f83202bd1c6569.webp

        3.1 初始配置

        0c50968c9346789440a0c37baa41b035.webp

        3.2 bing.wxml



        <view>

          <form bindsubmit='doLogin'>
                    
                    <view class="inputView">

                        <label class="loginLabel">賬號(hào)label>
                        <input name="phone" value='10086' class="inputText" placeholder="請(qǐng)輸入賬號(hào)" />
                    view>
                    <view class="line">view>

                    
                    <view class="inputView">

                        <label class="loginLabel">密碼label>
                        <input name="password" value='123456' class="inputText" password="true" placeholder="請(qǐng)輸入密碼" />
                    view>
                    <view class="line">view>
                    
                    <view class='backColor'>
                        <button class="loginBtn" formType="submit"  open-type='getUserInfo' >登錄button>
                    view>

                    
                form>

        view>

        3.3 bing.js

        ffb1518b059cb637a4a9da692d296348.webp

        3.3 list.wxml



          <button class="add" type='primary' bindtap='addArea'>添加button>
        <view class="container">
          <view class='widget'>
            <text class='column'>編號(hào)text>
            <text class='column'>姓名text>
            <text class='column'>年齡text>
            <text class='link-column'>操作text>
          view>
          <scroll-view scroll-y="true">
            <view>
              <block wx:for='{{list}}'>
              <view class='widget'> 
                <text class='column'>{{item.id}}text>
                <text class='column'>{{item.name}}text>
                 <text class='column'>{{item.age}}text>
                <view class='link-column'>
                  <navigator class='link' url='../operation/operation?id={{item.id}}'>編輯navigator> |
                  <text class='link' bindtap='deleteArea' data-areaid='{{item.id}}' data-areaname='{{item.name}}' data-index='{{index}}'>刪除text>  
                view>
                view>      
              block>
            view>
          scroll-view>

        view>

        3.4 list.js


        // pages/list/list.js
        Page({ /**
           * 頁(yè)面的初始數(shù)據(jù) */
         data: {
            list:[]
          }, /**
           * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 */
         onLoad: function (options{

          }, /**
           * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 */
         onReady: function () {

          }, /**
           * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 */
         onShow: function () var that=this;
            wx.request({
              url'http://localhost:8080/test/list',
              method:'GET',
              data:{},
              success:function(res)var list=res.data; if(list==null){ var toastText='獲取數(shù)據(jù)失敗';
                  wx.showToast({
                    title: toastText,
                    icon:'',
                    duration:2000 //彈出時(shí)間
         })
                }else{
                  that.setData({
                    list:list
                  })
                }
              }
            })
          }, /**
           * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 */
         onHide: function () {

          }, /**
           * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 */
         onUnload: function () {

          }, /**
           * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶(hù)下拉動(dòng)作 */
         onPullDownRefresh: function () {

          }, /**
           * 頁(yè)面上拉觸底事件的處理函數(shù) */
         onReachBottom: function () {

          }, /**
           * 用戶(hù)點(diǎn)擊右上角分享 */
         onShareAppMessage: function () {

          },
          addArea:function(){
            wx.navigateTo({
              url:'../operation/operation' })
          },
          deleteAreafunction (evar that=this;
            wx.showModal({
              title'提示',
              content'確定要?jiǎng)h除[' + e.target.dataset.areaname +']嗎?',
              success:function(sm)if(sm.confirm){
                  wx.request({
                    url'http://localhost:8080/test/delete',
                    data: { id: e.target.dataset.areaid},
                    method:'GET',
                    success:function(res)var result=res.statusCode; var toastText="刪除成功"if(result!=200){
                        toastText = "刪除失敗";
                      }else{
                        that.data.list.splice(e.target.dataset.index,1);
                        that.setData({
                          list:that.data.list
                        });
                      }
                      wx.showToast({
                        title: toastText,
                        icon:'',
                        duration:2000 });
                    }
                  })
                }
              }
            })

          }
        })

        3.5 app.json


        "pages": [ "pages/bind/bind""pages/list/list""pages/logs/logs""pages/operation/operation""pages/index/index" ], "window": { "backgroundColor""#F6F6F6""backgroundTextStyle""light""navigationBarBackgroundColor""#29d""navigationBarTitleText""login""navigationBarTextStyle""black" }, "sitemapLocation""sitemap.json""style""v2" }
        4. 測(cè)試

        啟動(dòng)開(kāi)發(fā)者服務(wù)器,啟動(dòng)SpringBoot的main方法。

        打開(kāi)微信小程序開(kāi)發(fā)者工具

        登錄頁(yè)面

        3eca9cfd8345f49a73a8ff68db6e3568.webp

        首頁(yè)

        11f548b517f5de5651260b01f5f534ef.webp

        添加頁(yè)面

        965f96949b47a8e8872d31364f2f5b93.webp

        修改頁(yè)面

        008bc112c86c38f3f316f790df8be6fa.webp

        刪除

        51ebf9e4f646019042cbbc6e6a995ff0.webp

        到處基本的增刪改查操作已經(jīng)完成了

        如有需要前往 Gitee(碼云)下載

        前臺(tái):https://gitee.com/ckfeng/applet_of_wechat.git

        后臺(tái):https://gitee.com/ckfeng/wx_login.git


        如果有人問(wèn)學(xué)習(xí)數(shù)據(jù)結(jié)構(gòu)和算法有什么書(shū)籍可以推薦,那么《數(shù)據(jù)結(jié)構(gòu)和算法(第二版)》一定必讀不可,這本書(shū)第二版的豆瓣評(píng)分高達(dá) 8.3 ,很經(jīng)典,非常適合假期集中時(shí)間閱讀。

        7822fec9142f76ceaf2ac48eadf58e16.webp

        這本書(shū)在市面上已經(jīng)絕版了,非常經(jīng)典,我這提供了高清電子書(shū)下載:
        獲取方式
        《數(shù)據(jù)結(jié)構(gòu)和算法》第二版高清電子書(shū)已經(jīng)打包好,可以通過(guò)下述步驟來(lái)獲?。?


        掃描下方二維碼回復(fù):數(shù)據(jù)結(jié)構(gòu)

        可獲取下載鏈接

        ???

        
         

        ?長(zhǎng)按上方二維碼 2 秒

        回復(fù)「數(shù)據(jù)結(jié)構(gòu)」即可獲取資料


        點(diǎn)贊是最大的支持 77846c92ea789ddd852f481bf2f56689.webp

        瀏覽 45
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            欧美一级大片 | 亚洲夜夜爽| 秋霞一区| 丰满又黄又爽少妇毛片免费看 | 色www| 91超碰九色成人偷拍 | 欧美跳弹操逼视频 | 欧美性受ⅩXXX猛交XXXXX国产 | 99热18 | 日韩精品一区二区成人 |