th:insert:将被引用的模板片段插⼊到自己的标签体中
th:replace:将被引用的模板片段替换掉自己
th:include:类似于 th:insert,⽽不是插⼊⽚段,它只插⼊此⽚段的内容
java
<!--1、比如抽取的公用代码片段如下-->
<footer th:fragment="copy">
© 2011 The Good Thymes Virtual Grocery
</footer>
<!--2、采用如下三种方式进行引用-->
<div th:insert="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
<div th:include="footer :: copy"></div>
<!--3、则三种引用方式的效果分别对应如下-->
<div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
</div>
<footer>
© 2011 The Good Thymes Virtual Grocery
</footer>
<div>
© 2011 The Good Thymes Virtual Grocery
</div>
后端数据校验
引入jar包
java
<!-- JSR303数据校验支持-->
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.6.Final</version>
</dependency>
目前可用的对应的spring版本号
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
之后只需要在实体类或者传入的参数上加上注解类似@null,@notbleak,@past...
另外需要在controller的类上加上@Validated,以及接受的实体或者参数上添加@Valid的注解
mybatis plus中的 e w . s q l S e g m e n t , {ew.sqlSegment}, ew.sqlSegment,{ew.sqlSelect}, e w . c u s t o m S q l S e g m e n t , {ew.customSqlSegment}, ew.customSqlSegment,{ew.sqlSet}使用
ew是mapper方法里的@Param(Constants.WRAPPER) Wrapper queryWrapper对象
首先判断ew.emptyOfWhere是否存在where条件,有的话再拼接上去,ew.customSqlSegment是WHERE + sql语句
没有where的时候加上 == false
使用${ew.sqlSegment} 如果是连表查询且查询条件是连表的字段则需在service层拼接查询条件时字段前指定别
名
例子
mapper.xml
xml
<select id="tableList" resultType="java.util.LinkedHashMap">
SELECT
${ew.sqlSelect} // 这里拼接select后面的语句
FROM
${table_name} //如果是单表的话,这里可以写死
${ew.customSqlSegment}
</select>
Mapper
IPage<LinkedHashMap<String,Object>> tableList(@Param("table_name") String table_name,
Page page,
@Param(Constants.WRAPPER) QueryWrapper queryWrapper);
Test
String responseField = "*";
queryWrapper.select(responseField);
// 即 select * ...
String responseField = "name";
queryWrapper.select(responseField);
// 即 select name ...
例子2
java
Controller
public String saveAddress(HttpSession session) {
UserVO user1 = (UserVO)session.getAttribute("user");
LambdaQueryWrapper<User> lambdaQueryWrapper = Wrappers.<User>lambdaQuery()
.select(User::getNickName, User::getUserId) // 需要查询的列,即 ${ew.sqlSelect}
.eq(User::getUserId, user1.getUserId());// 条件
User user = this.userMapper.selectNickNameAndUserId(lambdaQueryWrapper);
System.out.println(user);
return null;
}
Mapper
User selectNickNameAndUserId(@Param(Constants.WRAPPER) Wrapper<User> queryWrapper);
mapper.xml
<select id="selectNickNameAndUserId" resultType="com.example.demo.entity.User">
select
<if test="ew != null and ew.sqlSelect != null and ew.sqlSelect != ''">
${ew.sqlSelect}
</if>
from
user
where is_deleted != 1
<if test="ew != null">
<if test="ew.nonEmptyOfWhere">
AND
</if>
${ew.sqlSegment}
</if>
</select>
<select id="selectNickNameAndUserId" resultType="com.example.demo.entity.User">
select
<if test="ew != null and ew.sqlSelect != null and ew.sqlSelect != ''">
${ew.sqlSelect }
</if>
from
user
${ew.customSqlSegment}
</select>
使用${ew.sqlSegment} 如果是联表查询且查询条件是连表的字段则需在service层拼接查询条件时字段前指定别名,而且不能用lambda的查询了
java
<select id="selectByRoleId" resultType="com.captain.crewer.mybatis.plus.dto.RolePermsDTO">
SELECT tp.id,
tp.perm_name,
tp.url,
tr.role_id as roleId,
tr.role_name as roleName
FROM tb_role tr
LEFT JOIN tb_perm_role tpr ON tr.role_id = tpr.role_id
LEFT JOIN tb_perm tp ON tpr.perm_id = tp.id ${ew.customSqlSegment}
</select>
Mapper
List<RolePermsDTO> selectByRoleId(@Param(Constants.WRAPPER) Wrapper<RolePermsDTO> wrapper);
${ew.sqlSet}
LambdaUpdateWrapper<User> wrapper = Wrappers.<User>lambdaUpdate().set(User::getNickName, "1").eq(User::getUserId, 1);
this.userMapper.updateUser(wrapper);
int updateUser(@Param(Constants.WRAPPER) Wrapper<User> updateWrapper);
<update id="updateUser">
update user
set ${ew.sqlSet}
where ${ew.sqlSegment}
</update>
DateUtil时间工具的使用
暂时无法在郑煤机文档外展示此内容
spring中time-zone=GMT+8无效(主要原因是因为配置的拦截器中添加了@EnableWebMvc会导致失效)
需要实现 WebMvcConfigurer 或 继承WebMvcConfigurerAdapter
java
@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
//解决 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
//spring.jackson.time-zone=GMT+8 不生效的功能
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = converter.getObjectMapper();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
converter.setObjectMapper(objectMapper);
converters.add(0, converter);
}
}
git绑定远程分支
//创建并切换到本地分支
git checkout -b dev
//查看本地与远程分支
git branch -a
//关联本地分支到远程分支
git branch --set-upstream-to=origin/jp jp
git branch --set-upstream-to=origin/zjp zjp
、//新的代码推送到仓库步骤
1.git init
2.git add .
3.git commit -m "描述信息"
//添加远程仓库地址
-
git remote add origin https://github.com/ai-dengzy/c_server.git
-
git pull
6.git branch --set-upstream-to=origin/master
7.git pull
8.git push -u origin master
[图片]
再次推送
git push -u origin master
更改git仓库地址
2.先初始化git仓库 git init
git remote -v 查询所在仓库
3.删除原仓库路径git remote rm origin
git remote add origin '新的仓库地址'
对于t'inyint类型: 0 true 1 false
maven打包
mvn clean package -DskipTests
maven插件
mvn -U idea:idea
实体转换map对象
object...stream().collect(Collectors.toMap(Object::getField, Function.identity()))
testWhileIdle is true, validationQuery not set解决办法
[图片]
字符串替换{}
StrUtil.format(string,tihuan1,...)
日志打印在对应类中
private static Logger logger = LoggerFactory.getLogger(DriverXxlJob.class);
mysql注意点
隐式转换,where条件处类型一致需要(部分字符串转整形可以),但表为字符串查询值为整形会进行全表查询,结果不对导致
mybatiespius隐藏细节:更新语句不会进行空值处理,需要在字段加上注解@TableField(value = "group_id", fill = FieldFill.UPDATE)
LINUX常用命令
whereis java //寻找Java安装路径
修改文件权限:chmod 777 xxx
防火墙配置
防火墙配置
安装服务
#安装firewalld
yum install firewalld firewall-config
firewall-cmd --zone=public --add-port=80/tcp --permanent 关闭端口命令
systemctl restart firewalld.service 重启防火墙
systemctl start firewalld # 开启防火墙
firewall-cmd --list-all 查看防火墙所有开启的端口
systemctl status firewalld # 或者 firewall-cmd --state 查看防火墙状态
systemctl disable firewalld # 停止防火墙
systemctl stop firewalld # 禁用防火墙
端口管理
#打开443/TCP端口
firewall-cmd --add-port=443/tcp
#永久打开3690/TCP端口
firewall-cmd --permanent --add-port=3690/tcp# 查看防火墙,添加的端口也可以看到
或者
firewall-cmd --list-all
数组转字符串用字符拼接
StringUtils.join(user, ",");
注解使用
@ApiParam("设备变量")接口参数注释
Redis
redis获取哈希表的所有值
redisTemplate.opsForHash().values
OPC问题总结
点采集不到问题:检查是否配置了opc服务的映射
刷新host
ipconfig /flushdns
判空断言
Assert.notEmpty(req.getStorageNumbers(), "料位编号不能为空");