First Assignment 832202201 Qinye Ding 丁钦烨

832202201丁钦烨 2024-10-31 19:04:02

 

目录

1 Assignment

1.1 Basic Functions

1.3 Documentation and Submission

2 PSP Table

3 Presentation of the Finished Product

4 Design and Implementation Process

4.1 Requirements Analysis

4.2 Architectural Design:

4.3 Project Implementation Process

5 Code Description

5.1 Front-end code

5.1.1 System home page

5.1.2 TypeScript scripting section

5.1.3 Style

5.2 back-end code

6 Personal Journey and Learnings


Course for this AssignmentEE308
Where are the requirement for this assigmentFirst assignment-- front-end and back-end separation contacts programming
Name and student ID丁钦烨(Qinye Ding) 832202201
The objective of this assignment1. Front-end and Back-end Separation;2. Deployment and Functionality;3. Code Quality and Documentation
Front-end repository on GitHubhttps://github.com/A-Piao-ovo/-
Back-end repository on GitHubhttps://github.com/A-Piao-ovo/houduan
  •  
  • 1 Assignment

  • For this assignment, students are required to create a contact list using a front-end and back-end separation technology and meet the following basic requirements.

    1.1 Basic Functions

    1.1.1 Add:
    Users can add new contact information through certain interactions.
    1.1.2 Modify:
    Users can modify existing contact information through certain interactions.
    1.1.3 Delete:
    Users can delete existing contact information through certain interactions

  • 1.3 Documentation and Submission

    Students are required to document their coding standards, development process, and project structure. The assignment must be submitted via GitHub, with separate repositories for the front end and back end, and a blog post detailing the assignment, development journey, and code explanations.

  • 2 PSP Table

ActivityCommentsEstimated TimeActual Time
planningOverall plan of this project1h1h
Preparation(learning)download IDEA, Vue etc4h4h
Demand AnalysisDetermine the requirements of the project and the functions that can be achieved1h1.5h
Architecture DesignDesign a frontend-backend separated architecture with Vue for the frontend and Spring Boot for the backend1h1h
API DesignCreate excuses for the front and back ends, and correlate the front and back end designs10h11h
Database DesignCreate the required classes and bind the back end to the database15h20h
TestTest whether the project meets expectations1h1.5
ModifyCorrect errors and optimize code4h6h
Total 37h46h

3 Presentation of the Finished Product

 

4 Design and Implementation Process

4.1 Requirements Analysis

Functional Requirements: Implement the functions of adding, search, editing, and deleting contact information.
User Interface: The interface should be user-friendly, easy to operate, and compatible with mainstream browsers.
Tools Selection
Frontend: Use the Vue framework to build the user interface.
Backend: Utilize the Spring Boot and Maven framework.
Database: Choose MySQL to store contact data, use Navicat to visualize management data, ensuring data persistence and efficient querying.

4.2 Architectural Design:

Frontend Architecture: Develop using a component-based approach, leveraging the Element UI components to aid in development.
Backend Architecture: Study and implement backend code for CRUD (Create, Read, Update, Delete) operations.
Database Design: Design a reasonable table structure, including a contacts table (with fields such as ID, name, and phone number), and consider indexing to optimize search performance.

4.3 Project Implementation Process

·Environment setup and configuration:
Download Node.js  to set up the Vue front-end environment, and download npm to get the front-end up and running.
Download IDEA and build the Spring Boot framework into it.
Download Mysql and Navicat to prepare for the subsequent database setup

·Frontend Development:
Design and create user interfaces and design user interaction logic.
Set the callback function to the back end and display the back end data.

·Backend Development:
Receive front-end requirements, access database data and return data to the front-end

·Database Design and Implementation:
Design the database table structure based on requirements analysis, create and initialize the database.
Write code to handle cross-origin resource sharing (CORS) and implement CRUD operations for data.
Optimize database performance, such as by adding indexes and using transactions.

·Testing and Debugging:
Test that the code is running correctly, and optimize the code

5 Code Description

5.1 Front-end code

5.1.1 System home page

<template>
  <div class="container">
    <h1>联系人管理</h1>
    <div class="button-container">
      <button @click="showAddModal">添加联系人</button>
    </div>
    <table>
      <thead>
      <tr>
        <th>姓名</th>
        <th>电话</th>
        <th>年龄</th>
        <th>性别</th>
        <th>地址</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="contact in contacts" :key="contact.id">
        <td>{{ contact.name }}</td>
        <td>{{ contact.phone }}</td>
        <td>{{ contact.age }}</td>
        <td>{{ contact.gender }}</td>
        <td>{{ contact.address }}</td>
        <td>
          <button @click="editContact(contact)">修改</button>
          <button @click="deleteContact(contact.id)">删除</button>
        </td>
      </tr>
      </tbody>
    </table>
    <modal v-if="showModal" @close="closeModal">
      <template #header>
        <h2>{{ editMode ? '修改联系人' : '添加联系人' }}</h2>
      </template>
      <template #body>
        <div>
          <label>姓名:</label>
          <input v-model="currentContact.name" />
          <label>电话:</label>
          <input v-model="currentContact.phone" />
          <label>年龄:</label>
          <input type="number" v-model="currentContact.age" />
          <label>性别:</label>
          <input v-model="currentContact.gender" />
          <label>地址:</label>
          <input v-model="currentContact.address" />
        </div>
      </template>
      <template #footer>
        <div class="button-group">
          <button @click="saveContact">确认</button>
          <button @click="closeModal">取消</button>
        </div>
      </template>
    </modal>
  </div>
</template>

5.1.2 TypeScript scripting section

<script>
import axios from 'axios';
import Modal from './AppModal.vue';

export default {
  components: { Modal },
  data() {
    return {
      contacts: [],
      currentContact: { name: '', phone: '', age: null, gender: '', address: '' },
      showModal: false,
      editMode: false,
    };
  },
  methods: {
    fetchContacts() {
      axios.get('/api/contacts').then(response => {
        this.contacts = response.data;
      });
    },
    showAddModal() {
      this.currentContact = { name: '', phone: '', age: null, gender: '', address: '' };
      this.editMode = false;
      this.showModal = true;
    },
    editContact(contact) {
      this.currentContact = { ...contact };
      this.editMode = true;
      this.showModal = true;
    },
    deleteContact(id) {
      axios.delete(`/api/contacts/${id}`).then(() => {
        this.fetchContacts();
      });
    },
    saveContact() {
      const method = this.editMode ? 'put' : 'post';
      const url = this.editMode ? '/api/contacts' : '/api/contacts';

      axios[method](url, this.currentContact).then(() => {
        this.closeModal();
        this.fetchContacts();
      });
    },
    closeModal() {
      this.showModal = false;
    }
  },
  mounted() {
    this.fetchContacts();
  }
};
</script>

5.1.3 Style

<style scoped>
/* 页面主样式 */
h1 {
  text-align: center;
  font-size: 2rem;
  margin: 20px 0;
  color: #333;
}

/* 表格容器 */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* 表格样式 */
table {
  width: 50vw; /* 设置表格宽度为视口宽度的一半 */
  margin: 20px auto; /* 表格水平居中 */
  border-collapse: collapse;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

th, td {
  padding: 12px;
  border: 1px solid #ccc;
  text-align: center;
  word-wrap: break-word;
  white-space: nowrap; /* 防止内容换行 */
  overflow: hidden; /* 隐藏溢出文本 */
  text-overflow: ellipsis; /* 使用省略号表示溢出文本 */
}

th {
  background-color: #f2f2f2;
  font-weight: bold;
}

tbody tr:hover {
  background-color: #f5f5f5;
}

/* 媒体查询 */
@media (max-width: 768px) {
  table {
    display: block; /* 在小屏幕上使用块布局 */
    overflow-x: auto; /* 超出部分水平滚动 */
    white-space: nowrap; /* 避免单元格内容换行 */
  }

  th, td {
    display: block; /* 每个单元格为块元素 */
    text-align: right; /* 文字右对齐 */
  }

  th {
    text-align: left; /* 表头文字左对齐 */
  }

  tbody tr {
    margin-bottom: 10px; /* 行间距 */
    border: none; /* 移除行的边框 */
  }
}


/* 按钮容器样式 */
.button-container {
  display: flex; /* 使用 Flexbox 排列按钮 */
  justify-content: center; /* 水平居中 */
  margin-bottom: 20px; /* 下方外边距 */
}

/* 按钮组样式 */
.button-group {
  display: flex; /* 使用 Flexbox 布局 */
  justify-content: center; /* 水平居中 */
  gap: 10px; /* 按钮之间的间距 */
  flex-wrap: nowrap; /* 防止换行 */
  max-width: 100%; /* 最大宽度限制 */
}

/* 按钮样式 */
button {
  padding: 10px 15px; /* 内边距 */
  background-color: #007bff; /* 按钮背景颜色 */
  color: white; /* 按钮字体颜色 */
  border: none; /* 去掉边框 */
  border-radius: 5px; /* 圆角 */
  cursor: pointer; /* 鼠标悬停时的指针样式 */
  transition: background-color 0.3s; /* 背景颜色过渡 */
  margin: 0 5px; /* 按钮间距 */
  font-size: 1rem; /* 字体大小 */
}

button:hover {
  background-color: #0056b3; /* 鼠标悬停时背景颜色变化 */
}



/* 输入框样式 */
input {
  width: 100%; /* 输入框宽度 */
  padding: 10px; /* 内边距 */
  margin: 10px 0; /* 上下外边距 */
  border: 1px solid #ccc; /* 边框 */
  border-radius: 5px; /* 圆角 */
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1); /* 内部阴影 */
}

input:focus {
  border-color: #007bff; /* 聚焦时边框颜色 */
  outline: none; /* 去掉默认聚焦轮廓 */
}

.button-group {
  display: flex; /* 使用 flexbox 布局 */
  justify-content: center; /* 水平居中 */
  gap: 10px; /* 按钮之间的间距 */
}

button {
  padding: 10px 20px; /* 增加按钮内边距 */
  border: none; /* 去掉边框 */
  border-radius: 5px; /* 圆角 */
  background-color: #007bff; /* 按钮背景色 */
  color: white; /* 文字颜色 */
  cursor: pointer; /* 鼠标指针效果 */
  transition: background-color 0.3s; /* 背景色过渡效果 */
}

button:hover {
  background-color: #0056b3; /* 鼠标悬停时背景色 */
}

</style>

5.2 back-end code

import com.example.demo.entity.Contact;
import com.example.demo.service.ContactService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/contacts")
public class ContactController {

    @Resource
    private ContactService contactService;

    @GetMapping
    public List<Contact> getAllContacts() {
        return contactService.getAllContacts();
    }

    @GetMapping("/{id}")
    public Contact getContact(@PathVariable Integer id) {
        return contactService.getContactById(id);
    }

    @PostMapping
    public void addContact(@RequestBody Contact contact) {
        contact.setId(null); // 确保不传入 id
        contactService.addContact(contact);
    }

    @PutMapping
    public void updateContact(@RequestBody Contact contact) {
        contactService.updateContact(contact);
    }

    @DeleteMapping("/{id}")
    public void deleteContact(@PathVariable Integer id) {
        contactService.deleteContact(id);
    }
}

 

 

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

@Data
@TableName("contacts")
public class Contact {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String name;
    private String phone;
    private Integer age; 
    private String gender;
    private String address;
}

6 Personal Journey and Learnings

Through this project of separating the front and back ends, I have a deep understanding of the operation law of the front and back ends of the web page, can make some web pages, and know the underlying law of the back end. 

...全文
117 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:LTK8319是一款单通道H桥有刷直流电机驱动器,工作电压范围为2.5V至12V,支持最高3.9A的峰值电流和2.5A的平均电流驱动能力,适用于小家电、玩具、电子锁、机器人等小型电动设备。该芯片通过两个逻辑输入(INA和INB)控制电机的正转、反转、停止与刹车,并支持PWM调速控制。集成欠压锁定(UVLO)、过温保护(TSD)及自动故障恢复功能,确保系统安全可靠运行。当INA和INB持续为低电平时,芯片进入低功耗休眠模式,显著降低静态功耗。采用ESOP-8封装,符合环保无铅标准。; 适合人群:电子工程师、嵌入式系统开发者、电机控制技术人员,以及从事小型机电产品研发的设计人员;具备基本电路知识和电机控制经验者更佳。; 使用场景及目标:①用于驱动小型有刷直流电机或步进电机的一个绕组,实现精确的方向与速度控制;②适用于电池供电设备中对功耗敏感的应用,利用休眠模式延长续航时间;③在电机启停频繁、负载波动大的场合,发挥其电流控制与保护机制优势,提升系统稳定性。; 阅读建议:此文档提供了详细的电气特性、功能逻辑表、保护机制与时序参数,建议结合典型应用电路进行硬件设计,并重点关注电源去耦电容选型、散热布局及PWM频率设置(不超过100kHz),以确保系统可靠运行。
内容概要:本文研究了一种基于遗传算法(GA)与粒子群优化算法(PSO)融合的无人机三维路径规划方法,旨在解决复杂环境中无人机避障与路径优化的问题。通过构建三维空间环境模型,提出一种结合GA全局搜索能力强与PSO收敛速度快优势的混合优化策略,并利用Matlab平台完成算法仿真与路径可视化。研究不仅实现了无人机在存在多个障碍物场景下的安全、高效飞行路径规划,还对GA与PSO两种算法在路径长度、计算耗时、收敛稳定性等方面进行了对比分析,评估其性能差异,为实际应用中算法选型提供依据。; 适合人群:具备一定算法设计基础和Matlab编程能力的科研人员、自动化与人工智能方向的研究生,以及从事无人机导航、智能控制等相关领域的工程技术人员。; 使用场景及目标:①应用于城市密集建筑区、山地森林等复杂地形中的无人机自主巡检与应急救援任务;②为智能交通、地理测绘、灾害监测等需要自主路径决策的无人系统提供算法支持与仿真验证;③通过对比不同智能优化算法的表现,辅助研究人员在特定应用场景下选择最优路径规划方案。; 阅读建议:建议读者结合提供的Matlab代码进行仿真实验,调整种群规模、迭代次数、障碍物分布等参数,深入理解算法运行机制与性能表现,并可进一步拓展至动态环境更新、多无人机协同避障等更复杂的研究方向。

173

社区成员

发帖
与我相关
我的任务
社区描述
2401_MU_SE_FZU
软件工程 高校
社区管理员
  • FZU_SE_TeacherL
  • 助教-吴可仪
  • 助教-孔志豪
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧