栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

gulimall记录https://note.youdao.com/s/8Y50kXqe

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

gulimall记录https://note.youdao.com/s/8Y50kXqe

JDK,JRE下载-----配置环境

mysql数据----配置环境

maven------方便拉取公司依赖 https://mvnrepository.com

VM:https://customerconnect.vmware.com/cn/downloads/#all_products

linux:https://linux.org

命令网址:linux ping 菜鸟教程

hostname node01

vi /etc/hostname

关机:shutdown -h now

鼠标问题:ctrl+alt

vi /etc/sysconfig/network-scripts/ifcfg-ens33 -----系统配置

systemctl restart network.service ------重启生效

systemctl status firewalld

9 systemctl disable firewalld

10 systemctl status firewalld

11 systemctl stop firewalld

12 systemctl status firewalld

vi /etc/selinux/config -----修改配置文件 i ---- 修改完----esc ----:wq

whereis

who

whoname

useradd libai -----添加新的连接用户

25 password libai

ssh 192.168.188.100 ----连接虚拟机

更改网络配置: cd /etc/sysconfig/network-scripts/

ls---下面有一个和服务地址相关的ifcfg-eth1 ---进行修改

bin:可执行文件。boot:引导分区 dev:设备信息 etc:系统配置文件

opt:软件安装目录 proc:进程 root:超级用户的家目录 run:运行时的环境变量

mv 2020中南大学研究生学位论文撰写规范及其样例.zip lunwen.zip ----修改文件名

mkdir -p shiren/{libai,lsy,lh} ------ shiren下面创建多个目录

rm -r shiren/ ---删除目录

rm xxx.conf ----删除文件

cp anaconda-ks.cfg /opt ----复制文件到opt

mkdir -p a/b 创建目录 当a不存在的时候也可以创建

rm -rf 目录名 强制删除目录且不需要提醒是否删除

touch 文件名 ----创建文件

mkdir 文件夹名=----创建文件夹

stat 文件名 -----查看文件的信息

ln -s yingjieshi slink -----创建软连接

ln yingjieshi hlink ----创建硬连接

cat 文件名 ----看内容

分页看文件内容

more 文件名

enter加载内容

b -----回退内容

q----退出

head -10 jingjinjiu ----查看前10行

tail -10 jingjinjiu ----查看最后10行

head -10 anaconda-ks.cfg | tail -1 ----查看指定的某一行

tail -F 文件名 ----监控文件信息

tail -f 文件名----佳农文件信息--重新创建新的同名文件不监控

find / -name baidu ---查找/ 下面文件baidu

编辑模式(每一个按键都有自己的处理方式)---输入模式(按什么内容输入什么内容)----命令模式(:set num)

文件传输:linux和window传输----xftp需要依赖软件

yum install lrzsz -y ----安装

rz------window上传到linux

sz----linux下载到本地

linux与linux之间的传输:

scp 源文件名 root@192.168.188.101:/opt/

scp root@192.168.188.100:/root/baidu /opt/

scp -r 文件夹 root@192.168.188.101:/opt/

文件大小:

df -h

du -h --max-depth=1 /

解压tar包

tar -zxvf 包名

压缩tar:

tar -zcf 别名.tar.gz 文件夹名

解压和压缩zip包

yum install zip unzip -y

压缩:

zip -r shiren.zip shiren

解压:

unzip zip包名

删除乱码的文件:

ls -i ------查看唯一ID

find -inum id号 -delete

解压中文zip包防止乱码:unzip -O gbk 2020中南大学研究生学位论文撰写规范及其样例.zip

修改域名:vi /etc/hosts

ifconfig --------需要安装yum install net-tools -y

netstat -r

ping node01

telnet 192.168.188.101 22 -----判断端口通不通

ps -ef | grep redis

ps -aux -----查看进程对内存的使用信息

kill -9 8609 ---杀死进程

echo $PATH -----环境变量

vm:

ifconfig---查询ip地址

docker exec -it mysql /bin/bash

cd /etc/mysql/

ls

cat my.cnf

docker images----镜像

docker ps ------正在运行的

docker restart redis/mysql 重启程序

docker update redis/mysql --restart=always =====自动重启

free -m ---查看可用内存

启动容器后如果没有正常启动可以docker ps -a查看,然后重新启动 docker start xxxx(id可以只输入前几个字母)

netstat -nlp | grep 3306

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip

nacos启动:bin目录下的startup.cmd

nacos:127.0.0.1:8848/nacos ---访问地址

mysql断电导致无法正常启动Ignoring the redo log due to missing MLOG:

docker logs -f xxxx(服务id)----查看日志

找到文件:find / -name '*_logfile*'--删除后重启

后端:

vm(linux)+docker+redis+mysql+springBoot+springCloudAlibaba(nacos:注册中心+配置中心,openfeign远程调用)

+postman(后端请求测试)+navicat(数据库客户端)+xshell(虚拟机客户端)或vagant+xftp(windos与linux文件传输)+

git代码托管(github平台)+逆向工程+人人开源

数据校验+全局异常处理+全局统一回复+全局跨域处理+枚举状态+VO(前端数据+响应数据实体)+TO(服务之间调用对象配置参数)+PO(数据库实体对象)+逻辑删除

ctrl+alt+l===格式化代码

前端:

vue+elementUI(参照elementUI官网进行开发、控制台进行调试)

alt+shift+f===格式化代码

跨域问题解决:Java解决跨域的三种方式_Pioneer-Sun的博客-CSDN博客_java 跨域(CorsWebFilter)

lambda表达式创建树形结构:

all.stream().filter(categoryEntity ->  categoryEntity.getParentCid() == root.getCatId()) .map(categoryEntity -> { categoryEntity.setChildren(getChildren(categoryEntity, all)); return categoryEntity; })  .sorted((menu1, menu2) -> (menu1.getSort() == null ? 0 : menu1.getSort()) - (menu2.getSort() == null ? 0 : menu2.getSort())) .collect(Collectors.toList());

前端地址和服务器地址不一致(端口号或其他后缀)如何进行映射:后端使用网关gateway进行路由配置:

1.添加网关依赖

 org.springframework.cloud spring-cloud-starter-gateway 

2.添加网关路由的配置信息

spring: cloud: gateway: routes: - id: baidu_route uri: https://www.baidu.com predicates: - Query=url,baidu - id: qq_route uri: https://www.qq.com predicates: - Query=url,qq - id: product_route uri: lb://gulimall-product predicates: - Path=/api/product @Configuration public class GulimalCorsConfiguration { @Bean public CorsWebFilter corsWebFilter(){ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedHeader("*"); corsConfiguration.addAllowedMethod("*"); corsConfiguration.addAllowedOrigin("*"); corsConfiguration.setAllowCredentials(true); source.registerCorsConfiguration(" @RefreshScope @RestController @RequestMapping("coupon/coupon") public class CouponController { @Autowired private CouponService couponService; @Value("${coupon.user.name}") private String userName; @Value("${coupon.user.age}") private Integer age; @RequestMapping("/test") public R test(){ return R.ok().put("name",userName).put("age",age); }

注意:如果配置中心和当前应用的配置文件中都配置了相同的项,优先使用配置中心的配置

nacos配置中心一般配置步骤:

1.新建命名空间(以服务名字命名最佳)

2.在配置列表中找到对应的命名空间并创建配置

Controller层参数校验异常统一处理

@Slf4j @RestControllerAdvice(basePackages = "com.atguigu.gulimall.product.controller") //要处理的位置 public class gulimallExceptionControllerAdvice { @ExceptionHandler(value = MethodArgumentNotValidException.class) public R handlerException(MethodArgumentNotValidException e){ log.error("异常信息:{ },异常类:{ }",e.getMessage(),e.getClass()); BindingResult bindingResult = e.getBindingResult(); Map map = new HashMap<>(); bindingResult.getFieldErrors().forEach((item)->{ String field = item.getField(); String message = item.getDefaultMessage(); map.put(field,message); }); return R.error(BizCodeEnum.VALID_EXCEPTION.getCode(),BizCodeEnum.VALID_EXCEPTION.getMsg()).put("data",map); } @ExceptionHandler(value = Throwable.class) public R exceptionHandler(Throwable e){ return R.error(BizCodeEnum.UNKNOW_EXCEPTION.getCode(),BizCodeEnum.UNKNOW_EXCEPTION.getMsg()); } }

状态吗及返回信息用枚举进行配置

 public enum BizCodeEnum { VALID_EXCEPTION(10001,"参数校验异常"), UNKNOW_EXCEPTION(10000,"未知异常"); private int code; private String msg; BizCodeEnum(int code,String msg){ this.code = code; this.msg = msg; } public String getMsg(){ return msg; } public int getCode(){ return code; } }

前端进行参数校验为了防止跨过前端直接调取后端接口,后端也需要进行参数校验,并且也方便后端使用postman进行调试

并且针对增、删、改、查可以进行分组校验,参数传递可能对于操作可要可不要,进行分组配置

@RequestMapping("/update/status") //@RequiresPermissions("product:brand:update") public R updateStatus(@Validated(UpdateStatusGroup.class)@RequestBody BrandEntity brand){ brandService.updateById(brand); return R.ok(); }

@RequestMapping("/save") //@RequiresPermissions("product:brand:save") public R save(@Validated({AddGroup.class}) @RequestBody BrandEntity brand)

 @RequestMapping("/update") //@RequiresPermissions("product:brand:update") public R update(@Validated(UpdateGroup.class)@RequestBody BrandEntity brand){ brandService.updateById(brand); return R.ok(); }

@Data @TableName("pms_brand") public class BrandEntity implements Serializable { private static final long serialVersionUID = 1L;  @NotNull(message = "修改必须指定id",groups = {UpdateGroup.class}) @Null(message = "新增不用指定id",groups = {AddGroup.class}) @TableId private Long brandId;  @NotBlank(message = "品牌名不能为空",groups = {UpdateGroup.class,AddGroup.class}) private String name;  @NotBlank(groups = {AddGroup.class}) @URL(message = "logo必须是一个合法的url地址",groups = {AddGroup.class,UpdateGroup.class}) private String logo;  private String descript;  @NotNull(groups ={AddGroup.class,UpdateStatusGroup.class} ) @ListValue(vals = {0,1},groups ={AddGroup.class,UpdateGroup.class} ) private Integer showStatus;  @NotEmpty(groups = {AddGroup.class}) @Pattern(regexp = "^[a-zA-Z]$",message = "首字母必须是a-z或A-Z",groups = {AddGroup.class,UpdateGroup.class}) private String firstLetter;  @NotNull(groups = {AddGroup.class}) @Min(value = 0,message = "排序必须为大于等于的数值",groups = {AddGroup.class,UpdateGroup.class}) private Integer sort; }

AddGroup -----都只是空的接口就可以 UpdateGroup

feign实现远程调用----服务与服务之间的调用--面向接口

1.接口告知远程调用的服务

@FeignClient("gulimall-product") public interface ProductFeignService {  @RequestMapping("/product/skuinfo/info/{skuId}") public R info(@PathVariable("skuId") Long skuId);

2.启动远程调用

@EnableFeignClients

3.调用

//TODO远程调用 如果失败,整个事务无需回滚 //1.自己catch掉异常 //2.TODO 还有第二种方式

try{ R info = feignService.info(skuId); Map skuInfo = (Map) info.get("skuInfo"); if(info.getCode()==0){ skuEntity.setSkuName((String) skuInfo.get("skuName")); } }catch (Exception e){ }

mybatis分页插件配置

@EnableTransactionManagement @MapperScan("com.atguigu.gulimall.ware.dao") @Configuration public class WareMyBatisConfig { //引入分页插件 @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); //设置请求的页面大于最大页后操作,true调回到首页,false继续请求 paginationInterceptor.setOverflow(true); //设置最大单页限制数量,默认500条,-1不受限制 paginationInterceptor.setLimit(1000); return paginationInterceptor; } }

分页查询:

1.

*/ @RequestMapping("/list") // @RequiresPermissions("ware:wareinfo:list") public R list(@RequestParam Map params){ PageUtils page = wareInfoService.queryPage(params); return R.ok().put("page", page); }

2.

@Override public PageUtils queryPage(Map params) { QueryWrapper wrapper = new QueryWrapper<>(); String key = (String) params.get("key"); if(!StringUtils.isEmpty(key)){ wrapper.eq("id",key).or().like("name",key) .or().like("address",key) .or().like("areacode",key); } IPage page = this.page( new Query().getPage(params), wrapper ); return new PageUtils(page); }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1002991.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号