基于Spring,MyBatis,SpringBoot,Thymeleaf技术实现商品模块的增删改查操作。
准备工作1. MySQL(5.7)
2. JDK (1.8)
3. Maven (3.6.3)
4. STS(4.7.1)
技术架构
采用典型的c/s架构进行实现,客户端我们基于浏览器进行实现,服务端采用tomacat,数据库使用mysql,具体应用层基于mvc分层架构实现
技术栈
客户端:html,css,js,bootstrap
服务端:spring,springboot,mybaties,thymeleaf
数据库:mysql,SQL
API整合

业务时序

初始化数据库
登录mysql mysql -uroot -proot
设置编码格式
set names utf8;
执行goods.sql文件
其中goods.sql文件内容如下:drop database if exists dbbrand;
create database dbbrand default character set utf8;
use dbbrand;
create table tb_brand(
id bigint primary key auto_increment,
name varchar(100) not null,
remark text,
createdTime datetime not null
)engine=InnoDB;
insert into tb_brand values (null,'联想','very good',now());
insert into tb_brand values (null,'小米','very good',now());
insert into tb_brand values (null,'美的','very good',now());
insert into tb_brand values (null,'九阳','very good',now());
insert into tb_brand values (null,'TCL','very good',now());
insert into tb_brand values (null,'创维','very good',now());
insert into tb_brand values (null,'华为','very good',now());
基于idea创建
创建module
项目配置文件
application.properties,添加如下内容:#server
server.port=80
#server.servlet.context-path=/
#spring datasource
spring.datasource.url=jdbc:mysql:///dbgoods?serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root
#spring mybatis
mybatis.mapper-locations=classpath:/mapper/*/*.xml
#spring logging
logging.level.com.cy=debug
#spring thymeleaf
spring.thymeleaf.prefix=classpath:/templates/pages/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
添加依赖
org.springframework.boot
spring-boot-starter-data-jdbc
org.springframework.boot
spring-boot-starter-groovy-templates
org.springframework.boot
spring-boot-starter-jersey
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
runtime
启动类检查是否能正常启动
领域对象Pojo类定义设计及实现
第一步:定义Goods对象,用于封装从数据库查询到的商品信息。package com.cy.pj.goods.pojo;
import java.util.Date;
public class Goods {
private Integer id;//id bigint primary key auto_increment
private String name;//name varchar(100) not null
private String remark;//remark text
private Date createdTime;//createdTime datetime
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;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
@Override
public String toString() {
return "Goods [id=" + id + ", name=" + name + ",
remark=" + remark + ", createdTime=" + createdTime + "]";
}
}
第二步:### Dao接口方法<

该博客介绍了如何基于Spring、MyBatis、SpringBoot和Thymeleaf技术实现商品模块的增删改查(CRUD)操作。首先,博主详细讲述了项目的准备工作和技术栈,包括所需的软件版本和数据库准备。接着,逐步展示了从创建数据库表、配置Spring Boot应用、定义领域对象、Dao接口、服务接口及其实现,到测试和控制器层的实现过程。最后,博主提到了在项目运行中可能遇到的问题和解决方案,以及商品添加、删除和修改的业务实现步骤。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



