My development diary

Today, I mainly did the basic data management of the test user module, and encountered a relatively large problem. The u...

Today, I mainly did the basic data management of the test user module, and encountered a relatively large problem. The user attributes are all IDS, but they need to be converted to the corresponding string type when returned to the front end, and then there are various kinds of validation of non mandatory parameters. A complex SQL, especially in the configuration of the XML file of mybatis, really let me learn for a while. Share the learning results.

The requirement diagram is as follows. Obtain the list of test users created by the current user according to several filter conditions:

The interface documentation is as follows:

All of them are required parameters. The string type defaults to "" and the number default to 0 means all.

Here is the contents of my XML file:

<sql id="table"> qa_test_user </sql> <sql id="user_status"> qa_user_status_name </sql> <sql id="env"> family_base_env </sql> <sql id="user_role"> qa_role_name </sql> <select id="findUsers" parameterType="com.okay.family.common.bean.testuser.SearchUserBean" resultType="com.okay.family.common.bean.testuser.TestUserBean"> select tu.id,tu.descc,tu.user,tu.phone,tu.password,tu.create_time,us.name status,env.name env,ur.name role from <include refid="table"/> tu left join <include refid="user_status"/> us on tu.status = us.status left join <include refid="env"/> env on tu.envId = env.id left join <include refid="user_role"/> ur on tu.roleId = ur.roleId where tu.uid = # <if test="status != 0"> and tu.status = # </if> <if test="envId != 0"> and tu.envId = # </if> <if test="roleId != 0"> and tu.roleId = # </if> <choose> <when test="type == 0 and query != null"> and tu.user = # </when> <when test="type == 1 and query != null"> and tu.phone = # </when> <when test="type == 2 and query != null"> and tu.id = # </when> </choose> </select>

Here is the content of the Java bean:

package com.okay.family.common.bean.testuser import com.okay.family.common.basedata.OkayConstant import com.okay.family.fun.base.bean.AbstractBean import org.hibernate.validator.constraints.Range import javax.validation.constraints.Min class SearchUserBean extends AbstractBean { private static final long serialVersionUID = 894894891651651L; int uid @Range(min = 0L, max = OkayConstant.ENV, message = "Environment parameter error") int envId @Min(value = 1L) int pageNum @Range(min = 5L, max = 20L, message = "Display quantity per page is set incorrectly") int pageSize @Range(min = 0L, max = 10L, message = "User identity parameter error") int roleId @Range(min = 0L, max = OkayConstant.USER_STATUS, message = "User status parameter error") int status String query @Range(min = 0l, max = 2L, message = "Search type error!0 Account 1 mobile number 2 user id") int type }

Finally, we solved this problem. The rest of US continued to move the bricks, and finally realized the difficulty of development: moving the whole body with one hair, changing the property name, and modifying no less than five disorderly places. I hope there will be fewer bugs during the test.

Hot text selection

16 June 2020, 00:46 | Views: 5592

Add new comment

For adding a comment, please log in
or create account

0 comments