【Tomcat】localhost:8080/ で 404 になる
問題
EclipseでTomcat x Springのプロジェクトを使っているときに、localhost:8080/ が 404 になってしまった
原因
EclipseでTomcatを使うときには、Servers
というプロジェクトが作成され、その中に設定がある
Servers/server.xml
を見てみると、以下のようになっていた
<Context docBase="yourwebapp" path="/controller" reloadable="false" source="org.eclipse.jst.jee.server:yourwebapp"/></Host>
解決方法
path
の controller
の部分を削除し、/
のみにする
<Context docBase="yourwebapp" path="/" reloadable="false" source="org.eclipse.jst.jee.server:yourwebapp"/></Host>
すると、localhost:8080/
でページが表示された!
めでたしめでたし
参考文献
【Vim】gruvbox8でitalicを使わないようにする
問題
カラースキーマで lifepillar/vim-gruvbox8 を使っていて、ところどころ、italic(斜体)を使っているところがある。
なんかよくわからないけど、italicの部分が見切れてしまうため、OFFにしたかった
原因
g:gruvbox_italics
と g:gruvbox_italicize_strings
が設定されていなかった
解決方法
let g:gruvbox_italics = 0 let g:gruvbox_italicize_strings = 0 colorscheme gruvbox8_soft
のように設定する
また、colorscheme
より前に設定する必要がある
【MySQL】 TBL2のレコードの値によって、TBL1のレコードをUPDATEする
- 以下のようなデータを用意
CREATE TABLE table1(id int not null, name varchar (15)); CREATE TABLE table2(id int not null, gender char (1)); INSERT INTO table1 VALUES (1, 'takuya'); INSERT INTO table1 VALUES (2, 'taro'); INSERT INTO table1 VALUES (3, 'jiro'); INSERT INTO table1 VALUES (4, 'saburo'); INSERT INTO table1 VALUES (5, 'siro'); insert into table2 values (1, 1); insert into table2 values (2, 2); insert into table2 values (3, 1); insert into table2 values (4, 2); insert into table2 values (5, 2);
mysql> select * from table1; +----+--------+ | id | name | +----+--------+ | 1 | takuya | | 2 | taro | | 3 | jiro | | 4 | saburo | | 5 | siro | +----+--------+ 5 rows in set (0.00 sec) mysql> select * from table2; +----+--------+ | id | gender | +----+--------+ | 1 | 1 | | 2 | 2 | | 3 | 1 | | 4 | 2 | | 5 | 2 | +----+--------+ 5 rows in set (0.00 sec)
複数テーブルを使ったUPDATE文の実行をしてみる
カンマを使う場合
table2.gender = 2
のレコードと紐づくtable1
のデータの値を更新してみる
update table1 , (select * from table2 where gender = 2) tbl2 set table1.name = 'gender2' where table1.id = tbl2.id;
- 結果は以下のようになる
mysql> select table1.id, table1.name, table2.gender from table1 left join table2 on table1.id = table2.id; +----+---------+--------+ | id | name | gender | +----+---------+--------+ | 1 | takuya | 1 | | 2 | gender2 | 2 | | 3 | jiro | 1 | | 4 | gender2 | 2 | | 5 | gender2 | 2 | +----+---------+--------+ 5 rows in set (0.00 sec)
カンマを使わない場合
update table1 inner join (select * from table2 where gender = 2) tbl2 on table1.id = tbl2.id set table1.name = 'gender2'
inner join
を使っているところに注意する
もし、left join
にしてしまうと、table1
の全レコードがupdateされてしまう
参考文献
【MySQL】MySQLでのBooleanの扱い
Mysqlのboolean型について調べてみた - Qiita の内容を自分の手で確かめてみた
環境
> docker-compose exec mysql mysql --version mysql Ver 8.0.16 for Linux on x86_64 (MySQL Community Server - GPL)
まとめ
boolean
とtinyint(1)
のどちらともtinyint(1)
で CREATE TABLE されるtrue
は1
、false
は0
で INSERT される- 値の比較は
=
とis
で変わるwhere col = true
は1
のデータ、where col = false
は0
のデータ(想定通り)where col is true
は0
以外のデータ、where col is false
は0
のデータ(想定と違う)
CREATE
booleanとtinyint(1)のテーブルを作成し、全く同じデータを入れてみた
> create table test_boolean (bool_col boolean); > create table test_tinyint (bool_col tinyint(1));
boolean
とtinyint(1)
のどちらともtinyint(1)
でカラムが作成される
> show create table test_boolean; +--------------+--------------------------------------+ | Table | Create Table | +--------------+--------------------------------------+ | test_boolean | CREATE TABLE `test_boolean` ( | | | `bool_col` tinyint(1) DEFAULT NULL | | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +--------------+--------------------------------------+ > show create table test_tinyint; +--------------+--------------------------------------+ | Table | Create Table | +--------------+--------------------------------------+ | test_tinyint | CREATE TABLE `test_tinyint` ( | | | `bool_col` tinyint(1) DEFAULT NULL | | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +--------------+--------------------------------------+
INSERT
false
をINSERTすると0
> insert into test_boolean values (false); > select * from test_boolean; +----------+ | bool_col | +----------+ | 0 | +----------+
true
をINSERTすると1
> truncate test_boolean; > insert into test_boolean values (true); > select * from test_boolean; +----------+ | bool_col | +----------+ | 1 | +----------+
WHERE
where col = true
は1
のデータ、where col = false
は0
のデータが抽出できるwhere col is true
は0
以外のデータ、where col is false
は0
のデータが抽出できる- これ知ってないとハマりそう。でも、基本、
is
じゃなくて、=
で比較すればいいのかも?
- これ知ってないとハマりそう。でも、基本、
以下のようなデータを用意
> insert into test_tinyint values (false), (true), (1), (0), (100), (-100); > select * from test_tinyint; +----------+ | bool_col | +----------+ | 0 | | 1 | | 1 | | 0 | | 100 | | -100 | +----------+
=
を使った抽出
> select * from test_tinyint where bool_col = true; +----------+ | bool_col | +----------+ | 1 | | 1 | +----------+ > select * from test_tinyint where bool_col = false; +----------+ | bool_col | +----------+ | 0 | | 0 | +----------+
is
を使った抽出
> select * from test_tinyint where bool_col is true; +----------+ | bool_col | +----------+ | 1 | | 1 | | 100 | | -100 | +----------+ > select * from test_tinyint where bool_col is false; +----------+ | bool_col | +----------+ | 0 | | 0 | +----------+
参考文献
【PHP】LaravelでのCSRF対策
LaravelにはCSRF対策が簡単にできるような仕組みが組み込まれている。また、必ずCSRF対策をしないといけない。
そのため、form
を使うときには必ず<form>
内に@csrf
を記述する必要がある
<form action="/create" method="POST"> @csrf ... </form>
@csrf
は以下のように展開される(Ub7ebV8XbFCTtZyenNoFYyK9ctDzaj09wbp2R7II
の部分は毎回、ランダムな値になる)
<form action="/create" method="POST"> <input type="hidden" name="_token" value="Ub7ebV8XbFCTtZyenNoFYyK9ctDzaj09wbp2R7II"> </form>
この_token
も他の値と一緒に送信され、検証が行われる。もし、用意したトークンと一致しなかった場合、419 Page Expired
というエラーになる
CSRF(cross-site request forgeries: クロスサイトリクエストフォージェリ)
しーさふ と読む
Webアプリケーションの脆弱性の1つ
よそのサイトの機能を呼び出す攻撃
CSRFについてかみ砕いて説明してみる – blog.ISHINAO.net
別のサイトのページから悪意のあるリクエストを受け付けないようにする必要がある
以下のような方法が一般的
参考文献
【PHP】composer globalでのインストール先
composer globalでインストールされるディレクトリは
composer global config home
で確認できる
> ls `composer global config home`
Changed current directory to /Users/user_name/.config/composer
composer.json composer.lock keys.dev.pub keys.tags.pub vendor
参考文献
【PHP】MacにPHPとComposerをインストール
brew install php
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
しっかりとインストールされている
> composer -V
Composer version 1.8.5 2019-04-09 17:46:47