🔄Update: 获取数据库中的 Movie
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package cn.hezhaohui.pojo.dto;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class MovieDTO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Date day;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.hezhaohui.entity;
|
||||
package cn.hezhaohui.pojo.entity;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -0,0 +1,11 @@
|
||||
package cn.hezhaohui.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MovieVO {
|
||||
|
||||
private String name;
|
||||
|
||||
private String date;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MovieClient {
|
||||
|
||||
List<MovieDTO> listMovies();
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
|
||||
public interface WeatherClient {
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MovieClientImpl implements MovieClient {
|
||||
@Override
|
||||
public List<MovieDTO> listMovies() {
|
||||
String ans = HttpUtil.get("http://localhost:8081/movie");
|
||||
return JSONUtil.parseArray(ans).toList(MovieDTO.class);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hezhaohui.lark.handler;
|
||||
|
||||
import cn.hezhaohui.common.AppConstant;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hezhaohui.lark.util.BeanUtil;
|
||||
import cn.hezhaohui.lark.util.LarkUtil;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.hezhaohui.lark.service;
|
||||
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.pojo.vo.MovieVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MovieService {
|
||||
|
||||
@Resource
|
||||
private MovieClient movieClient;
|
||||
|
||||
public List<MovieVO> listMovies() {
|
||||
List<MovieDTO> movieDTOS = movieClient.listMovies();
|
||||
List<MovieVO> movieVOS = new ArrayList<>();
|
||||
for (MovieDTO movieDTO : movieDTOS) {
|
||||
MovieVO movieVO = new MovieVO();
|
||||
movieVO.setName(movieDTO.getName());
|
||||
movieVO.setDate(new SimpleDateFormat("yyyy-MM-dd").format(movieDTO.getDay()));
|
||||
movieVOS.add(movieVO);
|
||||
}
|
||||
return movieVOS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||
import cn.hezhaohui.lark.client.MovieClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class MovieClientImplTest {
|
||||
|
||||
@Resource
|
||||
private MovieClient movieClient;
|
||||
|
||||
@Test
|
||||
void listMovies() {
|
||||
List<MovieDTO> movieDTOS = movieClient.listMovies();
|
||||
for(MovieDTO movieDTO : movieDTOS) {
|
||||
System.out.println(movieDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.hezhaohui.lark.service;
|
||||
|
||||
import cn.hezhaohui.pojo.vo.MovieVO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class MovieServiceTest {
|
||||
|
||||
@Resource
|
||||
private MovieService movieService;
|
||||
|
||||
@Test
|
||||
void listMovies() {
|
||||
List<MovieVO> movies = movieService.listMovies();
|
||||
for (MovieVO movie : movies) {
|
||||
System.out.println(movie);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package cn.hezhaohui.lark.util;
|
||||
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
CREATE DATABASE IF NOT EXISTS panel;
|
||||
|
||||
USE panel;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS movie (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
day DATE NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.hezhaohui</groupId>
|
||||
<artifactId>lark-panel</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>movie</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hezhaohui</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -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{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<module>lark</module>
|
||||
<module>weather</module>
|
||||
<module>common</module>
|
||||
<module>movie</module>
|
||||
</modules>
|
||||
|
||||
<!-- 依赖管理 -->
|
||||
@@ -38,6 +39,16 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>3.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<!-- 构建配置 -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hezhaohui.weather.controller;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.weather.util.WeatherUtil;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hezhaohui.weather.util;
|
||||
|
||||
import cn.hezhaohui.common.AIConstant;
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import cn.hezhaohui.weather.service.ChatService;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hezhaohui.weather.util;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.pojo.entity.Weather;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user