Compare commits
3 Commits
cd6a13ba9d
...
6841ba67f1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6841ba67f1 | ||
|
|
1d4dee573e | ||
|
|
f84c66b6db |
4
pom.xml
4
pom.xml
@@ -50,6 +50,10 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.qf.myafterprojecy;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.qf.myafterprojecy.controller")
|
||||||
|
public class MyAfterProjecyApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MyAfterProjecyApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.qf.myafterprojecy.controller;
|
||||||
|
|
||||||
|
import com.qf.myafterprojecy.pojo.Article;
|
||||||
|
import com.qf.myafterprojecy.pojo.ResponseMessage;
|
||||||
|
import com.qf.myafterprojecy.pojo.dto.ArticleDto;
|
||||||
|
import com.qf.myafterprojecy.service.IArticleService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/article")
|
||||||
|
public class ArticleController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
IArticleService ArticleService;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseMessage<Iterable<Article>> getArticle(){
|
||||||
|
return ArticleService.getArticleAll();
|
||||||
|
};
|
||||||
|
@GetMapping
|
||||||
|
public ResponseMessage<Article> geybyID(@RequestBody ArticleDto articleDto){
|
||||||
|
System.out.println("id:"+ articleDto.getArticleid());
|
||||||
|
return ArticleService.getArticleByid(Integer.valueOf(articleDto.getArticleid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
95
src/main/java/com/qf/myafterprojecy/pojo/Article.java
Normal file
95
src/main/java/com/qf/myafterprojecy/pojo/Article.java
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
package com.qf.myafterprojecy.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "article")
|
||||||
|
public class Article {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "articleid")
|
||||||
|
private Integer articleid;
|
||||||
|
@Column(name = "title")
|
||||||
|
private String title;
|
||||||
|
@Column(name = "content")
|
||||||
|
private String content;
|
||||||
|
@Column(name = "img")
|
||||||
|
private String img;
|
||||||
|
@Column(name = "typeid")
|
||||||
|
private int typeid;
|
||||||
|
@Column(name = "published_at")
|
||||||
|
private String publisher_at;
|
||||||
|
@Column(name = "created_at")
|
||||||
|
private String created_at;
|
||||||
|
|
||||||
|
public Integer getArticleid() {
|
||||||
|
return articleid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArticleid(Integer articleid) {
|
||||||
|
this.articleid = articleid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImg() {
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImg(String img) {
|
||||||
|
this.img = img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTypeid() {
|
||||||
|
return typeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeid(int typeid) {
|
||||||
|
this.typeid = typeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher_at() {
|
||||||
|
return publisher_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher_at(String publisher_at) {
|
||||||
|
this.publisher_at = publisher_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreated_at() {
|
||||||
|
return created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreated_at(String created_at) {
|
||||||
|
this.created_at = created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Article{" +
|
||||||
|
"articleid=" + articleid +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", content='" + content + '\'' +
|
||||||
|
", img='" + img + '\'' +
|
||||||
|
", typeid=" + typeid +
|
||||||
|
", publisher_at='" + publisher_at + '\'' +
|
||||||
|
", created_at='" + created_at + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.qf.myafterprojecy.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
public class ResponseMessage<T> {
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
private T data;
|
||||||
|
public ResponseMessage(Integer code, String message, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
// 接口请求成功
|
||||||
|
public static <T> ResponseMessage<T> success(T data) {
|
||||||
|
return new ResponseMessage(HttpStatus.OK.value(), "success", data);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
src/main/java/com/qf/myafterprojecy/pojo/dto/ArticleDto.java
Normal file
82
src/main/java/com/qf/myafterprojecy/pojo/dto/ArticleDto.java
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package com.qf.myafterprojecy.pojo.dto;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
|
||||||
|
public class ArticleDto {
|
||||||
|
private Integer articleid;
|
||||||
|
private String title;
|
||||||
|
private String content;
|
||||||
|
private String img;
|
||||||
|
private Integer typeid;
|
||||||
|
private String publisher_at;
|
||||||
|
private String created_at;
|
||||||
|
|
||||||
|
public Integer getArticleid() {
|
||||||
|
return articleid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArticleid(Integer articleid) {
|
||||||
|
this.articleid = articleid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImg() {
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImg(String img) {
|
||||||
|
this.img = img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTypeid() {
|
||||||
|
return typeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeid(Integer typeid) {
|
||||||
|
this.typeid = typeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher_at() {
|
||||||
|
return publisher_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher_at(String publisher_at) {
|
||||||
|
this.publisher_at = publisher_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreated_at() {
|
||||||
|
return created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreated_at(String created_at) {
|
||||||
|
this.created_at = created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ArticleDto{" +
|
||||||
|
"articleid=" + articleid +
|
||||||
|
", title='" + title + '\'' +
|
||||||
|
", content='" + content + '\'' +
|
||||||
|
", img='" + img + '\'' +
|
||||||
|
", typeid=" + typeid +
|
||||||
|
", publisher_at='" + publisher_at + '\'' +
|
||||||
|
", created_at='" + created_at + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.qf.myafterprojecy.repository;
|
||||||
|
|
||||||
|
import com.qf.myafterprojecy.pojo.Article;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ArticleRepository extends CrudRepository<Article,Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.qf.myafterprojecy.service;
|
||||||
|
|
||||||
|
import com.qf.myafterprojecy.pojo.Article;
|
||||||
|
import com.qf.myafterprojecy.pojo.ResponseMessage;
|
||||||
|
import com.qf.myafterprojecy.repository.ArticleRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ArticleService implements IArticleService{
|
||||||
|
@Autowired
|
||||||
|
ArticleRepository articleRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseMessage<Article> getArticleByid(Integer articleid){
|
||||||
|
Article articlenew = articleRepository.findById(articleid).orElseThrow(RuntimeException::new);
|
||||||
|
return ResponseMessage.success(articlenew) ;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ResponseMessage<Iterable<Article>> getArticleAll(){
|
||||||
|
Iterable<Article> Articles = articleRepository.findAll();
|
||||||
|
return ResponseMessage.success(Articles);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.qf.myafterprojecy.service;
|
||||||
|
|
||||||
|
import com.qf.myafterprojecy.pojo.Article;
|
||||||
|
import com.qf.myafterprojecy.pojo.ResponseMessage;
|
||||||
|
|
||||||
|
public interface IArticleService {
|
||||||
|
|
||||||
|
ResponseMessage<Article> getArticleByid(Integer articleid);
|
||||||
|
|
||||||
|
ResponseMessage<Iterable<Article>> getArticleAll();
|
||||||
|
}
|
||||||
15
src/main/resources/application.properties
Normal file
15
src/main/resources/application.properties
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 应用服务 WEB 访问端口
|
||||||
|
server.port=8080
|
||||||
|
spring.application.name=web_project
|
||||||
|
spring.datasource.url=jdbc:mysql://localhost:3306/webporject
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=123456
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.properties.hibernate.format_sql=true
|
||||||
|
#下面这些内容是为了让MyBatis映射
|
||||||
|
#指定Mybatis的Mapper文件
|
||||||
|
mybatis.mapper-locations=classpath:mappers/*xml
|
||||||
|
#指定Mybatis的实体目录
|
||||||
|
mybatis.type-aliases-package=com.qf.myafterprojecy.mybatis.entity
|
||||||
6
src/main/resources/static/index.html
Normal file
6
src/main/resources/static/index.html
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>hello word!!!</h1>
|
||||||
|
<p>this is a html page</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.qf.myafterprojecy;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class MyAfterProjecyApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user