工作中细节问题(待完善)

字符串

操作字符串自己遇到的问题

字符串拼接

使用字符串拼接的时候尽量不要用+来拼接
常用:str.concat(str1);

concat()方法首先获取拼接字符串的长度,判断这个字符串长度是否为0(判断这个用来拼接的字符串是不是空串),如果是就返回原来的字符串(等于没有拼接);否则就获取源字符串的长度,创建一个新的char[]字符数组,这个字符数组的长度是拼接字符串的长度与源字符串的长度之和,通过Arrays类的copyOf方法复制源数组,然后通过getChars方法将拼接字符串拼接到源字符串中,然后将新串返回。
  • concat只能用于字符串的拼接,不能拼接其他类型的数据,并且字符串本身和拼接的字符串都不能为null,否则运行程序后会报空指针异常NullPointerException(编译时没有报错)。
  • “+”:可以对字符,数字,字符串等数据类型的拼接
  • append()方法:可以对字符,数字,字符串等数据类型的拼接,结果返回一个StringBuffer类型的对象
  • 使用StringBuilder的效率 > 使用concat > +

Linux命令

[root@izwz94gb5cfw913042mfyxz opt]# free -m  #查看内存
              total        used        free      shared  buff/cache   available
Mem:           1736         593         312          66         830         872
Swap:             0           0           0

跨域问题

通过一个地址去访问另一个地址,如果访问协议(http,https),ip地址,端口号有任何一个不一样就会出现跨域问题。
解决方法:
1.在controller上加@CrossOrigin
2.使用网关解决
3.写一个拦截器

实体类数据库 mybatis

使用mybatis数据类型使用Date时,插入数据正确,返回值变为2019-01-25T01:30:00.000+0000

解决方案:1.实体类上加@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@ApiModelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createTime;

@ApiModelProperty(value = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateTime;

2.配置文件加上
spring.jackson.date-format: yyyy-MM-dd HH:mm:ss GMT+8

数据库配置数据源(注意改为GMT+8)

spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/mybatisplusstudy?useSSL=false&useUnicode=true&characterEncoding=utf-8&severTimezone=GMT+8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

mapper.xml没有被编译

Mybatis问题:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):com.liu.eduservice.mapper.EduCourseMapper.getPublishCourseInfo
问题分析: dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所 有资源文件是不发布到target目录下的
常用解决方法:
1.pom.xml

<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

2.application.yml
#配置mapper xml文件的路径

mybatis-plus:
  mapper-locations: classpath:com/liu/eduservice/mapper/xml/*.xml

Maven

工具类

Controller控制层

tomcat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值