标签:图片 ESS connector interface amp ace image meta mapping
实现步骤如下:
1.添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mybatisPlus 核心库 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
<!-- thymeleaf模板引擎 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.41</version>
</dependency>
<!-- 引入阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--mybatis-plus 代码生成器依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1.tmp</version>
</dependency>
<!-- swagger 依赖 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>RELEASE</version>
</dependency>
<!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.4.0</version>
</dependency>
<!-- thymeleaf模板引擎和shiro框架的整合 -->
<dependency>
<groupId>com.github.theborakompanioni</groupId>
<artifactId>thymeleaf-extras-shiro</artifactId>
<version>2.0.0</version>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.22</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.22</version>
</dependency>
<!--json jar相关jar包-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.23</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.业务service层如下:
package com.ckf.springboot_mysql_redis.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ckf.springboot_mysql_redis.entity.Users;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ckf.springboot_mysql_redis.model.ResultFormat;
import io.swagger.models.auth.In;
/**
* <p>
* 服务类
* </p>
*
* @author 安详的苦丁茶
* @since 2020-05-02
*/
public interface UsersService extends IService<Users> {
/**
* 全查询用户信息
*
* @return
*/
IPage<Users> selectUsersList(Page<Users> page);
/**
* 添加用户
*
* @param users
* @return
*/
ResultFormat saveUsers(Users users);
/**
* 修改用户
*
* @param users
* @return
*/
Integer updateUsers(Users users);
/**
* 删除用户
*
* @param userId
* @return
*/
Integer deleteUsersId(Integer userId);
}
3. service实现层如下:
/**
* 修改
*
* @param users
* @return
*/
@Override
public Integer updateUsers(Users users) {
logger.info("-----------------进入service实现层 修改用户信息-----------------");
/**
* 查询标签名称是否存在
* 如果存在那就返回提示已经存在
* 如果不存在那就修改
*/
if (users != null) {
if (users.getUserId() != null && !users.getUserName().isEmpty()) {
Users pgLabelsByIdInfo = usersMapper.selectById(users.getUserId());
AbstractWrapper wrapper = new QueryWrapper();
wrapper.eq("user_name", users.getUserName());
Users pgLabelsByNameInfo = usersMapper.selectOne(wrapper);
/**
* 如果通过id查询的用户信息与前台传过来的名称一致
* 可修改其它数据
*/
if (pgLabelsByIdInfo != null) {
logger.info("pgLabelsByIdInfo={}", pgLabelsByIdInfo);
if (pgLabelsByIdInfo.getUserName().equals(users.getUserName())) {
Integer updateById = usersMapper.updateById(users);
if (updateById > 0) {
redisUtil.set("users:" + users.getUserId(), users);
return 200;
}
}
}
/**
* 从前台传过来的用户名称与id查询的名称不一致
* 再通过名称查询的数据为空就可以修改
*/
if (pgLabelsByNameInfo != null) {
logger.info("pgLabelsByNameInfo={}", pgLabelsByNameInfo);
if (!pgLabelsByNameInfo.getUserName().equals(pgLabelsByIdInfo.getUserName())) {
return 101;
}
}
}
}
/**
* 如果用户名名称不一致就修改成 不存在的用户名称
*/
Integer updateById = usersMapper.updateById(users);
if (updateById > 0) {
redisUtil.set("label:" + users.getUserName(), users);
return 200;
}
return 100;
}
4.controller层如下:
/**
* 修改用户信息
*
* @param users
* @return
*/
@ApiOperation("修改用户信息接口")
@PutMapping("/update")
@ResponseBody
public ResultFormat updatePgSorts(Users users) {
users.getRegisterTime();
users.setUpdateTime(TimeUtitl.dateTime());
Integer insert = usersService.updateUsers(users);
if (insert == 101) {
logger.info("用户名已存在");
return ResultUtil.error(101, "用户名已经存在");
}
if (insert == 200) {
logger.info("修改成功");
return ResultUtil.success();
}
return ResultUtil.error(100, "修改失败");
}
效果图如下:
修改:
首页:
码云地址:https://gitee.com/ckfeng/springboot_mysql_redis.git
修改逻辑问题出来方案(在判断用户名相同的同时,在执行修改用户信息时如果用户名相同可以修改其它数据,但是用户名不作为修改)
标签:图片 ESS connector interface amp ace image meta mapping
原文地址:https://www.cnblogs.com/ckfeng/p/12943636.html