Springboot +JPA+thymeleaf+MySQL设计一个数据驱动的管理系统

本文介绍了如何设计并实现一个数据驱动的笔记本电脑管理系统,包括设备的添加、删除、更新和查询功能,以及分页和排序。系统使用Lombok、Mysql、Thymeleaf和JPA等技术栈,涉及业务类、数据访问层、业务逻辑层和服务实现层的详细编码示例。
摘要由CSDN通过智能技术生成

目录

要求:设计并完成一个数据驱动的管理系统。例如设备管理系统,或其他自己感兴趣的管理系统。

功能实现:

背景:设计一个笔记本电脑管理系统,供用户方便查看并管理笔记本电脑

文件准备:

 开始写入:

业务类(Laptops):

数据访问层(Repository):

业务逻辑层(Service):

Impl:

控制层(Controller):

HTML部分:主页面以及新增和更新部分页面设置

主页面(index):

新增页面(NewLaptops):

更新页面(UpdateLaptops):

最终效果如下:

 样式设置:

相关源码我放在gitee内:https://gitee.com/sutiao77/Laptops_system.git

总结:

JAVA的学习可以说让我们正式认识了JAVA这门语言的魅力,从最初几行代码变为现如今的几十行到几百行,一点点的学习一点点的进步,漫长的过程也让我们对知识更深刻的记忆。


要求:设计并完成一个数据驱动的管理系统。例如设备管理系统,或其他自己感兴趣的管理系统。

功能实现:

1.设备:属性至少3个以上,包括并不限于设备类型、设备名称、初始状态……

2.添加设备

3.删除设备

4.更新设备

5.查找设备(自定义查询依据),显示查询结果。

6.分页

7.排序

背景:设计一个笔记本电脑管理系统,供用户方便查看并管理笔记本电脑

文件准备:

项目依赖:Lombok+Mysql+thmyeleaf+JPA+Spring Web

业务类(Laptops):属性,如品牌、型号、价格等等

数据访问层(Repository):负责与数据库进行交互,包括插入、更新、删除和查询信息的方法。

业务逻辑层(Service):处理业务逻辑,对信息的验证。

控制层(Controller):接收用户的请求,调用相应的服务方法,并返回处理结果。

HTML部分:主页面以及新增和更新部分页面设置

主页面(index)、新增页面(NewLaptops)、更新页面(UpdateLaptops)

 开始写入:

业务类(Laptops):

package com.example.laptops_system.model;

import jakarta.persistence.*;
import lombok.Data;

@Data
@Entity
@Table(name = "genie")
public class Laptops {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "brand")
    private String brand;

    @Column(name = "model")
    private String model;

    @Column(name = "price")
    private String price;

    @Column(name = "monthly_sales")
    private String monthly_sales;

    @Column(name = "recommend")
    private String recommend;

}

数据访问层(Repository):

package com.example.laptops_system.repository;

import com.example.laptops_system.model.Laptops;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface LaptopsRepository extends JpaRepository<Laptops, Long> {
    @Query("select s from Laptops s where s.brand like %:brand%")
    List<Laptops> findAllByGenieName(@Param("brand") String brand);
}

业务逻辑层(Service):

package com.example.laptops_system.service;

import com.example.laptops_system.model.Laptops;
import org.springframework.data.domain.Page;

import java.util.List;

public interface LaptopsService {
    List<Laptops> getAllStaff();
    // 新增/更新一个信息
    void saveGenie(Laptops laptops);
    // 根据品牌名字去查询
    List<Laptops>findByGeniesName(String brand);
    //删除信息
    void deleteGenieById(long id);
    //分页
    Page<Laptops> findPaginated(int pageNo, int pageSize, String sortField, String sortDirection);
    //获取指定ID的笔记本
    Laptops getGenieById(long id);
}

Impl:

package com.example.laptops_system.service;

import com.example.laptops_system.model.Laptops;
import com.example.laptops_system.repository.LaptopsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class LaptopsServiceImpl implements LaptopsService {
    @Autowired
    private LaptopsRepository laptopsRepository;
    @Override
    public List<Laptops> getAllStaff() {
        return laptopsRepository.findAll();
    }
    @Override
    public void saveG
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值