Commit 085f39e2 by 共享中心代码生成

Merge branch 'new-strut' into 'master'

New strut

See merge request !5
parents 31489dce 41d0a5a9
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*.iml *.iml
*.ipr *.ipr
*.lst *.lst
*.versionsBackup
### NetBeans ### ### NetBeans ###
/nbproject/private/ /nbproject/private/
......
# 简介 # 一、简介 ***
Matrix-sample是matrix组件的示例项目,包括redis、rocketmq等中间件以及提供通用util工具类使用方式等 Matrix-sample是matrix组件的示例项目,包括redis、rocketmq等中间件以及提供通用util工具类使用方式等
***
\ No newline at end of file
## 1.模块说明
- matrix-sample-xxx-biz为业务的实现模块,公共模块
- matrix-sample-xxx-spring为传统的spring项目的demo,主要参考如何进行配置和使用
- matrix-sample-xxx-springboot为springboot的示例
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo</artifactId> <artifactId>matrix-sample-dubbo</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo</artifactId> <artifactId>matrix-sample-dubbo</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo</artifactId> <artifactId>matrix-sample-dubbo</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo-springboot</artifactId> <artifactId>matrix-sample-dubbo-springboot</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo-springboot</artifactId> <artifactId>matrix-sample-dubbo-springboot</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-dubbo</artifactId> <artifactId>matrix-sample-dubbo</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-api</artifactId> <artifactId>matrix-sample-dubbo-api</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-dubbo-biz</artifactId> <artifactId>matrix-sample-dubbo-biz</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-hbase</artifactId> <artifactId>matrix-sample-hbase</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,15 +5,37 @@ ...@@ -5,15 +5,37 @@
<parent> <parent>
<artifactId>matrix-sample-hbase</artifactId> <artifactId>matrix-sample-hbase</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-hbase-starter</artifactId> <artifactId>matrix-sample-hbase-springboot</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-bigdata-hbase-starter</artifactId> <artifactId>matrix-bigdata-hbase-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core-asl</artifactId>
<groupId>org.codehaus.jackson</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-to-slf4j</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
......
...@@ -88,8 +88,8 @@ public class SimpleHBase implements InitializingBean { ...@@ -88,8 +88,8 @@ public class SimpleHBase implements InitializingBean {
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
// createTable(); createTable();
// put(); put();
get(); get();
} }
} }
...@@ -3,7 +3,6 @@ spring: ...@@ -3,7 +3,6 @@ spring:
name: matrix-bigdata-demo name: matrix-bigdata-demo
server: server:
port: 6080 port: 6080
hbase: hbase:
zookeeper: zookeeper:
quorum: 10.4.3.236:2181,10.4.3.237:2181,10.4.3.235:2181 quorum: 172.17.105.72:2181
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
<?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">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-biz</artifactId>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.22</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-core</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
package com.secoo.mall.mybatis.bean.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import com.secoo.mall.common.util.colletion.CollectionUtil;
import com.secoo.mall.common.util.json.FastJsonUtil;
import com.secoo.mall.common.util.string.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
//@ApiModel(value = "应用详细信息", description = "作用于project对象")
@Data
public class Project extends AbsBaseBean {
@ApiModelProperty(value = "应用id")
private Long id;
@ApiModelProperty(value = "仓库id")
private Long repositoryId;
@ApiModelProperty(value = "树id")
private Long opsTreeId;
@ApiModelProperty(value = "应用唯一标识")
private String name;
@ApiModelProperty(value = "应用中文名称")
private String cnName;
/**
* 如果sorce唯一用时间戳创建编码
*/
@ApiModelProperty(value = "应用编码")
private String code;
@ApiModelProperty(value = "应用等级:1-10,数值越大等级越低")
private Integer level;
/**
* 冗余字段
*/
@ApiModelProperty(value = "分组", position = 30)
private String groupName;
/**
* 冗余字段
*/
@ApiModelProperty(value = "gitlab地址", position = 40)
private String gitUrl;
/**
* 冗余字段
*/
@ApiModelProperty(value = "开发语言:1.java;2.lua;10、其他", position = 50)
private Integer language;
@JSONField(serialize = false)
private String tags;
@ApiModelProperty(value = "标签tags的参数形式")
@TableField(exist = false)
private List<String> tagList;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "状态:0、删除 1、正常;")
private Integer status;
@ApiModelProperty(value = "负责人id")
private Long owner;
@ApiModelProperty(value = "负责人")
private String ownerName;
@ApiModelProperty(value = "创建人id")
private Long creater;
@ApiModelProperty(value = "创建人")
private String createrName;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
public List<String> getTagList() {
if (StringUtil.isNotEmpty(this.tags)) {
tagList = FastJsonUtil.toList(this.tags);
}
return tagList;
}
public void setTagList(List<String> tagList) {
if (CollectionUtil.isNotEmpty(tagList)) {
String tags = FastJsonUtil.toString(tagList);
this.setTags(tags);
}
this.tagList = tagList;
}
}
package com.secoo.mall.mybatis.bean.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
//@ApiModel(value = "用户登录信息", description = "作用于user对象")
public class User extends AbsBaseBean {
@ApiModelProperty(value = "用户id")
private Long id;
@ApiModelProperty(value = "用户名")
private String name;
@ApiModelProperty(value = "中文用户名")
private String cnName;
@ApiModelProperty(value = "工号")
private String workNum;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "角色类型:1、admin;2、owner;3、dev;4、guest")
private Integer roleType;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "状态:0、删除 1、正常;")
private Integer status;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getEmail() {
return email;
}
public String getMobile() {
return mobile;
}
public String getRemark() {
return remark;
}
public Integer getStatus() {
return status;
}
public void setEmail(String email) {
this.email = email;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setRemark(String remark) {
this.remark = remark;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCnName() {
return cnName;
}
public void setCnName(String cnName) {
this.cnName = cnName;
}
public Integer getRoleType() {
return roleType;
}
public void setRoleType(Integer roleType) {
this.roleType = roleType;
}
public String getWorkNum() {
return workNum;
}
public void setWorkNum(String workNum) {
this.workNum = workNum;
}
}
\ No newline at end of file
package com.secoo.mall.mybatis.bean.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
//@ApiModel(value = "用户应用关联关系表", description = "作用于user和project对象")
@Data
public class UserProjectRelation extends AbsBaseBean {
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "用户id")
private Long userId;
@ApiModelProperty(value = "应用id")
private Long projectId;
//冗余字段
@ApiModelProperty(value = "仓库id")
private Long repositoryId;
@ApiModelProperty(value = "角色类型:10、admin;20、owner;30、dev;40、guest")
private Integer roleType;
@ApiModelProperty(value = "接收报警标识。0、不接收,1、接收")
private Integer warnFlag;
@JSONField(serialize = false)
@ApiModelProperty(value = "报警接收渠道。用逗号分隔")
private String warnChannels;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
}
\ No newline at end of file
package com.secoo.mall.mybatis.bean.vo;
import com.secoo.mall.common.util.colletion.CollectionUtil;
import com.secoo.mall.common.util.json.FastJsonUtil;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.mybatis.bean.entity.UserProjectRelation;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class UserProjectRelationVo extends UserProjectRelation {
@ApiModelProperty(value = "用户Id")
private Long userId;
@ApiModelProperty(value = "用户名")
private String userName;
@ApiModelProperty(value = "中文用户名")
private String userCnName;
@ApiModelProperty(value = "工号")
private String workNum;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "用于转换数组")
private List<Integer> warnChannelList;
}
\ No newline at end of file
package com.secoo.mall.mybatis.config;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.secoo.mall.datasource.bean.MatrixDataSource;
import com.secoo.mall.mybatis.bean.MatrixMybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
/**
* @Description:
* @Copyright: Copyright (c) 2020 ALL RIGHTS RESERVED.
* @Company: Secoo
* @Author: qiuwei.li
* @CreateDate: 2020/4/8 10:27
* @UpdateDate: 2020/4/8 10:27
* @UpdateRemark: init
* @Version: 1.0
* @menu ${description}
* @note 如果数据源中不存在多个sessionfactory示例,可以在mapper接口类直接使用@Mapper注解
*/
@Configuration
@MapperScan(value = "com.secoo.mall.mybatis.dao.mapper",sqlSessionFactoryRef = "demoSqlSessionFactory")
public class DataConfig {
/**
* 定义数据源
*
* @return
*/
@Bean
public DataSource demoDataSource() {
return new MatrixDataSource("default");
}
@Bean
public SqlSessionFactory demoSqlSessionFactory(DataSource demoDataSource, MatrixMybatisGlobalConfig globalConfig, MybatisConfiguration mybatisConfiguration) throws Exception {
MatrixMybatisSqlSessionFactoryBean factory = new MatrixMybatisSqlSessionFactoryBean();
factory.setConfiguration(mybatisConfiguration);
factory.setGlobalConfig(globalConfig);
factory.setDataSource(demoDataSource);
return factory.getObject();
}
}
package com.secoo.mall.mybatis.dao.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.mybatis.bean.entity.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
public interface UserMapper extends BaseMapper<User> {
default User getByEmail(String email) {
return this.selectOne(new QueryWrapper<User>().lambda().eq(User::getEmail, email).last("limit 1"));
}
default IPage<User> search(User user, Page page) {
LambdaQueryWrapper<User> queryWrapper = new QueryWrapper<User>().lambda();
if (StringUtil.isNotEmpty(user.getName()) || StringUtil.isNotEmpty(user.getCnName()) || StringUtil.isNotEmpty(user.getWorkNum())) {
queryWrapper.and(wapper -> wapper.like(User::getName, user.getName())
.or().like(User::getCnName, user.getCnName())
.or().like(User::getWorkNum, user.getWorkNum()));
}
return this.selectPage(page, queryWrapper);
}
}
\ No newline at end of file
package com.secoo.mall.mybatis.dao.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.secoo.mall.mybatis.bean.entity.UserProjectRelation;
import com.secoo.mall.mybatis.bean.vo.UserProjectRelationVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UserProjectRelationMapper extends BaseMapper<UserProjectRelation> {
IPage<UserProjectRelationVo> searchByProjectId(Page<UserProjectRelationVo> page, @Param("projectId") Long projectId, @Param("relationVo") UserProjectRelationVo userProjectRelationVo);
}
\ No newline at end of file
<?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="com.secoo.mall.mybatis.dao.mapper.UserProjectRelationMapper">
<sql id="base_feild_List">
id, user_id , project_id, update_time, create_time
</sql>
<sql id="user_map_field_List">
b.id,a.id as userId, a.name as userName,a.work_num,a.cn_name as userCnName,a.email ,a.mobile,b.role_type as roleType,b.warn_flag ,b.warn_channels
</sql>
<sql id="search_where">
<where>
<if test="relationVo.userName != null and relationVo.userName != ''">
AND a.name =TRIM(#{relationVo.userName,jdbcType=VARCHAR})
</if>
</where>
</sql>
<select id="searchByProjectId" resultType="com.secoo.mall.mybatis.bean.vo.UserProjectRelationVo">
select
<include refid="user_map_field_List"/>
from user a inner join user_project_relation b on a.id=b.user_id and b.project_id=#{projectId}
<include refid="search_where"/>
</select>
</mapper>
\ No newline at end of file
<?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">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-spring</artifactId>
</project>
\ No newline at end of file
<?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">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-springboot</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-mybatis-biz</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<!--接入日志组件-->
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.mybatis;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.secoo.mall.common.core.bean.ReqPage;
import com.secoo.mall.mybatis.bean.entity.User;
import com.secoo.mall.mybatis.bean.entity.UserProjectRelation;
import com.secoo.mall.mybatis.bean.vo.UserProjectRelationVo;
import com.secoo.mall.mybatis.dao.mapper.UserMapper;
import com.secoo.mall.mybatis.dao.mapper.UserProjectRelationMapper;
import com.secoo.mall.mybatis.util.PageUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import javax.annotation.Resource;
/**
* @Description: 支持特性:
* <p>1.控制台直接打印sql</p>
* <p>2.分页封装</p>
* <p>3.关联表查询</p>
* @Author: liqiuwei
* @UpdateUser: liqiuwei
* @Param:
* @Return:
* @CreateDate: 2020/4/7 10:45
* @UpdateDate: 2020/4/7 10:45
* @version: 1.0
* @status: done
*/
@SpringBootApplication
//@MapperScan("com.secoo.mall.mybatis.dao.mapper")
public class MybatisSampleApplication implements ApplicationRunner {
@Resource
private UserMapper userMapper;
@Resource
private UserProjectRelationMapper userProjectRelationMapper;
public static void main(String[] args) {
new SpringApplicationBuilder(MybatisSampleApplication.class)
.run(args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
// testGetByEmail("liqiuwei@secoo.com");
//测试查询分页
UserProjectRelationVo vo=new UserProjectRelationVo();
vo.setUserName("liqiuwei");
testSearch(1262L,vo,new ReqPage(0L,10L));
// testSave();
}
/**
* @Description: 按照固定条件查询,如邮箱
* @Author: liqiuwei
* @UpdateUser: liqiuwei
* @Param: [email] 邮箱
* @Return: {@link User}
* @CreateDate: 2020/4/7 10:15
* @UpdateDate: 2020/4/7 10:15
* @version: 1.0
* @status: done
*/
public User testGetByEmail(String email) {
User u1 = userMapper.getByEmail(email);
System.out.println(u1);
return u1;
}
/**
* @Description: 按照id进行查询
* @Author: liqiuwei
* @UpdateUser: liqiuwei
* @Param: [id]
* @Return: com.secoo.mall.mybatis.bean.entity.User
* @CreateDate: 2020/4/7 10:40
* @UpdateDate: 2020/4/7 10:40
* @version: 1.0
* @status: done
*/
public User testGetById(Long id) {
User u1 = userMapper.selectById(id);
System.out.println(u1);
return u1;
}
/***
* @Description:
* @Author: liqiuwei
* @UpdateUser: liqiuwei
* @Param: [id, reqPage] reqPage 为controller层传输参数
* @Return: com.secoo.mall.mybatis.bean.entity.User
* @CreateDate: 2020/4/7 11:31
* @UpdateDate: 2020/4/7 11:31
* @version: 1.0
* @status: done
*/
public IPage testSearch(Long id, UserProjectRelationVo userProjectRelationVo, ReqPage reqPage) {
Page<UserProjectRelationVo> page = PageUtil.createPage(reqPage);
IPage<UserProjectRelationVo> pageData = userProjectRelationMapper.searchByProjectId(page, id, userProjectRelationVo);
System.out.println(pageData.getRecords().size());
return pageData;
}
/**
* @Description: 保存数据.由于属性createTime使用@TableField(fill = FieldFill.INSERT),框架通过拦截器自动进行赋值
* @Author: liqiuwei
* @UpdateUser: liqiuwei
* @Param: []
* @Return: com.secoo.mall.mybatis.bean.entity.UserProjectRelation
* @CreateDate: 2020/4/8 9:56
* @UpdateDate: 2020/4/8 9:56
* @version: 1.0
* @status: done
*/
public UserProjectRelation testSave() {
UserProjectRelation relation = new UserProjectRelation();
relation.setProjectId(1261L);
relation.setUserId(1L);
userProjectRelationMapper.insert(relation);
return relation;
}
}
<?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">
<parent>
<artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-sample-mybatis-spring</module>
<module>matrix-sample-mybatis-springboot</module>
<module>matrix-sample-mybatis-biz</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-mybatis-biz</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
...@@ -5,11 +5,21 @@ ...@@ -5,11 +5,21 @@
<parent> <parent>
<artifactId>matrix-sample-redis</artifactId> <artifactId>matrix-sample-redis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis-biz</artifactId> <artifactId>matrix-sample-redis-biz</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
/**
* Created by Administrator on 2018/1/16.
*/
package com.secoo.mall.redis;
import lombok.Data;
import java.util.Date;
/**
* test
*
* @author Administrator
* @create 2018-01-16 11:19
**/
@Data
public class Person {
/**
* 用户ID
*/
private Long id;
/**
* 用户登录名
*/
private String loginName;
/**
* 用户名
*/
private String userName;
/**
* 部门名称
*/
private String deptName;
/**
* 操作时间
*/
private Date operDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public Date getOperDate() {
return operDate;
}
public void setOperDate(Date operDate) {
this.operDate = operDate;
}
}
/**
* Created by Administrator on 2018/1/17.
*/
package com.secoo.mall.redis;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* aa
*
* @author Administrator
* @create 2018-01-17 13:47
**/
@Service
public class PersonService {
private final static Logger logger = LoggerFactory.getLogger(PersonService.class);
public Person get(Long id) {
logger.info("get;{}", id);
Person p = new Person();
p.setOperDate(new Date());
// p.setDeptName("ddd");
p.setId(id);
return p;
}
}
<?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">
<parent>
<artifactId>matrix-sample-redis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis-spring</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-core</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-redis-biz</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.redis;
import com.secoo.mall.redis.helper.RedisHelper;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* Created by Administrator on 2018/1/15.
*/
//@ContextConfiguration({"classpath*:spring-jedis-cluster-config-sample.xml"})
@ContextConfiguration({"classpath*:spring-lettuce-cluster-config-sample.xml"})
public class RedisClusterTest extends AbstractJUnit4SpringContextTests {
@Resource
private RedisHelper redisClusterHelper;
@Resource
private PersonService personService;
@Test
public void testSet() throws InterruptedException {
redisClusterHelper.set("aaa", "bbb");
String ret = redisClusterHelper.get("aaa", String.class);
Assert.assertEquals("bbb", ret);
redisClusterHelper.set("aaa", "ccc", 2l);
ret = redisClusterHelper.get("aaa", String.class);
Assert.assertEquals("ccc", ret);
Thread.sleep(3000l);
ret = redisClusterHelper.get("aaa", String.class);
Assert.assertNull(ret);
}
@Test
public void testSet2() throws InterruptedException {
//批量设置测试
Map<String, String> dtos1 = new HashMap<>();
for (int i = 0; i < 100; i++) {
dtos1.put("testKey" + i, "testValue" + i);
}
long st = System.currentTimeMillis();
redisClusterHelper.sets(dtos1, 1000L);
long ed = System.currentTimeMillis();
System.out.println("耗时:" + (ed - st));
for (int i = 0; i < 100; i++) {
dtos1.put("testKeyi" + i, "testValue" + i);
}
st = System.currentTimeMillis();
redisClusterHelper.sets(dtos1, 1000L);
ed = System.currentTimeMillis();
System.out.println("耗时:" + (ed - st));
List<String> list = redisClusterHelper.gets(new ArrayList<String>(dtos1.keySet()), String.class);
System.out.println(list);
Map<String, String> dtos2 = new HashMap<>();
for (int i = 0; i < 1000; i++) {
dtos2.put("testKey2:" + i, "testValue2:" + i);
}
st = System.currentTimeMillis();
redisClusterHelper.pipelineSets(dtos2, 1000L);
ed = System.currentTimeMillis();
System.out.println("耗时2:" + (ed - st));
}
/**
* 测试多线程
*/
@Test
public void testThreads() throws InterruptedException {
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 0; i < 20; i++) {
final int j = i;
executorService.submit(new Runnable() {
@Override
public void run() {
Map<String, String> dtos1 = new HashMap<>();
for (int i = 0; i < 100; i++) {
dtos1.put("testKey" + j + ":" + i, "testValue" + i);
}
long st = System.currentTimeMillis();
redisClusterHelper.sets(dtos1, 1000L);
long ed = System.currentTimeMillis();
System.out.println("耗时:" + j + ":" + (ed - st));
}
});
}
Thread.sleep(5000L);
for (int i = 20; i < 40; i++) {
final int j = i;
executorService.submit(new Runnable() {
@Override
public void run() {
Map<String, String> dtos1 = new HashMap<>();
for (int i = 0; i < 100; i++) {
dtos1.put("testKey" + j + ":" + i, "testValue" + i);
}
long st = System.currentTimeMillis();
redisClusterHelper.sets(dtos1, 1000L);
long ed = System.currentTimeMillis();
System.out.println("耗时:" + j + ":" + (ed - st));
}
});
}
Thread.sleep(5000L);
}
@Test
public void testGet() {
Person p = new Person();
p.setDeptName("hhhhhh");
p.setOperDate(new Date());
redisClusterHelper.set("zhangsan111", p);
Person o = redisClusterHelper.get("zhangsan111", Person.class);
Assert.assertEquals("hhhhhh", o.getDeptName());
}
@Test
public void testGet2() throws InterruptedException {
//批量设置测试
Map<String, String> dtos2 = new HashMap<>();
for (int i = 0; i < 100; i++) {
dtos2.put("testKey2:" + i, "testValue2:" + i);
}
long st = System.currentTimeMillis();
redisClusterHelper.pipelineSets(dtos2, 1000L);
long ed = System.currentTimeMillis();
System.out.println("耗时2:" + (ed - st));
st = System.currentTimeMillis();
List<String> vList = redisClusterHelper
.pipelineGets(new ArrayList<String>(dtos2.keySet()), String.class);
ed = System.currentTimeMillis();
System.out.println("耗时2:" + (ed - st));
System.out.println(vList);
}
@Test
public void testH() {
Person p = new Person();
p.setDeptName("hhhhhh");
p.setOperDate(new Date());
redisClusterHelper.hSet("hsetKey", "f1", p);
Person person = redisClusterHelper.hGet("hsetKey", "f1", Person.class);
Assert.assertEquals("hhhhhh", p.getDeptName());
}
@Test
public void testAnn() {
Person person = personService.get(1L);
System.out.println(person);
person = personService.get(1L);
System.out.println(person);
}
@Test
public void testIncr() {
redisClusterHelper.set("incyKey", 1);
System.out.println(redisClusterHelper.get("incyKey", Long.class));
redisClusterHelper.incr("incyKey", 1);
System.out.println(redisClusterHelper.get("incyKey", Long.class));
redisClusterHelper.incr("incyKey", 10);
System.out.println(redisClusterHelper.get("incyKey", Long.class));
}
@Test
public void testTtl() throws InterruptedException {
redisClusterHelper.set("incyKey", 1, 100);
System.out.println(redisClusterHelper.ttl("incyKey", TimeUnit.MILLISECONDS));
Thread.sleep(444L);
System.out.println(redisClusterHelper.ttl("incyKey", TimeUnit.MILLISECONDS));
Thread.sleep(444L);
System.out.println(redisClusterHelper.exists("incyKey"));
System.out.println(redisClusterHelper.exists("incyKey111"));
}
@Test
public void testHmset() {
Map<String, Integer> vv = new HashMap<>();
vv.put("one", 1);
vv.put("two", 2);
redisClusterHelper.hMSet("hmsetNumKey", vv);
Map<String, Integer> ret = redisClusterHelper
.hMGet("hmsetNumKey", new String[]{"one", "two"}, Integer.class);
System.out.println(ret);
ret = redisClusterHelper
.hGetAll("hmsetNumKey", String.class, Integer.class);
System.out.println(ret);
}
}
package com.secoo.mall.redis;
import com.secoo.mall.redis.helper.RedisHelper;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
/**
* Created by Administrator on 2018/1/15.
*/
//@ContextConfiguration({"classpath*:spring-jedis-alone-config-sample.xml"})
@ContextConfiguration({"classpath*:spring-lettuce-alone-config-sample.xml"})
public class RedisTest extends AbstractJUnit4SpringContextTests {
@Resource
private RedisHelper redisHelper;
@Test
public void testSet() throws InterruptedException {
redisHelper.set("aaa", "bbb");
String ret = redisHelper.get("aaa", String.class);
Assert.assertEquals("bbb", ret);
redisHelper.set("aaa", "ccc", 2l);
ret = redisHelper.get("aaa", String.class);
Assert.assertEquals("ccc", ret);
Thread.sleep(3000l);
ret = redisHelper.get("aaa", String.class);
Assert.assertNull(ret);
//对实体对象操作
Person person=new Person();
Date date=new Date();
person.setOperDate(date);
person.setLoginName("李四");
redisHelper.set("person03",person);
Assert.assertEquals("李四",redisHelper.get("person03",Person.class).getLoginName());
Assert.assertEquals(date,person.getOperDate());
}
@Test
public void testIncr() {
redisHelper.set("incyKey01", 1);
redisHelper.incr("incyKey01",2);
System.out.println(redisHelper.get("incyKey01", Long.class));
}
/**
* 其他方法使用详见 @com.secoo.mall.redis.RedisClusterTest
*/
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.secoo.archetype" level="DEBUG" />
<Logger name="org.springframework.beans.factory" level="INFO" />
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
redis.maxRedirects=5
redis.host1=dev01-rediscluster01.secoolocal.com
redis.port1=7001
redis.host2=dev01-rediscluster01.secoolocal.com
redis.port2=7002
redis.host3=dev01-rediscluster02.secoolocal.com
redis.port3=7001
redis.host4=dev01-rediscluster02.secoolocal.com
redis.port4=7002
redis.host5=dev01-rediscluster03.secoolocal.com
redis.port5=7001
redis.host6=dev01-rediscluster03.secoolocal.com
redis.port6=7002
# connnet pool
redis.maxIdle=50
redis.maxTotal=100
redis.minIdle=10
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:property-placeholder ignore-unresolvable="true"
location="classpath:redis-cluster.properties"/>
<context:component-scan base-package="com.secoo.mall"></context:component-scan>
<!--单主机配置-->
<bean id="redisAloneConfiguration" class="org.springframework.data.redis.connection.RedisStandaloneConfiguration">
<property name="hostName" value="127.0.0.1"/>
<property name="port" value="6379"/>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}"/>
<property name="maxTotal" value="${redis.maxTotal}"/>
<property name="minIdle" value="${redis.minIdle}"/>
</bean>
<bean id="jeidsConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg ref="redisAloneConfiguration"/>
<constructor-arg ref="jedisPoolConfig"/>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jeidsConnectionFactory"/>
</bean>
<bean id="redisHelper" class="com.secoo.mall.redis.helper.RedisHelper">
<constructor-arg name="redisTemplate" ref="redisTemplate"/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer-->
<!--<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
</beans>
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-txs-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:property-placeholder ignore-unresolvable="true"
location="classpath:redis-cluster.properties"/>
<context:component-scan base-package="com.secoo.mall"></context:component-scan>
<bean id="redisClusterConfiguration"
class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<property name="maxRedirects" value="${redis.maxRedirects}"></property>
<property name="clusterNodes">
<set>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host1}"></constructor-arg>
<constructor-arg name="port" value="${redis.port1}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host2}"></constructor-arg>
<constructor-arg name="port" value="${redis.port2}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host3}"></constructor-arg>
<constructor-arg name="port" value="${redis.port3}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host4}"></constructor-arg>
<constructor-arg name="port" value="${redis.port4}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host5}"></constructor-arg>
<constructor-arg name="port" value="${redis.port5}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host6}"></constructor-arg>
<constructor-arg name="port" value="${redis.port6}"></constructor-arg>
</bean>
</set>
</property>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}"/>
<property name="maxTotal" value="${redis.maxTotal}"/>
<property name="minIdle" value="${redis.minIdle}"/>
</bean>
<bean id="jeidsConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg ref="redisClusterConfiguration"/>
<constructor-arg ref="jedisPoolConfig"/>
</bean>
<bean id="redisClusterTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jeidsConnectionFactory"/>
</bean>
<bean id="secooRedisTemplate" class="com.secoo.mall.redis.helper.RedisHelper">
<constructor-arg name="redisTemplate" ref="redisClusterTemplate"/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer -->
<!-- <property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
</beans>
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:property-placeholder ignore-unresolvable="true"
location="classpath:redis-cluster.properties"/>
<context:component-scan base-package="com.secoo.mall"></context:component-scan>
<aop:config proxy-target-class="true"></aop:config>
<aop:aspectj-autoproxy/>
<!--单主机配置-->
<bean id="redisAloneConfiguration" class="org.springframework.data.redis.connection.RedisStandaloneConfiguration">
<property name="hostName" value="127.0.0.1"/>
<property name="port" value="6379"/>
</bean>
<bean id="lettuceConnectionFactory"
class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory">
<constructor-arg ref="redisAloneConfiguration"/>
</bean>
<bean id="rediredisAloneConfigurationTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="lettuceConnectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
</bean>
<bean id="redisHelper" class="com.secoo.mall.redis.helper.RedisHelper">
<constructor-arg name="redisTemplate" ref="rediredisAloneConfigurationTemplate"/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer ,不指定可以使用默认的-->
<!-- <property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
</beans>
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-txs-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:property-placeholder ignore-unresolvable="true"
location="classpath:redis-cluster.properties"/>
<context:component-scan base-package="com.secoo.mall"></context:component-scan>
<aop:config proxy-target-class="true"></aop:config>
<aop:aspectj-autoproxy/>
<bean id="redisClusterConfiguration"
class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<property name="maxRedirects" value="${redis.maxRedirects}"></property>
<property name="clusterNodes">
<set>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host1}"></constructor-arg>
<constructor-arg name="port" value="${redis.port1}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host2}"></constructor-arg>
<constructor-arg name="port" value="${redis.port2}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host3}"></constructor-arg>
<constructor-arg name="port" value="${redis.port3}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host4}"></constructor-arg>
<constructor-arg name="port" value="${redis.port4}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host5}"></constructor-arg>
<constructor-arg name="port" value="${redis.port5}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisClusterNode">
<constructor-arg name="host" value="${redis.host6}"></constructor-arg>
<constructor-arg name="port" value="${redis.port6}"></constructor-arg>
</bean>
</set>
</property>
</bean>
<!--<bean id="clientResources" class="com.lambdaworks.redis.resource.DefaultClientResources"-->
<!--factory-method="create">-->
<!--</bean>-->
<bean id="lettuceConnectionFactory"
class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory">
<constructor-arg ref="redisClusterConfiguration"/>
<!--<property name="clientResources" ref="clientResources"/>-->
</bean>
<!--可以注入一个mapper,默认的序列化会序列化类名-->
<!--ObjectMapper mapper = new ObjectMapper();-->
<!--mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);-->
<!--//日期格式-->
<!--mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));-->
<!--//null不序列化 减小报文大小-->
<!--mapper.setSerializationInclusion(Include.NON_NULL);-->
<bean id="redisCluserTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="lettuceConnectionFactory"/>
</bean>
<bean id="redisClusterHelper" class="com.secoo.mall.redis.helper.RedisHelper">
<constructor-arg name="redisTemplate" ref="redisCluserTemplate"/>
<!-- 序列化方式 key/hashKey采用StringRedisSerializer ,也可以使用默认的-->
<!--<property name="keySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean
class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>-->
</bean>
</beans>
...@@ -5,11 +5,25 @@ ...@@ -5,11 +5,25 @@
<parent> <parent>
<artifactId>matrix-sample-redis</artifactId> <artifactId>matrix-sample-redis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-redis-starter</artifactId> <artifactId>matrix-sample-redis-starter</artifactId>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-redis-biz</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
package com.secoo.mall.redis;
import com.secoo.mall.redis.helper.RedisHelper;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import javax.annotation.Resource;
import java.util.Date;
@SpringBootApplication
public class RedisSampleApplication implements ApplicationRunner {
@Resource
private RedisHelper redisHelper;
@Resource
private RedisHelper productRedisHelper;
public static void main(String[] args) {
new SpringApplicationBuilder(RedisSampleApplication.class).run(args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
redisHelper.set("key01","word");
String key01 = redisHelper.get("key01",String.class);
Person person=new Person();
person.setId(2L);
// person.setDeptName("技术部");
person.setLoginName("zhangsan");
person.setOperDate(new Date());
redisHelper.set("person05",person);
//1.通过测试,Fastjson,对象缺少属性后支持序列化
System.out.println("person05::"+redisHelper.get("person05",Person.class).getLoginName());
productRedisHelper.set("p:01","帽子");
System.out.println("p:01=" +productRedisHelper.get("p:01",String.class));
}
}
package com.secoo.mall.redis.config;
import com.secoo.mall.redis.helper.RedisHelper;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
/**
* 多数据源配置
*/
@Configuration
@ConfigurationProperties(prefix = "redis.custom")
@Data
public class MuliRedisConfig {
public String host;
public Integer port;
/**
* 仅仅提供简单配置demo
*
* @return
*/
@Bean
public LettuceConnectionFactory productConnectionFactory() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(host, port);
return connectionFactory;
}
@Bean
public RedisTemplate productRedisTemplate(LettuceConnectionFactory productConnectionFactory){
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(productConnectionFactory);
return redisTemplate;
}
@Bean("productRedisHelper")
public RedisHelper productRedisHelper(RedisTemplate productRedisTemplate) {
return new RedisHelper(productRedisTemplate);
}
}
spring:
redis:
cluster:
nodes: dev01-rediscluster01.secoolocal.com:7001,dev01-rediscluster01.secoolocal.com:7002,dev01-rediscluster02.secoolocal.com:7001,dev01-rediscluster02.secoolocal.com:7002,dev01-rediscluster03.secoolocal.com:7001,dev01-rediscluster03.secoolocal.com:7002
timeout: 10000
# host: localhost
redis:
custom:
host: localhost
port: 6379
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -14,7 +14,38 @@ ...@@ -14,7 +14,38 @@
<modules> <modules>
<module>matrix-sample-redis-starter</module> <module>matrix-sample-redis-starter</module>
<module>matrix-sample-redis-biz</module> <module>matrix-sample-redis-biz</module>
<module>matrix-sample-redis-spring</module>
</modules> </modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-redis-biz</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
<!-- 推荐使用 lettuce -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-rocketmq</artifactId> <artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-rocketmq</artifactId> <artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-rocketmq</artifactId> <artifactId>matrix-sample-rocketmq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-rocketmq-biz</artifactId> <artifactId>matrix-sample-rocketmq-biz</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-xxl</artifactId> <artifactId>matrix-sample-xxl</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-xxl</artifactId> <artifactId>matrix-sample-xxl</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample-xxl</artifactId> <artifactId>matrix-sample-xxl</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-sample-xxl-biz</artifactId> <artifactId>matrix-sample-xxl-biz</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -8,18 +8,18 @@ ...@@ -8,18 +8,18 @@
<parent> <parent>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>matrix-sample</artifactId> <artifactId>matrix-sample</artifactId>
<version>2.0.1-SNAPSHOT</version>
<modules> <modules>
<module>matrix-sample-xxl</module> <module>matrix-sample-xxl</module>
<module>matrix-sample-dubbo</module> <module>matrix-sample-dubbo</module>
<module>matrix-sample-hbase</module> <module>matrix-sample-hbase</module>
<module>matrix-sample-rocketmq</module> <module>matrix-sample-rocketmq</module>
<module>matrix-sample-redis</module> <module>matrix-sample-redis</module>
<module>matrix-sample-mybatis</module>
</modules> </modules>
</project> </project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment