server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/course?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=True
username: root
password: 123456
mybatis-plus:
mapper-locations: mapper/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
type-aliases-package: com.example.springbootai.entity
依赖:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--简化代码的工具包-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
mapper.xml
<?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.example.springbootai.mapper.LunBoTuMapper">
<select id="selectAll" resultType="com.example.springbootai.entity.LunBoTu">
select * from LUN_BO_TU
</select>
</mapper>
controller
package com.example.springbootai.controller; import com.example.springbootai.entity.LunBoTu; import com.example.springbootai.service.LunBoTuService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * @title: LunBoTuController * @Author CaoJun * @Date: 2025/3/12 下午2:33 * @Version 1.0 */ @RestController @RequestMapping("/lunBoTu") public class LunBoTuController { @Autowired private LunBoTuService lunBoTuService; /** * 通过所有数据 * * @return 实例对象 */ @GetMapping("/selectAll") public ResponseEntity<List<LunBoTu>> selectAll() { return ResponseEntity.ok(lunBoTuService.selectAll()); } }
package com.example.springbootai.service.impl;
import com.example.springbootai.entity.LunBoTu;
import com.example.springbootai.mapper.LunBoTuMapper;
import com.example.springbootai.service.LunBoTuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @title: LunBoTuServiceImpl
* @Author CaoJun
* @Date: 2025/3/12 下午2:31
* @Version 1.0
*/
@Service
public class LunBoTuServiceImpl implements LunBoTuService {
@Autowired
private LunBoTuMapper lunBoTuMapper;
@Override
public List<LunBoTu> selectAll() {
return lunBoTuMapper.selectAll();
}
}
package com.example.springbootai.service;
import com.example.springbootai.entity.LunBoTu;
import java.util.List;
/**
* @title: LunBoTuService
* @Author CaoJun
* @Date: 2025/3/12 下午2:30
* @Version 1.0
*/
public interface LunBoTuService {
List<LunBoTu> selectAll();
}
package com.example.springbootai.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springbootai.entity.LunBoTu;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @title: LunBoTuMapper
* @Author CaoJun
* @Date: 2025/3/12 下午2:26
* @Version 1.0
*/
@Mapper
public interface LunBoTuMapper extends BaseMapper<LunBoTu> {
/**
* @return 对象列表
*/
List<LunBoTu> selectAll();
}
package com.example.springbootai.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* 首页轮播图;
*
* @author : http://www.chiner.pro
* @date : 2025-3-12
*/
@TableName("LUN_BO_TU")
@Data
public class LunBoTu implements Serializable {
/**
* 轮播图ID;主键ID
*/
@TableId(value = "LUN_BO_TU_ID",type = IdType.AUTO)
private String lunBoTuId;
/**
* 轮播图名称
*/
private String mingCheng;
/**
* 轮播图照片链接
*/
private String zhaoPianLj;
/**
* 轮播图状态;0上架 1下架
*/
private Integer zhuangTai;
/**
* 轮播图描述
*/
private String miaoShu;
/**
* 轮播图排序
*/
private Integer paiXu;
/**
* 是否删除;0存在 1删除
*/
private Integer shiFouSc;
/**
* 管理的链接
*/
private String guanLiLj;
/**
* 创建人
*/
private String chuangJianR;
/**
* 创建时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date chuangJianSj;
/**
* 更新人
*/
private String gengXinR;
/**
* 更新时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date gengXinSj;
/**
* 关联的活动ID
*/
private String huoDongId;
}
DROP TABLE IF EXISTS LUN_BO_TU;
CREATE TABLE LUN_BO_TU(
`LUN_BO_TU_ID` INT AUTO_INCREMENT COMMENT '轮播图ID;主键ID' ,
`MING_CHENG` VARCHAR(90) NOT NULL COMMENT '轮播图名称' ,
`ZHAO_PIAN_LJ` VARCHAR(255) NOT NULL COMMENT '轮播图照片链接' ,
`ZHUANG_TAI` INT(1) NOT NULL DEFAULT 0 COMMENT '轮播图状态;0上架 1下架' ,
`MIAO_SHU` VARCHAR(255) NOT NULL COMMENT '轮播图描述' ,
`PAI_XU` INT NOT NULL COMMENT '轮播图排序' ,
`SHI_FOU_SC` INT(1) NOT NULL DEFAULT 0 COMMENT '是否删除;0存在 1删除' ,
`GUAN_LI_LJ` VARCHAR(255) COMMENT '管理的链接' ,
`CHUANG_JIAN_R` VARCHAR(32) COMMENT '创建人' ,
`CHUANG_JIAN_SJ` DATETIME COMMENT '创建时间' ,
`GENG_XIN_R` VARCHAR(32) COMMENT '更新人' ,
`GENG_XIN_SJ` DATETIME COMMENT '更新时间' ,
`HUO_DONG_ID` VARCHAR(32) COMMENT '关联的活动ID' ,
PRIMARY KEY (LUN_BO_TU_ID)
) COMMENT = '首页轮播图';