day08 前后端分离开发(lanmoyun)

2019-03-15  本文已影响0人  黑桃_06ea

1.后端:

day08-2.png
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.version>5.1.5.RELEASE</spring.version>
    <aspectj.version>1.9.2</aspectj.version>
    <junit.version>4.12</junit.version>
    <log4j.version>1.2.17</log4j.version>
    <slf4j.version>1.7.12</slf4j.version>
    <hutool.version>4.5.1</hutool.version>
    <mysql.version>5.1.47</mysql.version>
    <mybatis.version>3.5.0</mybatis.version>
    <mybatis-spring.version>2.0.0</mybatis-spring.version>
    <tk-mybatis.version>4.1.5</tk-mybatis.version>
    <druid.version>1.1.14</druid.version>
    <lombok.version>1.18.6</lombok.version>
    <jackson.version>2.9.8</jackson.version>
    <jackson-mapper.version>1.9.13</jackson-mapper.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!--spring-context依赖-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>${aspectj.version}</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${aspectj.version}</version>
    </dependency>
    <!--spring-test依赖-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!--junit依赖-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <!-- log4j日志依赖 -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-all</artifactId>
      <version>${hutool.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>core</artifactId>
      <version>3.3.3</version>
    </dependency>
    <!--spring-jdbc依赖 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>${mybatis-spring.version}</version>
    </dependency>
    <dependency>
      <groupId>tk.mybatis</groupId>
      <artifactId>mapper</artifactId>
      <version>${tk-mybatis.version}</version>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>${druid.version}</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>${lombok.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>${jackson-mapper.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
    </dependency>
  </dependencies>

2.前端:

<html>
    <head>
        <meta charset="utf-8" />
        <title>Vue.js-访问API接口数据-蓝墨云班课练习</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <!-- 通过CDN引入Vue.js -->
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <!-- 通过CDN引入axios -->
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
        <style type="text/css">
            body {
                background-color: #eee;
            }
            .top {
                width: 80%;
                margin: 0 auto;
                display: flex;
                justify-content: space-between;
            }
            .bottom{
                width: 80%;
                margin: 0 auto;
                display: flex;
                justify-content: space-between;
            }
            hr{
                width: 80%;
                color: #efefef;
            }
            .container {
                width: 80%;
                margin: 0 auto;
                display: flex;
                flex-wrap: wrap;
                padding-left: 20px;
                padding-top: 10px;
            }
            .card {
                width: 190px;
                display: flex;
                flex-direction: column;
                border: 1px solid #eee;
                margin-right: 20px;
                margin-bottom: 10px;
                background-color: #fff;
                justify-content: center;
                padding-left: 5px;
                padding-right: 5px;
                padding-top: 5px;
            }
            .card img {
                width: 100%;
            }
            p {
                font-size: 12px;
                margin-bottom: 5px;
            }
            .teacher {
                display: flex;
                justify-content: space-between;
            }
            .left {
                display: flex;
            }
            .avatar img {
                width: 30px;
                height: 30px;
                border-radius: 50%;
                margin-right: 5px;
            }
            .code {
                color: #00BBDD;
                margin-top: 5px;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <div class="top">
                <p>进行中的班课</p>
                <p>{{courses.length}}个进行中的班课</p>
            </div>
            <hr>
            <div class="container">
                <div class="card" v-for="(course, index) in courses" :key="index">
                    <div class="cover">
                        <img :src="'img/'+course.cover">
                    </div>
                    <div class="course-class">
                        <p>{{course.courseClass}}</p>
                    </div>
                    <div class="course-name">
                        <p>{{course.courseName}}</p>
                    </div>
                    <div class="teacher">
                        <div class="left">
                            <div class="avatar">
                                <img :src="'img/'+course.avatar">
                            </div>
                            <div class="username">
                                <p class="code">{{course.username}}</p>
                            </div>
                        </div>
                        <div class="course-code">
                            <p class="code" v-if="loginUserId === course.userId">{{course.courseCode}}</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- <div class="bottom">
                <p>已结束的班课</p>
            </div>
            <hr> -->
            
        </div>
        <script type="text/javascript">
            var app = new Vue({
                el: '#app',
                data: {
                    loginUserId: 1,
                    courses: []
                },
                created: function() {
                    var _this = this;
                    axios.get('http://127.0.0.1:8080/web/courses')
                        .then(function(response) {
                            console.log(response.data);
                            _this.courses = response.data;
                        })
                }
            })
        </script>
    </body>
</html>

效果图:


day08-5.png
上一篇下一篇

猜你喜欢

热点阅读