Knowledge Points in the Process of D Language Learning

  • Knowledge Points in the Process of Adding, Deleting and Revising

1. If we want to save the data we added, we can use the following way to check the additions and deletions of D language items.

auto repo = new xxxRepository(_cManager);
repo.save(xxx);
//So we save the information in the data table.

2. How to Search Information in D Language

auto repo = new xxxRepository(_cManager);
auto data = repo.find(id)//find(id) is used to query a single piece of information under this Id in the data table
auto data = repo.findAll//findAll is used to query all information in a data table.

3.D Language How to Delete and Delete a Message

auto repo = new xxxRepository(_cManager);
repo.removeById(id);
//removeById is used to delete a single message under this Id

4.D Language for Association Query For example, blog tables are associated with user tables

    //The information of two tables is associated in the blog table, and user_id represents Id in the user table
    @OneToOne()
    @JoinColumn("user_id")
    User  user;

  • Use of request

Request is the use of a browser's request to a server

//get type
int id = request.get!int("id", 0);//Because the request type defaults to string type
//post type
 auto id = request.post("id");//When we need character conversion, we can refer to D language character conversion, using. to!
 auto allFiles = request.allFiles();
 request.all Is to get all the values in the request
  • How to Realize Character Conversion in D Language

Numeric format and character format have different uses in different occasions, some occasions need to use digital format, some occasions need to use character format, so we need to carry out character conversion to deal with different situations.

for example
string pwd = configManager().config("hunt").hunt.redis.password.value.to!string;
// D language uses. to! For format conversion, if we want to become a string type, we will add a string after. to! If we want to become an int type, we will add an int after.to!
// Use of cast
 CAST is an expression that converts one data type into another.

for example
int now = cast(int) time();
  • Form form validation will be used when adding and modifying information. The following example is how to use D language for form validation.
if (request.methodAsString() == HttpMethod.POST.asString()) {
            auto validRes = dataForm.valid();
            if(!validRes.isValid) {
                auto errors = validRes.messages();
                foreach(error; errors) {
                    assignError(error);
                }
                return new Response(request)
                .setHeader(HttpHeader.CONTENT_TYPE, MimeType.TEXT_HTML_UTF_8.asString())
                .setContent("<script>history.back(-1);</script>");
            //If the information does not meet the criteria, it will jump back to the previous page.
  • Conditional restrictions on certain data in form form, such as length requirements
class classForm : form
{
    @Length (1,20)//Length between 1 and 20
    string classname;

    @Min(1,"Not found this. id")
    int id;

    @Range(1, 3, "No redundant options")
    int audit;

}
  • How to Use the for Loop in D Language
for loop
//for example

import std.stdio;

int main ()
{
   /* for loop execution */
   for( int a = 10; a < 20; a = a + 1 )
   {
      writefln("value of a: %d", a);
   }
 
   return 0;
}

	//Let's compile and run the above program, which will produce the following results:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Keywords: Programming Redis

Added by atawmic on Fri, 30 Aug 2019 06:52:26 +0300