Compare commits
	
		
			2 Commits
		
	
	
		
			2024/08/03
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 10d774df62 | |||
|   | 00f8620424 | 
| @ -42,3 +42,11 @@ dependencies { | |||||||
| tasks.named('test') { | tasks.named('test') { | ||||||
| 	useJUnitPlatform() | 	useJUnitPlatform() | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | tasks.withType(JavaCompile) { | ||||||
|  | 	options.encoding = 'UTF-8' | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | tasks.withType(Test) { | ||||||
|  | 	systemProperty 'file.encoding', 'UTF-8' | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								src/main/java/com/example/demo/config/MybatisPlusConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/main/java/com/example/demo/config/MybatisPlusConfig.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | package com.example.demo.config; | ||||||
|  | 
 | ||||||
|  | import com.baomidou.mybatisplus.annotation.DbType; | ||||||
|  | import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; | ||||||
|  | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||||||
|  | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||||||
|  | import org.mybatis.spring.annotation.MapperScan; | ||||||
|  | import org.springframework.context.annotation.Bean; | ||||||
|  | import org.springframework.context.annotation.Configuration; | ||||||
|  | 
 | ||||||
|  | @Configuration | ||||||
|  | @MapperScan(basePackages = {"com.example.**.mapper"}) | ||||||
|  | public class MybatisPlusConfig { | ||||||
|  | 
 | ||||||
|  |     @Bean | ||||||
|  |     public MybatisPlusInterceptor mybatisPlusInterceptor() { | ||||||
|  |         MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||||||
|  |         interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||||||
|  |         return interceptor; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Bean | ||||||
|  |     public ConfigurationCustomizer configurationCustomizer() { | ||||||
|  |         return configuration -> configuration.setUseGeneratedShortKey(false); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,7 +1,7 @@ | |||||||
| package com.example.demo.controller; | package com.example.demo.controller; | ||||||
| 
 | 
 | ||||||
|  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||||
| import com.example.demo.entity.News; | import com.example.demo.entity.News; | ||||||
| import com.example.demo.entity.User; |  | ||||||
| import com.example.demo.service.NewsService; | import com.example.demo.service.NewsService; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
| @ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| @RestController | @RestController | ||||||
|  | @RequestMapping("/news") | ||||||
| public class NewsController { | public class NewsController { | ||||||
|     private final NewsService newsService; |     private final NewsService newsService; | ||||||
| 
 | 
 | ||||||
| @ -17,9 +18,11 @@ public class NewsController { | |||||||
|         this.newsService = newsService; |         this.newsService = newsService; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @GetMapping("/news") |     @GetMapping("/list") | ||||||
|     public List<News> getAllNews() { |     public Page<News> getAllNews(@RequestParam(defaultValue = "1") int page, | ||||||
|         return newsService.getAllNews(); |                                  @RequestParam(defaultValue = "10") int size) { | ||||||
|  |         Page<News> newsPage = new Page<>(page, size); | ||||||
|  |         return newsService.getAllNews(newsPage); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @PostMapping("/insertNews") |     @PostMapping("/insertNews") | ||||||
|  | |||||||
| @ -17,20 +17,20 @@ public class News { | |||||||
|     @TableField(value = "EXCERPT") |     @TableField(value = "EXCERPT") | ||||||
|     private String excerpt; |     private String excerpt; | ||||||
| 
 | 
 | ||||||
|     @TableField(value = "CREATE_TIME", fill = FieldFill.UPDATE) |     @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT) | ||||||
|     private Timestamp create_time; |     private Timestamp createTime; | ||||||
| 
 | 
 | ||||||
|     @TableField(value = "UPDATE_TIME", fill = FieldFill.INSERT) |     @TableField(value = "UPDATE_TIME", fill = FieldFill.UPDATE) | ||||||
|     private Timestamp update_time; |     private Timestamp updateTime; | ||||||
| 
 | 
 | ||||||
|     @TableField(value = "IS_DELETE") |     @TableField(value = "IS_DELETE") | ||||||
|     private Boolean is_delete; |     private Boolean isDelete; | ||||||
| 
 | 
 | ||||||
|     @TableField(value = "EXT") |     @TableField(value = "EXT") | ||||||
|     private String ext; |     private String ext; | ||||||
| 
 | 
 | ||||||
|     @TableField(value = "BATCH_ID") |     @TableField(value = "BATCH_ID") | ||||||
|     private String batch_id; |     private String batchId; | ||||||
| 
 | 
 | ||||||
|     public News() { |     public News() { | ||||||
| 
 | 
 | ||||||
| @ -40,14 +40,4 @@ public class News { | |||||||
|         this.title = title; |         this.title = title; | ||||||
|         this.excerpt = excerpt; |         this.excerpt = excerpt; | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     public News(int id, String title, String excerpt, Timestamp create_time, Timestamp update_time, Boolean is_delete, String ext) { |  | ||||||
|         this.id = id; |  | ||||||
|         this.title = title; |  | ||||||
|         this.excerpt = excerpt; |  | ||||||
|         this.create_time = create_time; |  | ||||||
|         this.update_time = update_time; |  | ||||||
|         this.is_delete = is_delete; |  | ||||||
|         this.ext = ext; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,6 +2,8 @@ package com.example.demo.mapper; | |||||||
| 
 | 
 | ||||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
| import com.example.demo.entity.News; | import com.example.demo.entity.News; | ||||||
|  | import org.apache.ibatis.annotations.Mapper; | ||||||
| 
 | 
 | ||||||
|  | @Mapper | ||||||
| public interface NewsMapper extends BaseMapper<News> { | public interface NewsMapper extends BaseMapper<News> { | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,6 +2,8 @@ package com.example.demo.mapper; | |||||||
| 
 | 
 | ||||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
| import com.example.demo.entity.User; | import com.example.demo.entity.User; | ||||||
|  | import org.apache.ibatis.annotations.Mapper; | ||||||
| 
 | 
 | ||||||
|  | @Mapper | ||||||
| public interface UserMapper extends BaseMapper<User> { | public interface UserMapper extends BaseMapper<User> { | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,10 +1,9 @@ | |||||||
| package com.example.demo.service; | package com.example.demo.service; | ||||||
|  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||||
| import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||||
| import com.example.demo.entity.News; | import com.example.demo.entity.News; | ||||||
| 
 | 
 | ||||||
| import java.util.List; |  | ||||||
| 
 |  | ||||||
| public interface NewsService extends IService<News> { | public interface NewsService extends IService<News> { | ||||||
|     List<News> getAllNews(); |     Page<News> getAllNews(Page<News> page); | ||||||
|     News getNewsById(Integer id); |     News getNewsById(Integer id); | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package com.example.demo.service.impl; | package com.example.demo.service.impl; | ||||||
| 
 | 
 | ||||||
|  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||||
| import com.example.demo.entity.News; | import com.example.demo.entity.News; | ||||||
| import com.example.demo.mapper.NewsMapper; | import com.example.demo.mapper.NewsMapper; | ||||||
| @ -12,9 +13,15 @@ import java.util.UUID; | |||||||
| 
 | 
 | ||||||
| @Service | @Service | ||||||
| public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService { | public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService { | ||||||
|  |     private final NewsMapper newsMapper; | ||||||
|  | 
 | ||||||
|  |     public NewsServiceImpl(NewsMapper newsMapper) { | ||||||
|  |         this.newsMapper = newsMapper; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<News> getAllNews() { |     public Page<News> getAllNews(Page<News> page) { | ||||||
|         return list(); |         return newsMapper.selectPage(page, null); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -26,7 +33,7 @@ public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements Ne | |||||||
|     public boolean saveBatch(Collection<News> newsList) { |     public boolean saveBatch(Collection<News> newsList) { | ||||||
|         String batchId = UUID.randomUUID().toString(); |         String batchId = UUID.randomUUID().toString(); | ||||||
|         for (News news : newsList) { |         for (News news : newsList) { | ||||||
|             news.setBatch_id(batchId); |             news.setBatchId(batchId); | ||||||
|         } |         } | ||||||
|         return super.saveBatch(newsList); |         return super.saveBatch(newsList); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -3,7 +3,10 @@ spring.datasource.url=jdbc:p6spy:mysql://47.106.93.245:9003/service | |||||||
| spring.datasource.username=root | spring.datasource.username=root | ||||||
| spring.datasource.password=qingyu23. | spring.datasource.password=qingyu23. | ||||||
| spring.datasource.driver-class-name = com.p6spy.engine.spy.P6SpyDriver | spring.datasource.driver-class-name = com.p6spy.engine.spy.P6SpyDriver | ||||||
| #spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl | ||||||
|  | mybatis-plus.global-config.db-config.id-type=auto | ||||||
|  | logging.level.com.baomidou.mybatisplus=DEBUG | ||||||
|  | logging.level.org.apache.ibatis=DEBUG | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user