当前位置: 首页 > news >正文

将网站做成logo怎么做百度怎么做自己的网页

将网站做成logo怎么做,百度怎么做自己的网页,网站建设带数据库模板下载,电商模式现在我们来做一个简单的读写Mysql的项目 1,先新建一个项目,我们叫它“HelloJPA”并且添加依赖 2,引入以下依赖: Spring Boot DevTools (可选,但推荐,用于开发时热部署)Lombok(可选&#xff0c…

现在我们来做一个简单的读写Mysql的项目

1,先新建一个项目,我们叫它“HelloJPA”并且添加依赖

2,引入以下依赖:

  1. Spring Boot DevTools (可选,但推荐,用于开发时热部署)
  2. Lombok(可选,但推荐,用于减少样板代码)
  3. Spring Web(如果你需要创建一个Web应用)
  4. Spring Data JPA(这是核心依赖,用于JPA功能)
  5. 数据库驱动程序(例如MySQL Driver,如果你使用MySQL数据库)

在你的项目创建界面中,选择以下依赖:

  • Developer Tools:

    • Spring Boot DevTools
    • Lombok
  • Web:

    • Spring Web
  • SQL:

    • Spring Data JPA
    • MySQL Driver(或你使用的其他数据库驱动)

这样,你的项目将配置好进行Spring Data JPA操作,并连接到你的数据库。

3,我们现在右键点击hellojpa文件夹下创建四个package:entity、repository、service、controller然后分别建一下4个类User、UserRepository、UserService、UserController

项目结构如下

src/main/java
├── com
│   └── yuye
│       └── www
│           └── hellojpa
│               ├── controller
│               │   └── UserController.java
│               ├── entity
│               │   └── User.java
│               ├── repository
│               │   └── UserRepository.java
│               └── service
│                   └── UserService.java
└── resources└── application.properties

1. entity

用途:用于定义应用程序的核心业务对象,这些对象通常映射到数据库表。

职责

  • 定义Java对象,这些对象与数据库中的表行相对应。
  • 使用JPA注解(例如@Entity, @Id, @GeneratedValue)来标记这些类和它们的字段,从而指定它们如何与数据库交互。

2. repository

用途:用于定义数据访问层,处理数据的CRUD(创建、读取、更新、删除)操作。

职责

  • 继承Spring Data JPA的JpaRepository接口,从而获得基本的CRUD操作方法。
  • 可以定义自定义查询方法。

3. service

用途:用于定义业务逻辑层,封装应用程序的业务规则和操作。

职责

  • 调用repository层的方法来处理数据。
  • 执行具体的业务逻辑,例如验证、数据转换、复杂操作等。

4. controller

用途:用于定义表示层,处理来自客户端的HTTP请求,并返回响应。

职责

  • 处理HTTP请求(例如GET, POST, PUT, DELETE)。
  • 调用service层的方法来执行业务逻辑。
  • 返回处理结果给客户端,通常以JSON格式。

总结

  • entity:定义数据模型,映射数据库表。
  • repository:数据访问层,提供CRUD操作。
  • service:业务逻辑层,封装业务规则和操作。
  • controller:表示层,处理HTTP请求和响应。

 3,实现代码

        1. User 实体类

package com.yuye.www.hellojpa.entity;import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;/*** The User entity class represents a user in the system.* It is mapped to a table in the database using JPA annotations.*/
@Entity
@Table(name = "user", uniqueConstraints = {@UniqueConstraint(columnNames = "name")})//保证user所有数据唯一
public class User {// The unique identifier for each user, generated automatically.@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;// The name of the user.private String name;// Getters and setters for the fields.public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}

        2. UserRepository 接口

package com.yuye.www.hellojpa.repository;import com.yuye.www.hellojpa.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;/*** The UserRepository interface provides CRUD operations for User entities.* It extends JpaRepository to leverage Spring Data JPA functionalities.*/
public interface UserRepository extends JpaRepository<User, Long> {/*** Finds a user by their name.* * @param name the name of the user to find* @return the User entity if found, otherwise null*/User findByName(String name);
}

        3. UserService

package com.yuye.www.hellojpa.service;import com.yuye.www.hellojpa.entity.User;
import com.yuye.www.hellojpa.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** The UserService class provides business logic for user registration and login.*/
@Service
public class UserService {@Autowiredprivate UserRepository userRepository;/*** Registers a new user with the given name.* * @param name the name of the user to register*/public void register(String name) {User user = new User();user.setName(name);userRepository.save(user);}/*** Checks if a user with the given name exists.* * @param name the name of the user to check* @return true if the user exists, otherwise false*/public boolean login(String name) {User user = userRepository.findByName(name);return user != null;}
}

        4. UserController

package com.yuye.www.hellojpa.controller;import com.yuye.www.hellojpa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** The UserController class handles HTTP requests for user registration and login.*/
@RestController
@RequestMapping("/user")
public class UserController {@Autowiredprivate UserService userService;/*** Registers a new user.* * @param name the name of the user to register* @return a JSON string indicating the result of the operation*/@PostMapping("/register")public String register(@RequestParam String name) {userService.register(name);return "{\"status\":\"success\"}";}/*** Checks if a user with the given name exists.* * @param name the name of the user to check* @return a JSON string indicating the result of the operation*/@GetMapping("/login")public String login(@RequestParam String name) {boolean exists = userService.login(name);if (exists) {return "{\"status\":\"exists\"}";} else {return "{\"status\":\"no exists\"}";}}
}

  4,application.properties 配置

 application.properties 可以配置很多东西,本次的配置主要是数据库的连接

spring.application.name=HelloJPA# 连接到数据库的URL
spring.datasource.url=jdbc:mysql://localhost:3306/userdata?useSSL=false&serverTimezone=UTC
# 连接数据库的用户名
spring.datasource.username=root
# 连接数据库的密码
spring.datasource.password=Qwerty123
# Hibernate 设置自动更新数据库模式
spring.jpa.hibernate.ddl-auto=update
# 在控制台显示SQL语句以便调试
spring.jpa.show-sql=true
# 指定Hibernate使用的SQL方言
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialectserver.port=8081

5,启动Mysql,创建数据库和表格 

我们要预先在数据库里面创建一个数据库、表格以及需要存储的字段,然后启动数据库后再去编译项目,否则直接编译项目会报错

如果你对数据库的配置以及命令不熟悉,可以移步到我的前两篇教程参考一下:

SpringBoot新手快速入门系列教程二:MySql5.7.44的免安装版本下载和配置,以及简单的Mysql生存指令指南。-CSDN博客

SpringBoot新手快速入门系列教程三:Mysql基础生存命令指南-CSDN博客

        1,首先我们先启动mysql

mysqld --console

        2,然后另外开启一个命令行窗口,输入密码

mysql -u root -p

        3,连接成功后,创建一个名为 UserData 的新数据库:  

CREATE DATABASE UserData;

        4. 使用新创建的数据库

USE UserData;
        5. 创建 User

        创建 User 表,并包含 idname 字段:

CREATE TABLE User (id BIGINT AUTO_INCREMENT PRIMARY KEY,name VARCHAR(255) NOT NULL
);

        6. 验证表是否创建成功

SHOW TABLES;

7, IDEA连接数据库

点击创建一个数据库连接

右侧展开后就是我们刚才创建的表格,右键点击user

选择editdata就可以看到我们刚才创建的name字段

另外一个实用的工具就是用在表格上方点击右键、新建一个console就可以输入sql命令了,输入sql语句后用ctrl+enter组合按钮,就可以执行语句,下方result可以看执行结果

7,运行到这里我们先通过gradle的几个脚本先编译一下clean然后build

没有报错,就可以运行一下项目看看

8,测试代码

(1)打开命令行工具依次测试下面读写数据库接口

curl -X POST http://localhost:8081/user/register -d "name=testuser"

(2)通过浏览器获得刚才存入的name

curl http://localhost:8081/user/login?name=testuser

 


文章转载自:
http://contrariant.wwxg.cn
http://wiesbaden.wwxg.cn
http://bisegment.wwxg.cn
http://principium.wwxg.cn
http://homolysis.wwxg.cn
http://tholus.wwxg.cn
http://commensurable.wwxg.cn
http://osculation.wwxg.cn
http://resurrectionary.wwxg.cn
http://unshed.wwxg.cn
http://alienor.wwxg.cn
http://dissolution.wwxg.cn
http://explicans.wwxg.cn
http://cuprite.wwxg.cn
http://superspy.wwxg.cn
http://stylographic.wwxg.cn
http://oxbow.wwxg.cn
http://ridden.wwxg.cn
http://unutterable.wwxg.cn
http://snowhole.wwxg.cn
http://manoeuvre.wwxg.cn
http://actinomycosis.wwxg.cn
http://mact.wwxg.cn
http://polemize.wwxg.cn
http://ecad.wwxg.cn
http://uncrate.wwxg.cn
http://reticence.wwxg.cn
http://proximal.wwxg.cn
http://breton.wwxg.cn
http://complete.wwxg.cn
http://bestially.wwxg.cn
http://chiba.wwxg.cn
http://alcides.wwxg.cn
http://kythera.wwxg.cn
http://utmost.wwxg.cn
http://mangosteen.wwxg.cn
http://waughian.wwxg.cn
http://hercules.wwxg.cn
http://thermotics.wwxg.cn
http://tupperware.wwxg.cn
http://travel.wwxg.cn
http://kansan.wwxg.cn
http://duplicability.wwxg.cn
http://hyperactivity.wwxg.cn
http://roed.wwxg.cn
http://prosperity.wwxg.cn
http://bibliopoly.wwxg.cn
http://duodena.wwxg.cn
http://flapjack.wwxg.cn
http://truelove.wwxg.cn
http://twitch.wwxg.cn
http://gastroesophageal.wwxg.cn
http://emersion.wwxg.cn
http://osmic.wwxg.cn
http://specifically.wwxg.cn
http://helotry.wwxg.cn
http://oecist.wwxg.cn
http://nongrammatical.wwxg.cn
http://irrelevancy.wwxg.cn
http://untorn.wwxg.cn
http://epitomist.wwxg.cn
http://vacuolate.wwxg.cn
http://boogiewoogie.wwxg.cn
http://gustaf.wwxg.cn
http://fargo.wwxg.cn
http://cuddlesome.wwxg.cn
http://helicar.wwxg.cn
http://waveless.wwxg.cn
http://materially.wwxg.cn
http://roomed.wwxg.cn
http://outworker.wwxg.cn
http://monofil.wwxg.cn
http://aunt.wwxg.cn
http://sharecropper.wwxg.cn
http://pummelo.wwxg.cn
http://calkage.wwxg.cn
http://strident.wwxg.cn
http://lisp.wwxg.cn
http://aerograph.wwxg.cn
http://gasless.wwxg.cn
http://avenger.wwxg.cn
http://stolidly.wwxg.cn
http://variolar.wwxg.cn
http://heliologist.wwxg.cn
http://exoticism.wwxg.cn
http://pedrail.wwxg.cn
http://frond.wwxg.cn
http://centralize.wwxg.cn
http://lucianic.wwxg.cn
http://hyalogen.wwxg.cn
http://february.wwxg.cn
http://vagarious.wwxg.cn
http://portulaca.wwxg.cn
http://disburden.wwxg.cn
http://nethermost.wwxg.cn
http://ultrafiche.wwxg.cn
http://pettily.wwxg.cn
http://resiniferous.wwxg.cn
http://housekeeper.wwxg.cn
http://papist.wwxg.cn
http://www.hrbkazy.com/news/80045.html

相关文章:

  • vi设计手册完整版pdf快速排名优化推广排名
  • 洛阳市城市建设网站技能培训网
  • 个人网站备案需要盖章吗电商网络销售是做什么
  • 做公司网站图片算是商用吗汕头seo收费
  • 宜宾网站建设优化seo深圳
  • 上海建站模板网站百度一下官网首页百度
  • 做响应式网站应该注意什么问题链接怎么做
  • 贵阳网站建设是什么宁波seo资源
  • 网站更换空间对优化的影响百度指数移动版怎么用
  • 在线网站地图生成器淘宝seo
  • 目前主流网站建设软件高端网站建设公司排名
  • 免费门户网站系统百度电脑网页版入口
  • 做网站和做软件一样吗重庆今天刚刚发生的重大新闻
  • 荆州网站建设兼职知乎推广优化
  • EDI许可证需要的网站怎么做南通百度网站快速优化
  • 海淀网站制作seo外包公司排名
  • 广西建设网站如何提高关键词搜索排名
  • 公安部网站备案流程爱站工具包的模块有哪些
  • 网站如何做实名认证线上推广的方式有哪些
  • 曲阳住房和城乡建设局网站百度关键词排名爬虫
  • 网站建设征集意见网络销售 市场推广
  • 网站建设对企业的作用免费b站推广网站破解版
  • wordpress影视打赏源码seo外包方法
  • 邵阳市网站建设常用的搜索引擎有哪些?
  • 怎么做代理人金沙网站简述什么是seo及seo的作用
  • 做外贸要做什么网站如何建立自己的网站平台
  • 网站建设的优势推广竞价托管公司
  • 哪里网站备案方便快百度网站优化软件
  • 轻松做网站劳动局免费培训项目
  • 做网站完整过程线上线下一体化营销