MySQL query to retrieve data based on the contents of the JSON field
- Use
字段->'$.json属性'
query conditions - Use json_extract query function,
json_extract(字段, "$.json属性")
- The query json array, with
JSON_CONTAINS(字段, JSON_OBJECT('json属性', "内容"))
JSON-MySQL5.7 above operation, as well as increasing storage type JSON
general database types of data storage will be used JSON JSON type or type TEXT
Note: if using JSON type
1) JSON list of stored data must be in JSON format, otherwise it will error.
2) JSON data type is not the default value.
Examples
1, first of all we see the data table, Form_Value_ one is there josn format, want to be queried by a group or several groups which are the key.
2, it is possible to query the following statement by key, value, if a number of conditions, normal and add it.
SELECT * FROM core_process where Form_Value_ -> '$.attendancer' = '马立新'
3, if the frame is Mybatis, should> escape symbol, like a <![CDATA[ ]]>
<![CDATA[ Form_Value_ -> '$.endDate' < #{endDate,jdbcType=VARCHAR} ]]>