博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 构建电商基础秒杀项目 (一) 项目搭建
阅读量:6923 次
发布时间:2019-06-27

本文共 4097 字,大约阅读时间需要 13 分钟。

学习笔记

Spring Boot 其实不是什么新的框架,它默认配置了很多框架的使用方式,就像 maven 整合了所有的 jar 包, Spring Boot 整合了所有的框架,并通过一行简单的 main 方法启动应用

使用 IDEA 新建 maven-archetype-quickstart 项目

添加 Spring Boot 依赖

org.springframework.boot
spring-boot-starter-parent
2.0.5.RELEASE
org.springframework.boot
spring-boot-starter-web

修改 App.java

@EnableAutoConfiguration@RestControllerpublic class App {    @RequestMapping("/")    public String home(){        return "Hello World!";    }    public static void main( String[] args )    {        System.out.println( "Hello World!" );        SpringApplication.run(App.class, args);    }}

运行,在浏览器输入:localhost:8080

注:8080 是默认端口,如果要使用其他端口,可以在 application.properties 修改,如:server.port=8090

接入 Mybatis

添加依赖

mysql
mysql-connector-java
5.1.41
com.alibaba
druid
1.1.3
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.1
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.5
org.mybatis.generator
mybatis-generator-core
1.3.5
mysql
mysql-connector-java
5.1.41
mybaits generator
package
generate
true
true
src/main/resources/mybatis-generator.xml

在 application.properties 添加配置

mybatis.mapper-locations=classpath:mapping/*.xml

新建数据表

数据库名为 seckill

create table if not exists user_info(    id int not null auto_increment,    name varchar(64) not null default '',    gender tinyint not null default 0 comment '1: 男, 2: 女',    age int not null default 0,    telphone varchar(16) not null default '',    register_mode varchar(64) not null default '' comment 'byphone, bywechat, byalipay',    third_party_id varchar(64) not null default '',    primary key (id));create table if not exists user_password (    id int not null auto_increment,    encrpt_password varchar(128) not null default '',    user_id int not null default 0,    primary key (id));

添加配置文件 mybatis-generator.xml

新建 Maven 命令

Run -- Edit Configurations -- 新增 -- Maven:

  • Name: mybatis-generator
  • Command line: mybatis-generator:generate

Run 'mybatis-generator'

配置数据源

在 application.properties 添加配置:

spring.datasource.name=seckillspring.datasource.url=jdbc:mysql://127.0.0.1:3306/seckillspring.datasource.username=rootspring.datasource.password=root# 使用 druid 数据源spring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.driver-class-name=com.mysql.jdbc.Driver

修改 App.java

@SpringBootApplication(scanBasePackages = {"com.karonda"})@RestController@MapperScan("com.karonda.dao")public class App {    @Autowired    private UserDOMapper userDOMapper;    @RequestMapping("/")    public String home(){        UserDO userDO = userDOMapper.selectByPrimaryKey(1);        if(userDO == null){            return "用户对象不存在";        }else{            return userDO.getName();        }    }    public static void main( String[] args )    {        System.out.println( "Hello World!" );        SpringApplication.run(App.class, args);    }}

源码:

转载于:https://www.cnblogs.com/victorbu/p/10538615.html

你可能感兴趣的文章
Android FragmentManage FragmentTransaction介绍
查看>>
手机APP,台前幕后在争啥?
查看>>
平衡二叉树的旋转(左旋和右旋)
查看>>
bash vim模式
查看>>
MyEclipse - 删除自带Libraries中的jar
查看>>
vi 高级应用
查看>>
find ~/ -name "*.aic" -exec rm -rf {} \;请问里面的各项是什么意思--?
查看>>
面向过程和面向对象的区别是什么?
查看>>
Linux命令详解 -- ls
查看>>
python while 基础练习
查看>>
MySQL增删改查--之增
查看>>
cpp命名空间
查看>>
10.11 Linux网络相关 10.12 firewalld和netfilter 10.13 ne
查看>>
互联网创业的准备——数据库:硬盘iops、mysql
查看>>
深入了解硬盘
查看>>
通过虚拟机VMware来练习安装ESXi
查看>>
Mybatis深度整合Mysql的Json字段
查看>>
程序清单3.2_print1.c_程序_《C Primer Plus》P37
查看>>
文档注释
查看>>
自然语言处理之:搭建基于HanLP的开发环境(转)
查看>>