Recently in the Watch Learning spark Framework.
This is a web framework, as its website link shows: SPARK-A Micro framework for creating Web applications in Kotlin and Java 8 with minimal effort
I follow its example to learn. Here comes the Blogservice project [portal], which is also an example of the main line step-by-step. The corresponding github[portal]
I am this machine is MySQL, need to note:
MySQL does not have a UUID data type, I use char (50) instead, so the whole project also corresponding to modify the reference type.
As for the char (50) type, it can be interfaced directly through the string type in Java.
Here are some of the problems that you have encountered:
Question 1: Could not acquire a connection from datasource-no suitable driver found for Jdbc:mysql://localhost:3306/blog
This is because there is no MySQL connection driver problem, it is recommended to search [MySQL repository] inside search [Mysql-connector-java] Select MySQL connector/j
Select the corresponding version after entering. For example, mine is 5.14, after the entry.
Add this to Maven <dependencies> and re-mvn compile the project again
The dependencies for these MAVEN downloads will eventually be stored in ~/.m2/repository .
Small tips: When I check this question online, someone actually put mysql-connector-java-bin.jar this ready-made jar package into .../jre/lib/ext/
This, of course, can solve the problem, but it should not be.
There are 2 main reasons:
- This bypassed the classpath. When other class files are loaded manually, they do not work properly if they exist on the extension path.
- Programmers often forget where the files were stored 3 months ago. When the ClassLoader ignores roost's carefully designed classpath, programmers will find them in the header file without a clue. In fact, loading is a class that has been forgotten for a long time on the extension path.
Question 2: when I just finished installing the database,
mysql> show databases;ERROR 1820 (HY000): Must reset your password using ALTER USER statement before executing this ....
This time only needs to set (the user initializes) the password can be
mysql> Set Password = password (' Your_password ');
Question 3: when I want to let my Blogservice remote connection database, how to fail, I also open the permissions, also set up a firewall.
So I found a computer in the LAN with MySQL to try to connect themselves, found that the error number 111
Originally, MySQL in the configuration file also has a layer of settings, so that only localhost connection.
Try to find the configuration file (each version may be different, you have to find), to find such a sentence
--bind-address= "localhost"
Comment out, or change to "*", or you want to connect your own IP
Question 4: The Blogservice Post accepts only one JSON object: If I was in an array form, he would not be able to receive
So I have to find a way to solve the problem of this parsing. Logically, it is dependent on the JSON parsing package has a corresponding method, but I chose a familiar one.
First go to [maven repository] search [json-lib]
But be aware that this is not feasible, it actually needs a support: The complete should be:
<dependencies> <!--https://mvnrepository.com/artifact/net.sf.json-lib/json-lib-- < dependency> <groupId>net.sf.json-lib</groupId> <artifactid>json-lib</ artifactid> <version>2.4</version> <classifier>jdk15</classifier> </ Dependency>
MVN compile, introduce the package in the code
After that, the key is:
arraylist<v> value = new arraylist<v> (); if (valueclass! = emptypayload.class) { //If payload is not empty Jsonarray Js_a = Jsonarray.fromobject (Request.body ()); for (int i = 0; i < js_a.size (); ++i) { System.out.println (((jsonobject) js_a.get (i)). ToString ()); V tmp = Objectmapper.readvalue (((jsonobject) js_a.get (i)). ToString (), valueclass); Value.add (TMP); } }
If the payload is non-empty, such as the Post/get type, then the Request.body () whole string is read into Jsonarray
Then, traverse the jsonarray to make it into a Java object.
Note Protected abstract Answer Processimpl (arraylist<v> value, map<string, String> urlparams, Boolean Shouldr eturnhtml); The function declarations in these places should be modified as well.
It is also the time of post, even an object that needs to be sent as an array, in the form of a JSON array:
[
{
"param1": "Value_string",
"Param2": Value_num
...
},
{
"param1": "Value_string",
"Param2": Value_num
...
}]
Example of using SQL2O to connect data in Spark Blogservice