• 搭建Java 开发环境


    1. 下载tomcat 并解压,详见参考:https://www.cnblogs.com/lizhilin2016/p/13579414.html

      tomcat 日志乱码:conf->logging.properties->java.util.logging.ConsoleHandler.encoding = GBK

    2. 安装Idea 开发环境,详细参考:https://www.codenong.com/cs106392310/ 

      碰到的问题及解决方案:

      1)不要直接去官方下载,最新版本无法破解,可下载历史版本:https://www.gpsmap.cc/soft/146.html 

      2)破解教程:https://blog.faaoo.cn/archives/24490 (百度网盘链接: https://pan.baidu.com/s/1Sf7OowO1m_5UgjM2afIjEQ  提取码: 3qdx)

    3. Intellij idea 部署tomcat , 参考:https://blog.csdn.net/qq_19986309/article/details/75416381

      碰到的问题和解决方案:

      1)配置tomcat 时提示:Application server libraries no found in Intellij, 解决方案:tomcat 使用9 的,参考:https://www.it1352.com/1840944.html 

      2)Intellij IDEA 部署tomcat 时提示:No artifacts marked for deployment, 解决方案:https://blog.csdn.net/sinat_41905822/article/details/88981871

      至此, Idea 部署 Tomcat 配置完毕~

    4. 运行拷贝的项目,项目demo 参照:https://blog.csdn.net/diyangxia/article/details/64122387 

      碰到的问题和解决方案:

      1)把项目代码的导入到Idea 中无法正常运行,一堆错误,提示 xxx 程序包不存在,根本原因是 maven 本地库 的配置有问题

        解决思路:https://blog.csdn.net/Jioho_chen/article/details/81046183/ 配置环境变量,并集成 maven 到 Idea 中

    5. 安MySQL 数据库

      1)MySQL 下载地址和安装配置,参考:https://www.cnblogs.com/winton-nfs/p/11524007.html

        (注意需要用管理员身份打开命令行,否则权限不足 lz)

      2)安装可视化工具Navicatfor MySQL,参考:https://blog.csdn.net/pc915968220/article/details/100763987 

        碰到的问题和解决方案:

        1)报错1130,host .. is not allowed to connect to this MySql server, 权限不足,参考:https://blog.csdn.net/dabao87/article/details/80571877 

        2)报错1251,client does not support authentication.. consider upgrading mysql client, 版本不兼容,参考:https://www.cnblogs.com/chao202426/p/11770894.html 

          

        3)报错:Duplicate entry '0' for key 'PRIMARY',表的主键没设置自增,将表的主键设置为自增即可

    6. 项目部署,参考:https://blog.csdn.net/zhanglf02/article/details/73565354 

      找到项目的war 文件(Idea 在target 目录下),直接放在 tomcat webapp 目录下面,启动tomcat 即可(最简单)

      1 PS C:WINDOWSsystem32> cd /
      2 PS C:> cd D:softmysql-8.0.21-winx64in
      3 PS D:softmysql-8.0.21-winx64in> mysqld --install
      4 Service successfully installed.
      5 PS D:softmysql-8.0.21-winx64in> mysqld --initialize --console
      6 2020-09-02T01:58:14.802373Z 0 [System] [MY-013169] [Server] D:softmysql-8.0.21-winx64inmysqld.exe (mysqld 8.0.21) initializing of server in progress as process 16348
      7 2020-09-02T01:58:14.817044Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
      8 2020-09-02T01:58:15.363177Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
      9 2020-09-02T01:58:16.541750Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9f9t<!OEFYKC
     10 PS D:softmysql-8.0.21-winx64in> ^C
     11 PS D:softmysql-8.0.21-winx64in> ^C
     12 PS D:softmysql-8.0.21-winx64in> net start mysql
     13 MySQL 服务正在启动 .
     14 MySQL 服务已经启动成功。
     15 
     16 PS D:softmysql-8.0.21-winx64in> mysql -u root -p
     17 Enter password: ************
     18 Welcome to the MySQL monitor.  Commands end with ; or g.
     19 Your MySQL connection id is 8
     20 Server version: 8.0.21
     21 
     22 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
     23 
     24 Oracle is a registered trademark of Oracle Corporation and/or its
     25 affiliates. Other names may be trademarks of their respective
     26 owners.
     27 
     28 Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
     29 
     30 mysql> alter user 'root'@'localhost' identified by 'lz';
     31 Query OK, 0 rows affected (0.01 sec)
     32 
     33 mysql> exit
     34 Bye
     35 PS D:softmysql-8.0.21-winx64in> mysql -u root -p
     36 Enter password: **
     37 Welcome to the MySQL monitor.  Commands end with ; or g.
     38 Your MySQL connection id is 9
     39 Server version: 8.0.21 MySQL Community Server - GPL
     40 
     41 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
     42 
     43 Oracle is a registered trademark of Oracle Corporation and/or its
     44 affiliates. Other names may be trademarks of their respective
     45 owners.
     46 
     47 Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
     48 
     49 mysql> ipconfig
     50     -> cd /
     51     -> show tables;
     52 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ipconfig
     53 cd /
     54 show tables' at line 1
     55 mysql> show tables;
     56 ERROR 1046 (3D000): No database selected
     57 mysql> show databases;
     58 +--------------------+
     59 | Database           |
     60 +--------------------+
     61 | information_schema |
     62 | mysql              |
     63 | performance_schema |
     64 | sys                |
     65 +--------------------+
     66 4 rows in set (0.01 sec)
     67 
     68 mysql> use mysql;
     69 Database changed
     70 mysql> show tables;
     71 +---------------------------+
     72 | Tables_in_mysql           |
     73 +---------------------------+
     74 | columns_priv              |
     75 | component                 |
     76 | db                        |
     77 | default_roles             |
     78 | engine_cost               |
     79 | func                      |
     80 | general_log               |
     81 | global_grants             |
     82 | gtid_executed             |
     83 | help_category             |
     84 | help_keyword              |
     85 | help_relation             |
     86 | help_topic                |
     87 | innodb_index_stats        |
     88 | innodb_table_stats        |
     89 | password_history          |
     90 | plugin                    |
     91 | procs_priv                |
     92 | proxies_priv              |
     93 | role_edges                |
     94 | server_cost               |
     95 | servers                   |
     96 | slave_master_info         |
     97 | slave_relay_log_info      |
     98 | slave_worker_info         |
     99 | slow_log                  |
    100 | tables_priv               |
    101 | time_zone                 |
    102 | time_zone_leap_second     |
    103 | time_zone_name            |
    104 | time_zone_transition      |
    105 | time_zone_transition_type |
    106 | user                      |
    107 +---------------------------+
    108 33 rows in set (0.01 sec)
    109 
    110 mysql> select Host, User,Password from user;
    111 ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
    112 mysql> select Host, User from user;
    113 +-----------+------------------+
    114 | Host      | User             |
    115 +-----------+------------------+
    116 | localhost | mysql.infoschema |
    117 | localhost | mysql.session    |
    118 | localhost | mysql.sys        |
    119 | localhost | root             |
    120 +-----------+------------------+
    121 4 rows in set (0.00 sec)
    122 
    123 mysql> update user set Host='%' where User='root';
    124 Query OK, 1 row affected (0.00 sec)
    125 Rows matched: 1  Changed: 1  Warnings: 0
    126 
    127 mysql> flush privileges;
    128 Query OK, 0 rows affected (0.00 sec)
    129 
    130 mysql> --help|grep my.cnf
    131     -> mysql --help|grep my.cnf
    132     -> mysql --help|grep my.cnf;
    133 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--help|grep my.cnf
    134 mysql --help|grep my.cnf
    135 mysql --help|grep my.cnf' at line 1
    136 mysql> --help|grep my.cnf;
    137 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--help|grep my.cnf' at line 1
    138 mysql> help
    139 
    140 For information about MySQL products and services, visit:
    141    http://www.mysql.com/
    142 For developer information, including the MySQL Reference Manual, visit:
    143    http://dev.mysql.com/
    144 To buy MySQL Enterprise support, training, or other products, visit:
    145    https://shop.mysql.com/
    146 
    147 List of all MySQL commands:
    148 Note that all text commands must be first on line and end with ';'
    149 ?         (?) Synonym for `help'.
    150 clear     (c) Clear the current input statement.
    151 connect   (
    ) Reconnect to the server. Optional arguments are db and host.
    152 delimiter (d) Set statement delimiter.
    153 ego       (G) Send command to mysql server, display result vertically.
    154 exit      (q) Exit mysql. Same as quit.
    155 go        (g) Send command to mysql server.
    156 help      (h) Display this help.
    157 notee     (	) Don't write into outfile.
    158 print     (p) Print current command.
    159 prompt    (R) Change your mysql prompt.
    160 quit      (q) Quit mysql.
    161 rehash    (#) Rebuild completion hash.
    162 source    (.) Execute an SQL script file. Takes a file name as an argument.
    163 status    (s) Get status information from the server.
    164 system    (!) Execute a system shell command.
    165 tee       (T) Set outfile [to_outfile]. Append everything into given outfile.
    166 use       (u) Use another database. Takes database name as argument.
    167 charset   (C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
    168 warnings  (W) Show warnings after every statement.
    169 nowarning (w) Don't show warnings after every statement.
    170 resetconnection(x) Clean session context.
    171 
    172 For server side help, type 'help contents'
    173 
    174 mysql> show variables like 'default_authentication_plugin';
    175 +-------------------------------+-----------------------+
    176 | Variable_name                 | Value                 |
    177 +-------------------------------+-----------------------+
    178 | default_authentication_plugin | caching_sha2_password |
    179 +-------------------------------+-----------------------+
    180 1 row in set, 1 warning (0.00 sec)
    181 
    182 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'lz';
    183 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    184 mysql> ^C
    185 mysql>  alter user 'root'@'localhost' identified by 'lz';
    186 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    187 mysql> USE mysql;
    188 Database changed
    189 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'lz';
    190 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    191 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
    192 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    193 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'lz';
    194 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    195 mysql> use mysql;
    196 Database changed
    197 mysql> select user,host from user;
    198 +------------------+-----------+
    199 | user             | host      |
    200 +------------------+-----------+
    201 | root             | %         |
    202 | mysql.infoschema | localhost |
    203 | mysql.session    | localhost |
    204 | mysql.sys        | localhost |
    205 +------------------+-----------+
    206 4 rows in set (0.00 sec)
    207 
    208 mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'lz';
    209 ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
    210 mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'lz';
    211 Query OK, 0 rows affected (0.00 sec)
    212 
    213 mysql> FLUSH PRIVILEGES;
    214 Query OK, 0 rows affected (0.01 sec)
    完整命令行

    项目中碰到的一些问题:

    1. 接口返回乱码,参考:https://blog.csdn.net/weixin_43453386/article/details/83512451 

    三、Content-Type用法
    1.headers
    
    //Accept=application/json :表示客户端希望接受的数据类型是json
    @RequestMapping(value = "/test/ContentType", headers = "Accept=application/json")  
    public void test1(HttpServletResponse response) throws IOException {  
        //表示响应的内容区数据的媒体类型为json格式,且编码为utf-8(客户端应该以utf-8解码)  
        response.setContentType("application/json;charset=utf-8");  
        //写出响应体内容  
        String jsonData = "{"username":"zhang", "password":"123"}";  
        response.getWriter().write(jsonData);  
    }
    
    
    //content-type =application/json :表示客户端发送的数据格式是json
    @RequestMapping(value = "/test/ContentType", headers = {"content-type = application/json"})  
    public void test2(@RequestBody Pet pet) throws IOException {  
        // TODO
    }
    
    
    2.consumes
    
    //仅处理request Content-Type为“application/json”类型的请求
    @RequestMapping(value = "/test/produces", method = RequestMethod.POST, consumes="application/json")  
    public void test(@RequestBody Pet pet, Model model) {      
        // TODO
    }
    
    //处理request Content-Type,定义的2种类型的请求
    @RequestMapping(consumes = {"application/json","application/x-www-form-urlencoded"})
    public void test2(@RequestBody Pet pet, Model model) {      
        // TODO
    }
    
    //处理request Content-Type中,除了以下2种类型的请求
    @RequestMapping(consumes = {"!application/json","!application/x-www-form-urlencoded"})
    public void test3(@RequestBody Pet pet, Model model) {      
        // TODO
    }
    
    
    
    3.produces
    
    //返回json数据 && 字符编码为utf-8
    @RequestMapping(value = "/test/consumes", method = RequestMethod.POST, produces="application/json;charset=utf-8")    
    @ResponseBody    
    public Pet test3(@PathVariable String petId, Model model) {       
        // TODO
    } 
    

      

    2. 

    以一颗童心善待生活
  • 相关阅读:
    均值回归理论,均值回归法则是指万物最终都将回归于其长期的均值
    文本框仅允许输入大于0的正整数
    Angularjs接收服务端的布尔值
    Ajax POST单个对象或多个对象至API
    ASP.NET MVC程序重构
    查询数据库创建时间
    查询MS SQL的版本号
    获取Data和Log默认路径
    快速查找对象
    表关联使用INNER JOIN实现更新功能
  • 原文地址:https://www.cnblogs.com/lizhilin2016/p/13595994.html
Copyright © 2020-2023  润新知