Resultmap in the sqlmap file:
< Resultmap ID = "Productandpackageresult" Class = "Productandpackage" > < Result Column = "ID" Property = "ID" Jdbctype = "Decimal" /> < Result Column = "Name" Property = "Name" Jdbctype = "Varchar" /> < Result Column = "Disctription" Property = "Disctription" Jdbctype = "Varchar" /> < Result Column = "Duration" Property = "Duration" Jdbctype = "Decimal" /> < Result Column = "Status" Property = "Status" Jdbctype = "Decimal" /> < Result Column = "Ad_count" Property = "Adcount" Jdbctype = "Decimal" /> < Result Column = "Begin_time" Property = "Begintime" Jdbctype = "Date" /> < Result Column = "End_time" Property = "Endtime" Jdbctype = "Date" /> < Result Column = "Market_price" Property = "Marketprice" Jdbctype = "Decimal" /> < Result Column = "Price" Property = "Price" Jdbctype = "Decimal" /> < Result Column = "Release_tel_num" Property = "Releasetelnum" Jdbctype = "Decimal" /> < Result Column = "Relevance_tel_num" Property = "Relevancetelnum" Jdbctype = "Decimal" /> < Result Property = "Productpackagelist" Column = "{Productid = ID, areaid = areaid, status = status }" Select = "Productpackagesql. getbyproductid" /> </ Resultmap >
Note:ProductpackagelistThe field is.Select= "Productpackagesql. getbyproductid.
GetbyproductidThe SELECT statement of is as follows:
< Select ID = "Getbyproductid" Resultmap = "Productpackageresult" Parameterclass = "Java. util. hashmap" > Select * From tb_product_package where product_id = # productid # < Isnotnull Property = "Areaid" Prepend = "And" > Area_id = # areaid # </ Isnotnull > < Isnotnull Property = "Status" Prepend = "And" > Status = # status # </ Isnotnull > </ Select >
ProductandpackageresultUsage:
< Select ID = "Getlist" Resultmap = "Productandpackageresult" Parameterclass = "Java. util. Map" > Select ID, name, disctription, duration, status, price, ad_count, begin_time, end_time, market_price, price, release_tel_num, relevance_tel_num, # areaid # As areaid, # status # As status from tb_product < Dynamic Prepend = "Where" > < Isnotempty Prepend = "And" Property = "Productid" > Id = # productid # </ Isnotempty > </ Dynamic > Order by ID </ Select >
It should be noted that this word query has three parameters. Generally, the relationship between the primary key and the foreign key is one-to-many. This solution is to solve this possible multi-parameter situation.
The key of the example is to use# Areaid # As areaid, # status # As status, which can be used in Word query.StatusAndAreaidThese two parameters.