如何搭建自己的网站(二)

一、ubuntu安装数据库

1.安装

安装:sudo apt-get install mysql-server
查看版本:mysql -V
查看运行状态:sudo netstat -tap | grep mysql

2.寻找初始密码

cd /etc/mysql
sudo vim debian.cnf

 

3.登录

mysql -u debian-sys-maint -p
Enter password: xxxxxxxxxxxxxxxx

4.修改密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';

5.修改远程连接

use mysql;
select host,user from user;
update user set host = '%' where user = 'root';
flush privileges;

二、mybatis连接数据库

1.新建demoMybatis项目

勾选mybatis、jdbc等依赖。

2.修改application.properties配置文件

可以将这个文件拆成三个,一个是选择启动文件的application.yml,一个是开发环境application-dev.yml,一个是生产环境application-prod.yml,生产环境的url将localhost替换成远程数据库地址,详细如下:

spring:
  profiles:
    active: prod
server:
  port: 8080
spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://82.157.160.30:3306/ache?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
  mapper-locations: classpath:mapping/*Mapper.xml
  type-aliases-package: com.example.demoMybatis.entity
#showSql
logging:
  level:
    com:
      example:
        mapper: debug

3.写查询的接口

mapper



数据库:



测试一下:



常规打包mvn clean package、常规上传、查找容器docker ps、查找镜像docker images、kill容器docker kill CONTAINERID、移除容器docker rm CONTAINERID、移除镜像docker rmi IMAGEID构建镜像docker build -t my/demo .运行容器docker run -d --name demo -p 8080:8080 my/demo 

三、vue搜索关键字高亮

const highLight = (allText, keyword) => {
  let Reg = new RegExp(keyword, "ig");
  if (allText) {
    let execRes = Reg.exec(allText.toString()); //得到一个匹配结果的集合,包含关键字出现的索引
    if (execRes) {
      let realword = allText.substr(execRes.index, keyword.length); //根据索引和关键字长度获取原本的真实大小写关键词
      let res = allText.replace(
        Reg,
        `<span style="color: red;">${realword}</span>`
      );
      return res;
    } else return allText;
  } else return allText;
};
<h3 v-html="highLight(item.title, filter.search)"></h3>
<p v-html="highLight(item.detail, filter.search)"></p>

四、成功辽

猜你喜欢

转载自blog.csdn.net/bDreamer/article/details/123498500