🔄Update: 获取数据库中的 Movie

This commit is contained in:
2025-10-30 21:04:57 +08:00
parent f964515038
commit de5b7d679a
28 changed files with 423 additions and 9 deletions
@@ -0,0 +1,14 @@
package cn.hezhaohui.movie;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.hezhaohui.movie.mapper")
public class MovieApplication {
public static void main(String[] args) {
SpringApplication.run(MovieApplication.class, args);
}
}
@@ -0,0 +1,25 @@
package cn.hezhaohui.movie.controller;
import cn.hezhaohui.movie.entity.Movie;
import cn.hezhaohui.movie.service.MovieService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
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;
@RestController
@RequestMapping("movie")
public class MovieController {
@Resource
private MovieService movieService;
@GetMapping
public List<Movie> getMovieList(){
return movieService.list(new QueryWrapper<Movie>().orderByDesc("id"));
}
}
@@ -0,0 +1,71 @@
package cn.hezhaohui.movie.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName movie
*/
@TableName(value ="movie")
@Data
public class Movie {
/**
*
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
*
*/
private String name;
/**
*
*/
private Date day;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Movie other = (Movie) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getDay() == null ? other.getDay() == null : this.getDay().equals(other.getDay()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getDay() == null) ? 0 : getDay().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", name=").append(name);
sb.append(", day=").append(day);
sb.append("]");
return sb.toString();
}
}
@@ -0,0 +1,18 @@
package cn.hezhaohui.movie.mapper;
import cn.hezhaohui.movie.entity.Movie;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 23117
* @description 针对表【movie】的数据库操作Mapper
* @createDate 2025-10-30 19:52:48
* @Entity cn.hezhaohui.movie.entity.Movie
*/
public interface MovieMapper extends BaseMapper<Movie> {
}
@@ -0,0 +1,13 @@
package cn.hezhaohui.movie.service;
import cn.hezhaohui.movie.entity.Movie;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author 23117
* @description 针对表【movie】的数据库操作Service
* @createDate 2025-10-30 19:52:48
*/
public interface MovieService extends IService<Movie> {
}
@@ -0,0 +1,22 @@
package cn.hezhaohui.movie.service.impl;
import cn.hezhaohui.movie.entity.Movie;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hezhaohui.movie.service.MovieService;
import cn.hezhaohui.movie.mapper.MovieMapper;
import org.springframework.stereotype.Service;
/**
* @author 23117
* @description 针对表【movie】的数据库操作Service实现
* @createDate 2025-10-30 19:52:48
*/
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie>
implements MovieService{
}
+8
View File
@@ -0,0 +1,8 @@
spring:
datasource:
username: root
password: dn293830
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.121.181.112:3306/panel
server:
port: 8081
@@ -0,0 +1,16 @@
<?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="cn.hezhaohui.movie.mapper.MovieMapper">
<resultMap id="BaseResultMap" type="cn.hezhaohui.movie.entity.Movie">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="day" column="day" />
</resultMap>
<sql id="Base_Column_List">
id,name,day
</sql>
</mapper>
@@ -0,0 +1,25 @@
package cn.hezhaohui.movie.service.impl;
import cn.hezhaohui.movie.entity.Movie;
import cn.hezhaohui.movie.service.MovieService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class MovieServiceImplTest {
@Resource
private MovieService movieService;
@Test
void getMovies() {
List<Movie> list = movieService.list();
System.out.println(list);
}
}