Learning record on November 1, 2021

1.Mybatis reverse engineering

Reverse engineering is that mybatis directly helps us generate the corresponding entity class, the corresponding persistence layer method and the corresponding mapping xml file through the database table.

There are only two things we need to do:

1. Write configuration file

2. Start through Java class

1.1 write configuration file:

From what reverse engineering has done, we should specify at least the following configurations in the configuration file:

1. Specify the database to connect to

2. Specify the entity class generated by the table, the persistent class method, and the location where the mapping file should be stored.

3. Specify the table to reverse and the name of the generated class

1. Database related configuration

  <context id="context"    targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--Database link address account password-->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/emp?serverTimezone=UTC" userId="root" password="123456">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

2. Specify the generation location

 <javaModelGenerator targetPackage="com.example.mgb.pojo" targetProject="./src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--Storage location of generation mapping file-->
        <sqlMapGenerator targetPackage="Mybatis" targetProject="./src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--generate Dao Class storage location-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.mgb.dao" targetProject="*/src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

3. Specify the reverse table and the generated class name

<table tableName="t_emp" domainObjectName="emp" ></table>
        <table tableName="t_dept" domainObjectName="dept"></table>

2. Startup (in the form of java classes) the startup method is relatively fixed. You only need to copy it from the official document and modify the path of the configuration file to your own configuration file path.

  @Test
    public void runMgb() throws Exception{
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        File configFile = new File("D:\\programming\\mbg\\src\\main\\resources\\MBG.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }

2. Common linux commands

ps view executing processes

Optional parameters: - a: display all

-u: Displayed process information in user format

-x: Displays the parameters for the background process to run

-e: Show all processes

-f: Full format display

kill process number

Kill process name

-9 forcibly terminate the process

Start a service: / bin/ststemctl start service name

View process tree: pstree

-p displays the process number

-u display user information

Instructions related to service management: service name [start|stop|restart|reload|status]

setup view all commands with * for self starting applications

  User: the user who created the process

PID: process number

%CPU: percentage of CPU consumed

%MEN: percentage of physical memory used

VSZ: size of virtual memory occupied by the process

RSS: the amount of physical memory occupied by the process

TTY: terminal name (abbreviation)

STAT:       Process status   S-sleep, s indicates that the process is the leader of the session, N indicates that the process has a lower priority than the normal priority, R-running, D-short-term waiting, Z-dead process, Y-tracked or stopped, etc

START: process START time

TIME: total CPU TIME consumed by the process

COMMAND: the COMMAND and parameters used to start the process

Keywords: Java Back-end

Added by sungpeng on Mon, 01 Nov 2021 14:19:35 +0200