Service tier Business
Package Com.zx.common.service.impl;import Com.zx.common.entity.sysuser;import Com.zx.common.mapper.SysUserMapper; Import Com.zx.common.service.sysuserservice;import Com.zx.common.util.dateutil;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.service;import Org.springframework.transaction.annotation.transactional;import java.util.list;import Java.util.UUID; @Service (" Sysuserservice ") public class Sysuserserviceimpl implements Sysuserservice {@Autowired private sysusermapper Sysuser Mapper; @Override public list<sysuser> Selectalluser () {return sysusermapper.selectalluser (); } @Transactional (rollbackfor = {Exception.class}) @Override public void Updateuserinfotimer () {//based on the date of the previous day Rename Sys_user to Sys_user_ on Day date String beforedatestr = Dateutil.getbeforedatestring (); String rename = "Sys_user_" + Beforedatestr + uuid.randomuuid (). toString (). substring (0,16); Sysusermapper.renametable(Rename.replace ("-", "")); New Sys_user table sysusermapper.createtable (); }}
Mapper Layer Interface
Package Com.zx.common.mapper;import Com.zx.common.entity.sysuser;import Org.apache.ibatis.annotations.Param; Import Java.util.list;public interface Sysusermapper { list<sysuser> selectalluser (); void Renametable (@Param ("TableName") String tableName); void CreateTable ();}
Mapper.xml
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >< Mapper namespace= "Com.zx.common.mapper.SysUserMapper" > <resultmap id= "baseresultmap" type= " Com.zx.common.entity.SysUser "> <id column=" id "property=" id "jdbctype=" INTEGER "/> <result column=" USER NAME "property=" username "jdbctype=" varchar "/> <result column=" PASSWORD "property=" PASSWORD "jdbctype=" varchar "/> </resultMap> <sql id=" base_column_list "> ID, USERNAME, PASSWORD </sql> <update id=" re NameTable "parametertype=" java.lang.String "> Rename table Sys_user to ${tablename}; </update> <update id= "createtable" > CREATE TABLE sys_user (ID INT (one) not NULL auto_increment COMM ENT ' primary key ', USERNAME varchar (+) NOT null default ' ', PASSWORD varchar (+) NOT null default ', PRIMARY Key (ID), key I_sys_user_userNAME (USERNAME)) Engine=innodb DEFAULT charset=utf8 comment= ' user table '; </update></mapper>
Mysql + mybatis Dynamic Build table