My development diary

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">

    <sql id="user_status">

    <sql id="env">

    <sql id="user_role">

    <select id="findUsers" parameterType=""
        select,tu.descc,tu.user,,tu.password,tu.create_time, status, env, role from
        <include refid="table"/>
        left join
        <include refid="user_status"/>
        us on tu.status = us.status
        left join
        <include refid="env"/>
        env on tu.envId =
        left join
        <include refid="user_role"/>
        ur on tu.roleId = ur.roleId
        where tu.uid = #{uid}
        <if test="status != 0">
            and tu.status = #{status}
        <if test="envId != 0">
            and tu.envId = #{envId}
        <if test="roleId != 0">
            and tu.roleId = #{roleId}
            <when test="type == 0 and query != null">
                and tu.user = #{query}
            <when test="type == 1 and query != null">
                and = #{query}
            <when test="type == 2 and query != null">
                and = #{query}


Here is the content of the Java bean:


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.

  • The official account is that the public number "FunTester" starts, and welcomes attention and prohibits the third party from reprinting. More original articles: FunTester 18 original albums , please contact .

Hot text selection

Tags: Programming SQL xml Java Mybatis

Posted on Tue, 16 Jun 2020 00:46:03 -0400 by RynMan