Computer room charge System--When converting list generics, field names do not correspond to problems

Source: Internet
Author: User

As a result of the previous study of generics, we began to try to add the use of generics in the machine room fee system reconfiguration. But to do the student to check the balance of this function, or follow the previous method, but when loading the data class this box does not show up ... And I was wondering.



I'm going to go see this section of code, found that there is no problem ah, are in the assignment, and then I was a single-step debugging, but also walked that sentence assignment code, but there is no value, why the other is OK, so I am very puzzled, because this place I used the view, I think the view is a problem, and then to check my view. But I think about it, the view is a virtual table, as long as it is built, and directly tune the database table is the same thing, so should not be the view of the problem, through the elimination method, I found the root of the problem-the database field! This field in the database is class, but I'm going to see that the fields in my entity are written in Sclass, because class is a keyword, so it can only be defined as Sclass, and this field is different from the field in the database, the other fields are the same, and I let him return generics, So only this field can cause problems.

Code:




View fields:



Database fields:



Then I changed the field in the database to be the same as the entity, so I succeeded!

To modify a database field:



To modify a view field:



Successful display:


Because the generic parameter (in angle brackets) is written as an entity class, when executed, the attribute name of the entity class is automatically obtained, and then the DataTable matches the field with the name, and some values are assigned. Each row of records in a DataTable is handled this way. So we should make the attribute name of the entity class exactly the same as the field name in the database table.

Summary: Sometimes we think we understand this new knowledge, will use, in fact, we just did not encounter problems, only more use, more problems, we can really more and more understand, this is what we say in the problem of growth!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Computer room charge System--When converting list generics, field names do not correspond to problems

Related Article

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.