Cloud Notes Development Ideas

Source: Internet
Author: User
Tags mysql delete

Foreplay
Configuring the front-segment controller Web. XML configuration requires Spring-*.xml file processing *.do requests
Configure MyBatis Spring-mybatis.xml Add a data connection pool Basedatasource There are several parameters
TEST: Note The SQL for the Guide pack
Add mybatis sqlsessionfactory Configuration ref
Org.mybatis.spring.SqlSessionFactoryBean
Add Mapper Interface Scanner configuration
Org.mybatis.spring.mapper.MapperScannerConfigurer

Services.msc E:\tts9\mysql Delete files C:\ProgramData hidden folders Delete mysql
Install MySQL second, then select Path
Import MySQL Day01
Create Database Cloud_note;
Set names UTF8;
SOURCE E:/cloud_note.sql;
Update cn_user set cn_user_password= ' 23f97b1171789885989406b36f3d4035 ';
23f97b1171789885989406b36f3d4035

Test DataSource sqlsessionfactory Mapperscanner getbean instantiate output test separately
Add ready-to-use data to the database
======================================================================
Add a Save method to the DAO package save
function Trimstr (str) {return str.replace (/(^\s*) | ( \s*$)/g, "");} JS Trim ()
Org.apache.ibatis.binding.BindingException:Invalid bound statement (not found): Cn.sm.note.dao.UserDao.saveUser
The exception estimate is that there is no SSF configuration problem, and the Bean factory
Add the Mapperscan configuration to the SSF configuration
Org.apache.ibatis.binding.BindingException:Invalid bound statement (not found): Cn.sm.note.dao.UserDao.saveUser
Sqlid wrong
Org.springframework.jdbc.BadSqlGrammarException:
/* Error querying database. Cause:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:You has an error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near ' as id,cn_user_name as Nam E,cn_user_password as Password,cn_user_token a ' at line 2*/
An alias was given when the query was made
Org.springframework.dao.DuplicateKeyException
Primary key is not unique, replication is really hard to control, two save () ....

A null pointer appears when the field does not match the entity class

Userdao adding Finduserbyname Method Parameters Username,password->userservice
Usercontroller using Jsonresoult to return JSON objects
This tool class contains generic data (this is a well-designed), exception, and a status message
Zhoujia123 23f97b1171789885989406b36f3d4035
Write controller-> Interface Integration

In the persistence layer, the user name can be used to find the corresponding user, if present, the user information is returned

Login.js
Find the ID of the user name and password, make a reasonable test, use Ajax to send an asynchronous request, find out how the rules give hints
Login user Name id= "count" password id= "password" Find user name after login bind mouse remove Event
The specific process is as follows
Loginaction Login Action---account checking in order to display error messages, span id= "count-msg" after account and reasonableness rule validation
If the requirements are met, it is clear that the error message displayed by Count-msg can be used to bind the account to a focus, when logging in
The same password are the same.

Add Login Event Check method Loginaction ()
Operation: The account meets the requirements, the Direct tab to the password, prompt, if all is correct click () #login button;
Send Ajax request, state==0, jump to edit.html? Url,data,datatype,success,error
After state returns 0, jump to edit.html page//tip: Use Location.href

The Mapper method ID is sqlid and the package is a namespace. If a mismatch occurs, the binding fails

Step
We have already saved some debugging information in the database
in the persistence layer, through the user name can find the corresponding user, if there is the user information is returned to the client object
Business layer, the realization of the login function logic, To make a reasonable check call the persistence layer method if the user is not found to throw a user name error or password exception, hand over to the user to handle
login success, return user Information
Presentation layer according to the request, call different controller processing
I goalkeeper processing results, Through Jsonresult encapsulation, call the business Layer login method, the same AJAX request message (JSON) sent to the page,
Login successfully redirected to the editing module, login failed to give hints
interface Integration
The landing page based on jquery to find the corresponding control to make a simple judgment, do not meet the requirements to give the prompt
to the login button to bind an event, if the account password through the rules to verify, to the server to initiate an AJAX request
Request parameters include the user name, account information, post method to submit
Successful request returns a JSON, based on status code 0 success 123 failed
to give hints or redirect to the editing interface
========================================================= ================
2. Registering a module
password needs to be encrypted when the user registers
use, add Salt Digest, first combination of password and salt, that is, any set of strings, by the MD5 algorithm saved to the database, Effectively improve the security of the password.
Need Commons-code Package
Userservice->usercontroller//username=username.trim (); User-friendly wipe operation, if the space is more than the next bad landing
for the first time refactoring , the exception part is slightly cumbersome
Refactoring login method Usercontroller

Interface Integration->edit.html the same, in Login.js
Observe the log_in.html. On the annotations page, there is a span in the DIV after the user name with an error message, except that display is none, which is the equivalent of hide (), and does not display
Send Ajax request, register using $.post (url,data,function (Result) {})
Registration process seems to have a little trouble, because of the use of Salt Digest, password + you eat it? Take MD5 value into the database, so when the login need to add salt after the password and data in the comparison of the password?
It really needs to be compared, but then it needs to be refactored.

Landing
Persistence layer, which saves the information as a user object to the database based on information such as username, password, etc.
Business layer, the same for reasonable inspection (not NULL, rule 3-10: If the user already exists, call the persistence layer's Save method and return a user
The control layer invokes the business layer's register method, sending JSON to the page successfully or not,
Go back to landing page or prompt message
@ExceptionHandler Unified processing can simplify the writing of the Controller method.
Interface Integration
In the previous step, jquery has been introduced. Selector find registration name, nickname, password, confirm password preliminary test
Inspection by clicking the Register button, you want the server to initiate an AJAX request, the information on the page as a parameter to the server, the server (pass the parameters to the service layer method, and call the service Layer registration method, check: Continue to call persistent layer to save user information) Return JSON object, save successfully back to landing page, fail to give hint

There are some user-friendly skills, when submitting the account password can be removed from the extra space
As well, when you return to the registration page, you can simply fill in the login page with the user's newly registered account.
The process is this, with the user's information returned in the JSON,
var user =result.data;
Name=user.name. Get the username of the account you just registered

=========================================================================
Implementing the Notebook List feature
After loading the edit.html page, display the notebook list, according to the user ID in the database query belongs to the user's notebook, id where, when landing can be saved (concrete implementation)
Use list to save the queried notebooks.
Experience using map to encapsulate query results to reduce traffic and improve software efficiency
Map<string,object> key for Notebook Id?value is notebook name?

Idea One:
Originally my idea was that the return value is notebook, assuming that I am returning notebook should also be able to do
Find all notebooks based on UserID, find more than one piece of data, which means there may be a lot of this note
stored in the list collection, each record is a notebook object? Yes, test it.
Notebookcontroller calls Notebookservice's Findnotebookbyuserid
By passing in a userid, you can find out all the notebooks.
Idea two:
In fact, querying all of the fields, returning a notebook object compares the effects of performance, and now I just
Follow the UserID to get Notebookid and notebookname.
At this point, you can use map to increase the efficiency of the queried ID as key,name as value

Returns the query result for the map type. A record corresponds to a Map object with the field name as key and the field value as value
Map, a field corresponding to a key,value
{Key:value,key:value},
{id:1101,name: Reading notes}

Tip, if you need only the values of several fields in a record, you can use map as the query result

Show Notebooks


************************************************************************
1, get the security of the method is less than the post, including confidential information, it is recommended to use the Post data submission method;
2, in the data query, you can use Get method, because it is efficient, and in the data add, modify or delete, it is recommended to use post, because it is safe;
As for Ajax, it's simpler: Ajax is asynchronous, post is synchronous, and as for very fine distinctions,
Edit_init.js part
Show notebook list after page load
Click Notebook Li to display all the notes for this notebook

Notebook
Save the UserID.
====================================================================
Loadnotebookaction ();
Model.updatenotebooks (list); Save the query out of all the notebooks, List.do returned to NB 16
Model.notebooks NB 36 times calendar Get each note
When I put Li on the UL, I deposited the notebooks subscript I NB 41

$ (' #notebooks '). On (' Click ', ' Li ', shownotesaction);
Bubble get Li, just save index, take out
Add effect, checked
Model.shownotes (Notebookindex), Show all notes
And put the This.notebookindex=notebookindex in the notebook.
A single notebook can be obtained according to the subscript
Model.updatanote (Notes) Displays the note to the interface
If this.notes=notes to save all the notes.
Send Request, traverse (if I=this.noteindex has checked effect)
Hang to the notes under the UL
function Loadnoteaction Gets the ordinal of the selected element index
Model.loadnote=function (index) Load selected notes to send data with get90
Model.updatanote=function (note,newnotes) Displays the note object to the edit area
function Savenoteaction () Handles the Save button event #input_note_title
Get the note ID from model
Model.updatetitle=function (title)
function Showaddnotedialog () response to the Add Note button event, open the Add Note dialog box
function addnoteaction () Handle Click Save Note button Event

The Blur event occurs when an element loses focus.
Ctrl+i can be typeset

The persistence layer looks for the user's notebook based on the userid into the database, returning the result of the map type
Because only need to query, notebook ID and the name of the notebook, other irrelevant not required (not all bad back)
Reference
<!--return query results for map type
Map is the shorthand form of JAVA.UTIL.MAP
-
<select id= "FindById2"
parametertype= "int"
Resulttype= "Map" >
SELECT * FROM emp WHERE id = #{id1}
</select>

@Test
public void Test6 () {
Map data =
Session.selectone (
"Test.findbyid2",
23);
Note that the field names are capitalized,
Oracle converts field names to uppercase.
System.out.println (
Data.get ("ename"));
Session.close ();
}
Specifically not detailed, I think it is necessary to need a few fields to return a few fields, more flexible, if not, change back later
November 26, 2016 16:44:32
The business layer calls the persistence layer, according to the ID of the method to find a notebook, reasonable check (ID, exists ...) Returns list because one user notebook is more than one
The presentation layer invokes the Listnotebook method of the business layer, and if found, sends the information in JSON to the page
Integration page
Write the method of editing the page in a JS, Edit_inti also includes the operation of global variables
Focus on the Var model={} JS Object * * * can be used when defining properties and methods
On the landing page, use the Setcookie tool method to store the UserID in a cookie when you log in,
In the edit page, you can remove the ID from the cookie and send an AJAX request to the server via $.getjson.
-----------------------------------------
As a supplement:
$.getjson This method to get data from the server to return the data must be a JSON object, otherwise the callback function Xhr object is empty, jquery will first convert this method to the corresponding JS object
$.post $.get two ways to submit
---------------------------------------------
Based on the return, JSON is essentially a list of many notebook IDs and notebook names
Use the Model object to update the list of notebooks, add a updatenotebooks (), go to the edit screen, follow the new notebook list, pass the template, and then hang Li under UL
====================================================================

With the new Notes list
November 27, 2016 10:37:27
Time is too late, just a simple understanding


Save Notes feature
Interface Integration
Click the Save button to initiate an AJAX request to the server, which includes the header title, the body of the content, and the notebook ID noteid. First on the edit page, make reasonable checks such as:
Check if title is empty
The rule I set is not empty. Then judge whether the title and body change

Send the Title\body as a parameter to the server,/note/save.do
If it fails, the popup window prompts.
On the server, the front controller calls the response controller according to the handlemapping configuration, passes the parameters to the business layer, calls the persistence layer's Save method, returns an int value, the business layer determines whether the value is one,
If one, the description is saved successfully, return to the controller a true, otherwise return flase.
The edit page accepts JSON return results for response processing
In the persistence layer, you use MyBatis to dynamically pass parameters to implement code reuse. The realization of dynamic splicing function of MyBatis by determining whether the parameters are passed through the ID tag test property

Add Notes feature, similar to the features of notebooks
The persistence layer adds a method to save notes based on note, which accepts the note object to return an int value
Configuring in the Notemapper.xml mapping file because of the many conditions, you can test it first
In the business layer, the required parameters are the user ID, the notebook id,title,body (can have
Conduct reasonable inspection, determine whether it is empty, and whether the user && notebook exists etc.
Other into Noteid can be automatically generated, the modification time is the current time ...
This information is saved as a note object called by the Add method of the persistence layer
If added successfully returns 1, the note object is returned
The parameters in the control layer that accept the AJAX request, the method is called by layer, and the JSON object of note is returned successfully.
Integration page
Click the Add button, pop up the Add Note dialog box, call the relevant method display ...
$obj. Load (), to place the returned data in the specified element
You can get the user ID and the notebook ID from the model data models to get the notebook first and then get it based on the subscript
Explain, because it is sent through the list, according to the subscript and get (i) the effect of the same
Sends an AJAX request to get the note object returned.
Call a method with a new notebook updatenote () <--refactoring

Implement login permission Check,
The principle is to add tokens to the cookie. Check that tokens are consistent on each login, and that inconsistencies fail to log in, and the spring listener comes in and the filter
Refactoring business layer Userserivie, adding methods for checking UserID and Token
Filters implement the Filter interface. Check the request path
Init, the UserService object is obtained through the container
Business processing in Dofileter
Obtain the UserID from the cookie, and token calls the business layer's method to check, match the condition return true, the normal execution business
Back to Flase redirect to landing page

Cloud Notes Development Ideas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.