自学实前后端践项目2 phone Store 3

1.创建

 下面是后端新建步骤

自学实前后端践项目2 phone Store 3

 自学实前后端践项目2 phone Store 3

 自学实前后端践项目2 phone Store 3

 建好后写入数据库连接代码写到yml文件中

自学实前后端践项目2 phone Store 3

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/phone_store_dmeo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    show-sql: true
    properties:
      hibernate:
        format_sql: true
server:
  port: 8181

2.数据库

链接:https://pan.baidu.com/s/1JQpJks-nSVgE1U0Ac2qKlQ 
提取码:q8dv

3.PhoneCategory持久化

package com.southwind2.phone_store_demo.repository;

import com.southwind2.phone_store_demo.entity.PhoneCategory;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PhoneCategoryRepository extends JpaRepository<PhoneCategory,Integer> {
  public PhoneCategory findByCategoryType(Integer categoryType);
}

4.PhoneInfo持久化

package com.southwind2.phone_store_demo.repository;

import com.southwind2.phone_store_demo.entity.PhoneInfo;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PhoneInfoRepository extends JpaRepository<PhoneInfo,Integer> {
public List<PhoneInfo> findAllByCategoryType(Integer categoryType);
}

5.PhoneSpecs持久化

package com.southwind2.phone_store_demo.repository;

import com.southwind2.phone_store_demo.entity.PhoneSpecs;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PhoneSpecsRepository extends JpaRepository<PhoneSpecs, Integer> {
    public List<PhoneSpecs> findAllByPhoneId(Integer phoneId);
}

6.ByerAddress持久化

package com.southwind2.phone_store_demo.repository;

        import com.southwind2.phone_store_demo.entity.BuyerAddress;
        import org.springframework.data.jpa.repository.JpaRepository;

public interface BuyerAddressRepository extends JpaRepository<BuyerAddress,Integer> {
    public  BuyerAddress  getByAreaCode(Integer areaCode);
}

7.OderMaster持久化

package com.southwind2.phone_store_demo.repository;

import com.southwind2.phone_store_demo.entity.OrderMaster;
import org.springframework.data.jpa.repository.JpaRepository;

public interface OrderMasterRepository extends JpaRepository <OrderMaster,String>{
}

8.创建对应的entity文件夹创建数据库实体的映射类

1)BuyerAddress
package com.southwind2.phone_store_demo.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;

@Data
@Entity
@DynamicInsert
@DynamicUpdate
public class BuyerAddress {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer addressId;
    private String buyerName;
    private String buyerPhone;
    private String buyerAddress;
    private String areaCode;
    private Date createTime;
    private Date updateTime;
    //测试 保存
//    public void setAreaCode(String areaCode) {
//        this.areaCode = areaCode;
//    }
//
//    public String getAreaCode() {
//        return areaCode;
//    }

//    public void setBuyerAddress(String buyerAddress) {
//        this.buyerAddress = buyerAddress;
//    }
//
//    public void setBuyerName(String buyerName) {
//        this.buyerName = buyerName;
//    }
//
//    public String getBuyerName() {
//        return buyerName;
//    }
//
//    public void setBuyerPhone(String buyerPhone) {
//        this.buyerPhone = buyerPhone;
//    }
//
//    public String getBuyerPhone() {
//        return buyerPhone;
//    }
}

2)OrderMaster

@DynamicUpdate
@DynamicInsert
public class OrderMaster {
    @Id
    private String orderId;
    private String buyerName;
    private String buyerPhone;
    private String buyerAddress;
    private Integer phoneId;
    private String phoneName;
    private Integer phoneQuantity;
    private String phoneIcon;
    private Integer specsId;
    private String specsName;
    private BigDecimal specsPrice;
    private BigDecimal orderAmount;
    private Integer payStatus;
    private Date createTime;
    private Date updateTime;

}

3)PhoneCategory

package com.southwind2.phone_store_demo.entity;

import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
public class PhoneCategory {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer categoryId;
    private String categoryName;
    private Integer categoryType;
    private Date createTime;
    private Date updateTime;
}

4)PhoneInfo

package com.southwind2.phone_store_demo.entity;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity

public class PhoneInfo {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer phoneId;
    private String phoneName;
    private BigDecimal phonePrice;
    private String phoneDescription;
    private Integer phoneStock;
    private String phoneIcon;
    private Integer categoryType;
    private String phoneTag;
    private Date createTime;
    private Date updateTime;
}

5)PhoneSpecs

package com.southwind2.phone_store_demo.entity;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity
public class PhoneSpecs {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer specsId;
    private Integer phoneId;
    private String specsName;
    private Integer specsStock;
    private BigDecimal specsPrice;
    private String specsIcon;
    private  String specsPreview;
    private Date createTime;
    private Date updateTime;
}
上一篇:Python-正则


下一篇:Neo私钥到地址