谷粒商场篇】第一天

第一天

  • 1. 简介
  • 2. 相关技术
  • 3. IDEA简单配置
  • 4. 数据库软件和脚本文件
  • 5. 新建一个user项目
    • 5.1 application.properties
    • 5.2 bean
    • 5.3 mapper和xml
    • 5.4 service和impl
    • 5.5 controller
  • 6. 修改host文件
  • 7. idea自动导包和配置数据库
  • 8. 通用mapper
    • 8.1 Mapper接口继承Mapper
    • 8.2 程序入口需要使用tkMapper的@MapperScan注解
    • 8.3 记得tk.mybatis的版本要跟springboot的大版本匹配
  • 9. 相关链接

中国加油,武汉加油!

1. 简介

模式 含义 代表
B2C Business To Consumer 商对客 天猫,京东
C2C Consumer To Consumer 个人与个人之间的电子商务 淘宝
P2P Peer To Peer 人人贷
P2C Production 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谷粒商场篇】第一天_第1张图片

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

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

5. 新建一个user项目

  1. 新建module,选择springboot,springweb,mysql驱动,jdbc,mybatis,lombox依赖
  2. 写controller,service
  3. 写bean的映射类,映射数据库表ums_user_member表
  4. 写功能
    谷粒商场篇】第一天_第2张图片
  5. 导通用Mapper依赖
    
    <dependency>
    	<groupId>tk.mybatisgroupId>
    	<artifactId>mapper-spring-boot-starterartifactId>
    	<version>2.1.5version>
    	<exclusions>
    		<exclusion>
    			<groupId>org.springframework.bootgroupId>
    			<artifactId>spring-boot-starter-jdbcartifactId>
    		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();

}


<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 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;
    }
}

谷粒商场篇】第一天_第3张图片

6. 修改host文件

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

谷粒商场篇】第一天_第4张图片
谷粒商场篇】第一天_第5张图片

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

8. 通用mapper

8.1 Mapper接口继承Mapper

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

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

9. 相关链接

  1. 项目源码
  2. 谷粒商场篇】第二天

你可能感兴趣的:(谷粒商场)