06/08 17:21
This commit is contained in:
parent
1fae68d6b6
commit
d9e8587dfa
2
pom.xml
2
pom.xml
@ -91,6 +91,8 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!--启动类的全路径-->
|
||||
<mainClass>cn.czyx007.mt.Application</mainClass>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -2,14 +2,22 @@ package cn.czyx007.mt;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement(proxyTargetClass = true)
|
||||
public class Application {
|
||||
@EnableCaching
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(this.getClass());
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class AlipayConfig {
|
||||
// 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
public static String notify_url = "http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/notify_url.jsp";
|
||||
// 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
|
||||
public static String return_url = "http://localhost:8080/order/afterPayOrder";
|
||||
public static String return_url = "http://101.43.84.101:8080/order/afterPayOrder";
|
||||
// 请求网关地址
|
||||
public static String URL = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
||||
// 编码
|
||||
|
@ -1,14 +1,30 @@
|
||||
package cn.czyx007.mt.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
@ -34,4 +50,36 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
||||
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
// 解决jackson2无法反序列化LocalDateTime的问题
|
||||
//LocalDatetime序列化
|
||||
JavaTimeModule timeModule = new JavaTimeModule();
|
||||
timeModule.addDeserializer(LocalDate.class,
|
||||
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
timeModule.addDeserializer(LocalDateTime.class,
|
||||
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
timeModule.addSerializer(LocalDate.class,
|
||||
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
timeModule.addSerializer(LocalDateTime.class,
|
||||
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
om.registerModule(timeModule);
|
||||
|
||||
//设置GenericJackson2JsonRedisSerializer可以将R类的对象类型也能进行JSON保存
|
||||
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||
GenericJackson2JsonRedisSerializer gen = new GenericJackson2JsonRedisSerializer(om);
|
||||
|
||||
//配置序列化
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
||||
RedisCacheConfiguration redisCacheConfiguration = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(gen));
|
||||
return RedisCacheManager
|
||||
.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
|
||||
.cacheDefaults(redisCacheConfiguration).build();
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -47,6 +49,7 @@ public class SetmealController {
|
||||
private DishService dishService;
|
||||
|
||||
//添加套餐信息
|
||||
@CacheEvict(value = "setmealCache", allEntries = true)
|
||||
@PostMapping
|
||||
public R<String> saveSetmealDish(@RequestBody SetmealDTO setmealDTO){
|
||||
setmealService.saveSetmealDish(setmealDTO);
|
||||
@ -127,6 +130,7 @@ public class SetmealController {
|
||||
// List<Setmeal> list = setmealService.list(lqw);
|
||||
// return R.success(list);
|
||||
// }
|
||||
@Cacheable(value = "setmealCache", key = "#setmeal.categoryId + '_' + #setmeal.status")
|
||||
public R<List<Setmeal>> list(Setmeal setmeal){
|
||||
LambdaQueryWrapper<Setmeal> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(Setmeal::getCategoryId, setmeal.getCategoryId())
|
||||
|
Loading…
x
Reference in New Issue
Block a user