Day1环境搭建与用户登录
1.Vmware无法连接到连接工具:
2.导入maven工程报错:cannot reconnect:
3.lamadaQueryMapper:
(1)LambdaQueryWrapper 报错 Object is not a functional interface
因为没有加泛型
(2) service层不能单纯的实现接口,还有继承才能使用MP
public class ApUserServiceImpl extends ServiceImpl<ApUserMapper, ApUser>
implements ApUserService {
//必须写继承,不然用不出来
(3)
ApUser apUser = getOne(Wrappers.<ApUser>lambdaQuery().eq(ApUser::getPhone, dto.getPhone())); 与
LambdaQueryWrapper<ApUser> wrapper = new LambdaQueryWrapper(); wrapper.eq(ApUser::getPhone, dto.getPhone()); ApUser apUser = this.getOne(wrapper);
相等
4.判断传过来的数据是否为空
StringUtils(org.springframework.util.).isempty;
StringUtils(org.apache.commons.lang3.StringUtils家的).isblank
都可以
5.打开service窗口

6.nacos连接不上
注意一下Data Id要一致。
7.gateway配置解释
server:
port: 9000
spring:
application:
name: sca-gateway
cloud:
gateway:
routes: #配置网关路由规则
- id: route01 #路由id,自己指定一个唯一值即可
uri: http://localhost:8081/ #网关帮我们转发的url
predicates: ###断言(谓词):匹配请求规则
- Path=/nacos/provider/echo/** #请求路径定义,此路径对应uri中的资源
filters: ##网关过滤器,用于对谓词中的内容进行判断分析以及处理
- StripPrefix=1 #转发之前去掉path中第一层路径,例如nacos
Day2 app端看文章
1.垂直分表:

2.mapper语句的疑惑
<select id="loadArticleList" resultMap="resultMap">
SELECT
aa.*
FROM
`ap_article` aa
LEFT JOIN ap_article_config aac ON aa.id = aac.article_id
<where>
and aac.is_delete != 1
and aac.is_down != 1
<!-- loadmore -->
<if test="type != null and type == 1">
and aa.publish_time <![CDATA[<]]> #{dto.minBehotTime}
</if>
<if test="type != null and type == 2">
and aa.publish_time <![CDATA[>]]> #{dto.maxBehotTime}
</if>
<if test="dto.tag != '__all__'">
and aa.channel_id = #{dto.tag}
</if>
</where>
order by aa.publish_time desc
limit #{dto.size}
</select>
(1) <where>
and aac.is_delete != 1
这个为什么要接and?
(2)<![CDATA[<]]> 又是什么意思?
(3)这里为什么要编写xml文件?
因为相关的表没有对应可以注入的service对象,所以没有办法使用lamda查询器,只能手写mapper文件
(4)一对一关联查询为什么没有association?
3.Short type 参数
4.对于固定的值我们一般会抽出来做一个固定的常量
size = Math.min(size,50); //这样写就不让好
//这样写表准
private final static short MAX_PAGE_SIZE = 50;
size = Math.min(size,MAX_PAGE_SIZE);
5.报错:
(1)lass path resource [com/heima/apis/article/IArticleClient.class] cannot be opened because it does not exist
把target文件删了重写启动一下啊
(2)Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected:
注意一下日志的存储位置,不要错了
Day3:文章查询发布
1.疑惑:这是什么意思?
//获得token解析后中的用户信息
Object userId = claimsBody.get("id");
//在header中添加新的信息
ServerHttpRequest serverHttpRequest = request.mutate().headers(httpHeaders -> {
httpHeaders.add("userId", userId + "");
}).build();
//重置header
exchange.mutate().request(serverHttpRequest).build();
2.业务层的this
@Override
public ResponseResult findAll() {
return ResponseResult.okResult(this.list());
}
这里面的源码如下
public interface IService<T> {
....
default List<T> list() {
return this.list(Wrappers.emptyWrapper());
}
.....
}
https://blog.youkuaiyun.com/u011870022/article/details/110705281?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164906084316781683990319%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164906084316781683990319&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-110705281.142^v5^pc_search_result_control_group,157^v4^control&utm_term=Iservice&spm=1018.2226.3001.4187
https://blog.youkuaiyun.com/u011870022/article/details/110705281?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164906084316781683990319%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164906084316781683990319&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-110705281.142%5Ev5%5Epc_search_result_control_group,157%5Ev4%5Econtrol&utm_term=Iservice&spm=1018.2226.3001.4187https://blog.youkuaiyun.com/u011870022/category_10231475.html
https://blog.youkuaiyun.com/u011870022/category_10231475.html具体学习如上
3.pojos里的枚举类
因为表中status是这样的:

为了方便
//状态枚举类
@Alias("WmNewsStatus")
public enum Status{
NORMAL((short)0),SUBMIT((short)1),FAIL((short)2),ADMIN_AUTH((short)3),ADMIN_SUCCESS((short)4),SUCCESS((short)8),PUBLISHED((short)9);
short code;
Status(short code){
this.code = code;
}
public short getCode(){
return this.code;
}
}
4. 注意一个小细节

这样就没错了

5.分页查询,使用的是Iservice的功能
//结果返回 page= this.page(page, lambdaQueryWrapper); 源码如下:

6.这里用的是多态:
//结果返回
page= this.page(page, lambdaQueryWrapper);
ResponseResult responseResult
=new PageResponseResult(page.getCurrent(), page.getSize(), page.getTotal());
//多态
responseResult.setData(page.getRecords());
return responseResult;
这里有个疑问,为什么是dto不是page
//结果返回
page= this.page(page, lambdaQueryWrapper);
System.out.println("________________"+page);
System.out.println("$$$$$$"+page.toString());
ResponseResult responseResult=new PageResponseResult(dto.getPage (),dto.getSize(),(int)page.getTotal());
ResponseResult responseResult1= new PageResponseResult((int)page.getCurrent(), (int)page.getSize(), (int)page.getTotal());
responseResult.setData(page.getRecords());
responseResult1.setData(page.getRecords());
return responseResult;

你会发现打印结果一致。
7.mapper的遍历
<insert id="saveRelations">
insert into wm_news_material (material_id,news_id,type,ord)
values
<foreach collection="materialIds" index="ord" item="mid" separator=",">
(#{mid},#{newsId},#{type},#{ord})
</foreach>
</insert>
(1)collection = “” ,这个参数是 dao 层(mapper)接口方法里面传过来的集合参数,如果dao 层传的参数只有一个,这里写关键字 list(如果是数组,写 array)
例子:
dao 层:User getInfo(List user_ids)
collection = “list”【
如果有多个参数,并且使用了 @Param 注解(import org.apache.ibatis.annotations.Param),则这里要写注解里面的参数!
例子: dao 层 :User getInfo(@Param(“user_ids”)List user_ids,@Param(“xxx”)String xxx)
collection = “user_ids”
】
(2)item = “” ,集合里面的单个值,给下面 #{ } 用
(3)index = “” ,这个是遍历的下标,举个简单的例子立刻明白,就是平时 for 循环,我们定义的 i 一样
例子: for(int i = 0 ;i < 10 ; i ++){undefined
}
因此这个参数随便定义都可以,有就行
(4)open separator close 这3个比较好理解,就是 ( , , ,) 这样子啦,拼接括号,中间逗号隔开的意思
————————————————
版权声明:本文为优快云博主「Heart_B」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/hearth_b/article/details/107554611
8.alibaba的将String类型转换为map的集合
JSON.parseArray(content, Map.class);
9.枚举类的错误

用逗号隔开
10.报错:
2022-04-05 17:11:52.257 [http-nio-51803-exec-5] ERROR c.h.common.exception.ExceptionCatch - catch exception:
### Error querying database. Cause: java.sql.SQLException: Invalid utf8mb4 character string: 'ACED00'
### The error may exist in com/heima/wemedia/mapper/WmMaterialMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,user_id,url,type,is_collection,created_time FROM wm_material WHERE (url = ?)
### Cause: java.sql.SQLException: Invalid utf8mb4 character string: 'ACED00'
; uncategorized SQLException; SQL state [HY000]; error code [1300]; Invalid utf8mb4 character string: 'ACED00'; nested exception is java.sql.SQLException: Invalid utf8mb4 character string: 'ACED00'
错误原因:
//错误的:
List<WmMaterial> dbMaterials = wmMaterialMapper
.selectList(Wrappers.<WmMaterial>
lambdaQuery().eq(WmMaterial::getUrl, materials));
//正确的
List<WmMaterial> dbMaterials = wmMaterialMapper.
selectList(Wrappers.<WmMaterial>lambdaQuery()
.in(WmMaterial::getUrl, materials));
//in在sql语句中表述批量查询
比如SELECT * FROM wm_material WHERE id IN(67,68)
意思就是展示id为67和68的,这里不能用and,and就是id即等于67又等于68
这篇博客总结了LeadNews(黑马头条)项目开发过程中的关键步骤和遇到的问题,包括VMware网络适配器配置、IDEA中Maven工程导入错误、LambdaQueryMapper使用技巧、Nacos连接、服务层配置、MyBatis的mapper语句和XML文件编写,以及日志配置等。还涉及了分页查询、枚举类、数据转换和SQL错误处理等内容。
https://blog.youkuaiyun.com/qq_43613772/article/details/104030233?ops_request_misc=&request_id=&biz_id=102&utm_term=%E8%AE%A1%E7%AE%97%E6%9C%BA%E6%B2%A1%E6%9C%89VMware%20adapter&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-104030233.142%5Ev5%5Epc_search_result_control_group,157%5Ev4%5Econtrol&spm=1018.2226.3001.4187
https://blog.youkuaiyun.com/u011870022/article/details/110705281?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164906084316781683990319%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164906084316781683990319&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-110705281.142%5Ev5%5Epc_search_result_control_group,157%5Ev4%5Econtrol&utm_term=Iservice&spm=1018.2226.3001.4187
5432

被折叠的 条评论
为什么被折叠?



