谷粒商场篇】第一天


中国加油,武汉加油!

1. 简介

模式含义代表
B2CBusiness To Consumer 商对客天猫,京东
C2CConsumer To Consumer 个人与个人之间的电子商务淘宝
P2PPeer To Peer人人贷
P2CProduction To Consumer餐饮,家政服务,健康,医疗

2. 相关技术

Spring,SpringBoot,Dubbo,Maven,git,MySql,MyBatis,Redis,kibana,fastdfs(轻量级分布式文件系统),ActiveMQ,支付宝,nginx,apache服务器,SSO(Single Sign On),Docker+kubernetes,idea

3. IDEA简单配置

  1. 配置maven仓库
  2. 配置JDK
  3. 码云或者github创建仓库
  4. new — Project from Version Control在这里插入图片描述

4. 数据库软件和脚本文件

  1. 软件: Navicat
  2. 脚本文件:点击下载

5. 新建一个user项目

  1. 新建module,选择springboot,springweb,mysql驱动,jdbc,mybatis,lombox依赖
  2. 写controller,service
  3. 写bean的映射类,映射数据库表ums_user_member表
  4. 写功能
    在这里插入图片描述
  5. 导通用Mapper依赖
    <!-- 通用mapper -->
    <dependency>
    	<groupId>tk.mybatis</groupId>
    	<artifactId>mapper-spring-boot-starter</artifactId>
    	<version>2.1.5</version>
    	<exclusions>
    		<exclusion>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-jdbc</artifactId>
    		</exclusion>
    	</exclusions>
    </dependency>
    

5.1 application.properties

# 项目配置
server.port=8080

# jdbc配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/gmall
spring.datasource.username=root
spring.datasource.password=123456

# mybatis配置
mybatis.mapper-locations=classpath:mapper/*Mapper.xml
# 驼峰
mybatis.configuration.map-underscore-to-camel-case=true
# 别名
mybatis.type-aliases-package=com.wpj.gmall.user.bean

5.2 bean

package com.wpj.gmall.user.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UmsMember {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private String id;
    private String memberLevelId;
    private String username;
    private String password;
    private String nickname;
    private String phone;
    private int status;
    private Date createTime;
    private String icon;
    private int gender;
    private Date birthday;
    private String city;
    private String job;
    private String personalizedSignature;
    private int sourceType;
    private int integration;
    private int growth;
    private int luckeyCount;
    private int historyIntegration;
}

5.3 mapper和xml

package com.wpj.gmall.user.mapper;

import com.wpj.gmall.user.bean.UmsMember;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Component
public interface IUserMapper extends Mapper<UmsMember> {

    List<UmsMember> selectAllUser();

}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wpj.gmall.user.mapper.IUserMapper">

    <select id="selectAllUser" resultType="umsMember">
        select * from ums_member
    </select>

</mapper>

5.4 service和impl

package com.wpj.gmall.user.service;

import com.wpj.gmall.user.bean.UmsMember;

import java.util.List;

public interface IUserService {
    List<UmsMember> getAllUser();
}
package com.wpj.gmall.user.service.impl;

import com.wpj.gmall.user.bean.UmsMember;
import com.wpj.gmall.user.mapper.IUserMapper;
import com.wpj.gmall.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper iUserMapper;

    @Override
    public List<UmsMember> getAllUser() {
//        List<UmsMember> umsMembers = iUserMapper.selectAllUser();
        List<UmsMember> umsMembers = iUserMapper.selectAll();
        return umsMembers;
    }
}

5.5 controller

package com.wpj.gmall.user.controller;

import com.wpj.gmall.user.bean.UmsMember;
import com.wpj.gmall.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {

    @Autowired
    private IUserService iUserService;

    @RequestMapping("index")
    @ResponseBody
    public String index(){
        return "hello gmall";
    }

    @RequestMapping("getAllUser")
    @ResponseBody
    public List<UmsMember> getAllUser(){
        List<UmsMember> umsMembers = iUserService.getAllUser();
        return umsMembers;
    }
}

在这里插入图片描述

6. 修改host文件

127.0.0.1 localhost user.gmall.com cart.gmall.com manage.gmall.com

在这里插入图片描述
在这里插入图片描述

7. idea自动导包和配置数据库

8. 通用mapper

8.1 Mapper接口继承Mapper

8.2 程序入口需要使用tkMapper的@MapperScan注解

8.3 记得tk.mybatis的版本要跟springboot的大版本匹配

9. 相关链接

  1. 项目源码
  2. 谷粒商场篇】第二天
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
gulimall_pms 商品 drop table if exists pms_attr; drop table if exists pms_attr_attrgroup_relation; drop table if exists pms_attr_group; drop table if exists pms_brand; drop table if exists pms_category; drop table if exists pms_category_brand_relation; drop table if exists pms_comment_replay; drop table if exists pms_product_attr_value; drop table if exists pms_sku_images; drop table if exists pms_sku_info; drop table if exists pms_sku_sale_attr_value; drop table if exists pms_spu_comment; drop table if exists pms_spu_images; drop table if exists pms_spu_info; drop table if exists pms_spu_info_desc; /*==============================================================*/ /* Table: pms_attr */ /*==============================================================*/ create table pms_attr ( attr_id bigint not null auto_increment comment '属性id', attr_name char(30) comment '属性名', search_type tinyint comment '是否需要检索[0-不需要,1-需要]', icon varchar(255) comment '属性图标', value_select char(255) comment '可选值列表[用逗号分隔]', attr_type tinyint comment '属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性]', enable bigint comment '启用状态[0 - 禁用,1 - 启用]', catelog_id bigint comment '所属分类', show_desc tinyint comment '快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整', primary key (attr_id) ); alter table pms_attr comment '商品属性'; /*==============================================================*/ /* Table: pms_attr_attrgroup_relation */ /*==============================================================*/ create table pms_attr_attrgroup_relation ( id bigint not null auto_increment comment 'id', attr_id bigint comment '属性id', attr_group_id bigint comment '属性分组id', attr_sort int comment '属性组内排序', primary key (id) ); alter table pms_attr_attrgroup_relation comment '属性&

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值