1. Select the data table
2. Create the t_address table in the computer_store database
Note that name is a keyword, so it needs to be enclosed in “
Create an entity class Address under the entity package, inheriting the BaseEntity class
3.1 Development sequence of various functions
Current shipping address function module:
The first page: list display, modification, deletion, setting default address. The second page: add new shipping address
Development sequence: add new shipping address -> list display -> set default shipping address -> delete shipping address -> modify shipping address
3.2 Plan the SQL statements to be executed
1. The new shipping address corresponds to the insert statement:
2. Most platforms will specify the number of a user’s shipping address, here we specify a maximum of 20. So before inserting a new address for the user, a query operation must be performed first. If the query result is exactly 20, this is not a Java syntax exception, it can be considered a business control exception, which is thrown in the service and caught in the controller
3.3 Design the interface and abstract method
Create the interface AddressMapper, in which the abstract methods of the two SQL statements defined above are defined
3.4 Write the mapping
1. Quickly create an AddressMapper.xml mapping file:
Place the mouse on the UserMapper.xml file and press Ctrl+C, then place the mouse on the mapper folder and press Ctrl+V. In the pop-up window, change UserMapper to AddressMapper. Enter the AddressMapper.xml file, delete all the code under the mapper tag, and change the attribute value of the mapper tag to namespace=”com.cy.store.mapper.AddressMapper”
The result is as shown below:
2. Configure the mapping of the Address class attribute and the field of the table in the database in the mapper tag
Check if the mapping is configured successfully: Pressing Ctrl and clicking on type=”com.cy.store.entity.Address” in the Address, if it can jump to the Address class, it means the mapping is successful
3. Configure the mapping of the two abstract methods in AddressMapper.xml.
3.5 Unit test
Create an AddressMapperTests test class under the mapper folder in the test directory.
download lottery download and The latest plan
4.1 Plan exceptions
When inserting data, if the user does not exist (deleted by an administrator, etc.), throw the UsernameNotFoundException exception (already exists, no need to create again).
When the user’s inserted address is the first one, the current address needs to be set as the default delivery address.
Implementation method: if the total count of the query is 0, then set the is_default value of the current address to 1.
If the query result is >= 20, then it is necessary to throw a business control exception AddressCountLimitException.
An unknown exception InsertException (already exists, no need to create again) occurs when inserting data.
4.2 Design interfaces and abstract methods and implementation
1. Create an IAddressService interface and define the abstract business methods in the interface.
Because the mapper layer interface defines two abstract methods for this functional module, so it is necessary to define two abstract methods for this functional module in the service layer interface as well? Not at all, it depends on whether the two methods in the mapper layer are dependent or independent. If one abstract method depends on another, then these two methods need to be integrated into one method in the business layer. In one sentence, a functional module may require multiple SQL statements.
The origin of the three parameters in the method addNewAddress:
Firstly, there must be an address.
The business layer needs to query the total number of delivery addresses for the user according to uid and assign the value of uid to the field when creating a new address.
However, there is no control in the new delivery address form that allows input of the user’s uid, so the control layer needs to pass the uid to the business layer and encapsulate it into the address object in the business layer.
The business layer needs to modify the creator/modifier field in the database at the same time when creating/modify the delivery address.
However, there is no control in the new delivery address form that allows input of the user’s username, so the control layer needs to pass the username to the business layer and encapsulate it into the address object in the business layer.
HttpSession session can be used instead of Integer uid, String username, but in this case, it is necessary to encapsulate the methods to obtain uid and username in the BaseController class and make the AddressServiceImpl implementation class inherit from it. This requires a micro-adjustment of the code logic, which is too麻烦, and it is best to handle only the tasks of each layer. The session object is passed by the control layer, so the session object is defined and encapsulated in the control layer, and there is no need to process it extra in the business layer, which can reduce coupling.
2. Create an AddressServiceImpl class to implement the abstract methods in the interface
Don’t forget to define user.address.max-count=20 in the configuration file application.properties
4.3 Unit testing
Create the AddressServiceTests test class under the service folder in the test directory
5.1 Handling exceptions
The service layer threw an exception that the total number of shipping addresses exceeded the limit, and it was caught and handled in BaseController
5.2 Designing requests
/addresses/add_new_address postAddress address, HttpSession sessionJsonResult
5.3 Handling requests
Create AddressController under the controller package and inherit from BaseController, which is used to handle user’s shipping address requests and responses
Start the server, log in to the account, and enter http://localhost:8080/addresses/add_new_address?name=tom&phone=98745612 in the address bar for testing
The content display of the three dropdown lists on the new shipping address page does not interact with the database, but is implemented on the front end (the code logic is placed in the distpicker.data.js file). The implementation method is to load this js file when loading the new shipping address page, which is not advisable (I don’t know why)online casino helpJust need you
The correct approach is: save these data to the database, and when the user clicks the dropdown list, the corresponding data will be displayed in detail. Then, listen to which item the user selects so that the next dropdown list can perform secondary association
online casino help and The latest entrance
1. Create the t_dict_district table
code and name need to be added, parent represents the code number of the parent area, code represents the code number of itself; the parent code number of the province is +86, representing China
2. Insert province, city, and district data into the table
What are LOCK and UNLOCK used for?
Create the entity class District under the package entity (it does not need to inherit BaseEntity, but since it does not inherit BaseEntity, it needs to implement the Serializable interface for serialization)
3.1 Planning the SQL statements to be executed
3.2 Designing interfaces and abstract methods
In the future, if new modules need to be developed that still require the province, city, and district list, in order to reduce coupling, it is necessary to create a new interface
Create the interface DistrictMapper under the mapper layer
3.3 Write the mapping
Create a DistrictMapper.xml mapping file and configure the mapping of the above abstract methods
3.4 Unit testing
Create the DistrictMapperTests test class and write code for testing
4.1 Plan exceptions
No exceptions need to be handled
4.2 Design interfaces and abstract methods and implementation
1. Create an interface IDistrictService and define abstract methods
2. Create a DistrictServiceImpl implementation class to implement the abstract method
4.3 Unit testing
Create a DistrictServiceTests test class under the service folder in the test directory
5.1 Design requests
/districts/GETString parentJsonResult
5.2 Handle requests
sports betting method,come on baby
1. Create a DistrictController class and write request handling methods in the class
2. In order to be able to access the data without logging in, the districts request needs to be added to the whitelist:
Add code in the addInterceptors method of the LoginInterceptorConfigure class: patterns.add(“/districts/**”);
3. Start the server, do not log in, directly enter http://localhost:8080/districts?parent=86 in the address bar to test whether the data can be obtained normally
1. The original dropdown list display puts the data in js and dynamically retrieves the data in js, but so far we have put the data in the database, so we cannot let it use this method anymore, so we need to comment out these two lines of js code in the addAddress.html page:
Regarding these two lines of js code: the former is to obtain the data, and the latter is to display the obtained data in the dropdown list
2. Check whether there are related name attributes and id attributes (name is used to submit data, id is used to listen to user clicks) when the front-end page submits the data of provinces, cities, and districts
3. Start the server and verify on the front end whether the data can still be saved normally (except for provinces, cities, and districts)
The previous module retrieves the list of provinces, cities, and districts by obtaining the child code number through the parent code number to complete the linkage, and this module retrieves the name of the province, city, and district by itself through its own code to obtain its own name
1.1 Plan the SQL statements to be executed
Retrieve the name of the current province, city, and district according to the current code, which corresponds to a query statement
1.2 Design the interface and abstract methods
The findNameByCode method is defined in the DistrictMapper interface
1.3 Write mapping
Add the mapping of the findNameByCode method in the DistrictMapper.xml file
1.4 Unit Test
Write test code in DistrictMapperTests
2.1 Plan exceptions
No exceptions need to be handled
2.2 Design the interface and abstract method and implementation
1. Define the abstract method in the IDistrictService interface corresponding to the business layer interface
2. Implement this method in DistrictServiceImpl
2.3 Unit Testsports betting platformClick to enter
The business layer only calls the corresponding method of the persistence layer and returns, with no additional implementation, so it does not need to be tested (generally, code over 8 lines needs to be tested)
In actual development, it is not necessary to pass the control layer from the front-end, then the business layer, and then the persistence layer when obtaining the province/city/district names. Instead, when adding a new shipping address in the business layer, it is necessary to obtain the province/city/district names, that is to say, the module for obtaining the province/city/district names does not need the control layer, but only needs to be dependent on the business layer of adding a new shipping address
1. In the business layer of adding a new shipping address, encapsulate the address to store all the data, and then pass the address to the persistence layer (remember, the persistence layer will only call a method with the parameters passed to interact with the database, and there will never be any additional implementation). At this time, the business layer of adding a new shipping address does not have the province/city/district data, so it needs to rely on the getNameByCode method in the interface of the business layer corresponding to the obtaining the province/city/district list
Therefore, it is necessary to add in the business layer implementation class AddressServiceImpl
2. In the AddressServiceImpl method, encapsulate the province/city/district data obtained from the DistrictService interface into the address object, at this time, the address contains all the user’s shipping address data
Write the corresponding province/city/district display and limit the content of the corresponding tags based on the user’s different choices in the addAddress.html page
Analysis:
When loading this page, the content of the three drop-down lists is all displayed as “—–Please select—–“. If no city is selected and the district drop-down list is clicked, there is only one “—–Please select—–” in the list. When loading this page, it is necessary to automatically send a request with parent=86, then fill the returned province/municipality directly into the select tag. After clicking Sichuan Province, send a request to get the cities under it, and list the obtained cities in the city area drop-down list. If “—–Please select—–” is clicked, fill the city, county content with “—–Please select—–” and terminate the request instead of the program continuing to run. When switching provinces, replace the city, county content with “—–Please select—–”
Write JS code in addAddress.html