Table 1

The front end requires you to look up the ‘name’ from Table 2 based on ‘category_id’ in Table 1 and return to the page

  • For the first time, I did two queries, which encapsulated the objects of two tables into a List. This is very unreasonable and ugly, and returned all the data of two tables
  • After finding unreasonable, use left link query, query results

    Add a field “name” to the entity class in table 1 and wrap it in the query

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

2019.4.15 update

  • This time the project query needs to join four tables. The SQL of the query is written quickly, using inner join
SELECT
	p1.id,p1.brand_id,p1.name "Trade Name",
	p2.NAME "Commodity Classification Ii",
	p4.NAME "Commodity Classification Level I",
	p3.vertify_man "Auditor",
	p3.STATUS "Audit Status",
	p3.detail "Audit Details"
FROM
	pms_product p1,
	pms_product_category p2,
	pms_product_vertify_record p3,
	pms_product_category p4 
WHERE
	p1.product_category_id = p2.id 
	AND p1.id = p3.id 
	AND p2.parent_id = p4.id
	AND p1.id = 1;
Copy the code

The query results

Because the other table is not many fields and is based on the commodity table (PMS_product) added, so to add the corresponding field in the commodity table entity class, the above is directly added in the commodity class, which is equal to modify the original entity class, personal feeling is not very good, so I wrote another class to inherit the commodity table entity class

mapper.xml

  • But I just solved it today, I didn’t solve it last Saturday, I was too stupid

  • And then all of this is wrapped with the value of the first name

  • After the occurrence of this problem, has been thinking is not the query method is not appropriate to cause, thinking about using sub-query, because did not write out the sub-query did not get
  • You can use aliases on Monday, haha

  • So let’s see what happens