浅夏的猫 @shawsongyue
直接下载可用 https://gitee.com/shawsongyue/aurora.git
详细参考我的另外一遍博客: https://blog.csdn.net/weixin_40736233/article/details/135582926?spm=1001.2014.3001.5501
4.0.0
com.xsy
aurora_mybatis
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.3.5.RELEASE
1.8
3.8.1
UTF-8
UTF-8
8.0.21
1.2.75
3.5.3
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.projectlombok
lombok
com.alibaba
fastjson
${fastjson.version}
mysql
mysql-connector-java
${mysql-connector-java.version}
runtime
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.2
${project.name}
src/main/resources
src/main/java
**/*.xml
org.springframework.boot
spring-boot-maven-plugin
${spring.boot.version}
true
${project.build.finalName}
repackage
maven-compiler-plugin
${maven.plugin.version}
${java.version}
UTF-8
-parameters
aliyun-repos
https://maven.aliyun.com/nexus/content/groups/public/
false
aliyun-plugin
https://maven.aliyun.com/nexus/content/groups/public/
false
登录mysql数据库,创建表 tianchi_resource,并插入数据
CREATE TABLE `tianchi_resource` (
`id` bigint NOT NULL COMMENT '自增主键',
`resource_name` varchar(128) DEFAULT NULL COMMENT '资源名称',
`resource_path` varchar(255) DEFAULT NULL COMMENT '资源路径',
`resource_icon` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '资源图标',
`resource_icon_color` varchar(32) DEFAULT NULL COMMENT '资源图标颜色',
`resource_describe` varchar(255) DEFAULT NULL COMMENT '资源描述',
`resource_author` varchar(16) DEFAULT NULL COMMENT '资源作者',
`resource_type` varchar(16) DEFAULT NULL COMMENT '资源类型',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- 插入数据验证
INSERT INTO `aurora`.`tianchi_resource` (`id`, `resource_name`, `resource_path`, `resource_icon`, `resource_icon_color`, `resource_describe`, `resource_author`, `resource_type`, `create_time`, `update_time`) VALUES (1, 'colorUI资源包', 'http://baidu.com', 'url(https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg)', NULL, 'uniapp的ui页面资源包,免费提供,uniapp的ui页面资源包,免费提供,uniapp的ui页面资源包,免费提供', '浅夏的猫', NULL, '2024-01-06 00:50:33', '2024-01-07 23:56:58');
#服务配置
server:
#端口
port: 7001
#spring配置
spring:
#应用配置
application:
#应用名
name: aurora_mybatis
#数据源配置
datasource:
#驱动
driver-class-name: com.mysql.cj.jdbc.Driver
#连接地址
url: jdbc:mysql://127.0.0.1:3306/aurora?serverTimezone=UTC&characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true
#数据库用户
username: root
#数据库密码
password: yourpassword
#mybatis配置
mybatis:
#mapper.xml文件扫描路径
mapper-locations: classpath*:mapper/*Mapper.xml
#实体类扫描路径,配置这个以后mapper,xml里面写的实体类不需要全路径
type-aliases-package: com.aurora.entity
#mybatis拓展配置
configuration:
#设置下划线自动转换为大写字母
map-underscore-to-camel-case: true
tips:Application.class 类 springboot程序启动必备
package com.aurora;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author 浅夏的猫
* @description 主启动类
* @date 22:46 2024/1/13
*/
@SpringBootApplication
@MapperScan("com.aurora.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
tips:ResourceEntity.class 类 创建与数据库表对应的实体类,后续映射需要使用
package com.aurora.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @author 浅夏的猫
* @description 资源实体类
* @date 22:42 2024/1/13
*/
public class ResourceEntity implements Serializable {
private static final long serialVersionUID = 1L;
//资源id
private Long id;
//资源名称
private String resourceName;
//资源路径
private String resourcePath;
//资源图标
private String resourceIcon;
//资源图标颜色
private String resourceIconColor;
//资源描述
private String resourceDescribe;
//资源类型
private String resourceType;
//资源作者
private String resourceAuthor;
//资源创建时间
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
//资源更新时间
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
//查询结束时间
private Date endTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public String getResourcePath() {
return resourcePath;
}
public void setResourcePath(String resourcePath) {
this.resourcePath = resourcePath;
}
public String getResourceIcon() {
return resourceIcon;
}
public void setResourceIcon(String resourceIcon) {
this.resourceIcon = resourceIcon;
}
public String getResourceIconColor() {
return resourceIconColor;
}
public void setResourceIconColor(String resourceIconColor) {
this.resourceIconColor = resourceIconColor;
}
public String getResourceDescribe() {
return resourceDescribe;
}
public void setResourceDescribe(String resourceDescribe) {
this.resourceDescribe = resourceDescribe;
}
public String getResourceType() {
return resourceType;
}
public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}
public String getResourceAuthor() {
return resourceAuthor;
}
public void setResourceAuthor(String resourceAuthor) {
this.resourceAuthor = resourceAuthor;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
@Override
public String toString() {
return "ResourceEntity{" +
"id=" + id +
", resourceName='" + resourceName + '\'' +
", resourcePath='" + resourcePath + '\'' +
", resourceIcon='" + resourceIcon + '\'' +
", resourceIconColor='" + resourceIconColor + '\'' +
", resourceDescribe='" + resourceDescribe + '\'' +
", resourceType='" + resourceType + '\'' +
", resourceAuthor='" + resourceAuthor + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
", endTime=" + endTime +
'}';
}
}
tips:映射类主要用于编写操作sql的接口方法
package com.aurora.mapper;
import com.aurora.entity.ResourceEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @author 浅夏的猫
* @description 资源mapper操作类
* @date 22:45 2024/1/13
*/
@Mapper
public interface ResourceMapper {
/**
* @return java.util.List
* @description
* @author 浅夏的猫
* @datetime 23:19 2024/1/13
*/
List list();
}
tips: 每一个映射类对应一个mapper映射文件,在resources的mapper包下写映射文件
tips: 控制类用于浏览器或前端访问使用
package com.aurora.controller;
import com.aurora.entity.ResourceEntity;
import com.aurora.mapper.ResourceMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author 浅夏的猫
* @description 资源controller
* @date 22:38 2024/1/13
*/
@RestController
@RequestMapping("/resource")
public class ResourceController {
@Resource
private ResourceMapper resourceMapper;
/**
* @return java.util.List
* @description 查询全部资源数据列表
* @author 浅夏的猫
* @date 22:40 2024/1/13
*/
@RequestMapping("/list")
public List list() {
return resourceMapper.list();
}
}
tips: 访问地址http://localhost:7001/resource/list