当前位置: 首页 > news >正文

有没有什么网站可以直接在网上做试题并且可以给你判出来南京搜索引擎推广优化

有没有什么网站可以直接在网上做试题并且可以给你判出来,南京搜索引擎推广优化,微网站怎么做,盗qq钓鱼软件目录 一、Mybatis插件简介🥙二、工程创建及前期准备工作🥫实现代码配置文件 三、插件核心代码实现🍗四、测试🥓 一、Mybatis插件简介🥙 Mybatis插件运行原理及自定义插件_简述mybatis的插件运行原理,以及如何编写一个…

目录

  • 一、Mybatis插件简介🥙
  • 二、工程创建及前期准备工作🥫
    • 实现代码
    • 配置文件
  • 三、插件核心代码实现🍗
  • 四、测试🥓

一、Mybatis插件简介🥙

Mybatis插件运行原理及自定义插件_简述mybatis的插件运行原理,以及如何编写一个插件-CSDN博客

MyBatis 是一款优秀的持久层框架,它简化了数据库操作过程,提供了强大的 SQL 映射功能。MyBatis 插件是用来扩展 MyBatis 框架功能的工具,可以通过插件来定制和增强 MyBatis 的功能。

MyBatis 插件可以用来实现一些自定义的功能,比如拦截 SQL 语句、修改 SQL 语句、添加新的功能等。通过插件,我们可以在 MyBatis 框架的各个阶段进行干预和扩展,从而实现更灵活、更强大的功能。

通常情况下,编写一个 MyBatis 插件需要实现 MyBatis 提供的接口,并在配置文件中注册插件。Mybatis只支持针对ParameterHandler、ResultSetHandler、StatementHandler、Executor这4种接口

总的来说,MyBatis 插件是一种扩展机制,可以让我们更好地定制和增强 MyBatis 框架的功能,使得我们能够更好地适应各种不同的业务需求。

二、工程创建及前期准备工作🥫

以下都为前期准备工作,可直接略过,插件核心实现代码在第三节

PixPin_2024-03-11_14-26-17

PixPin_2024-03-11_14-27-44

创建test数据库

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`  (`id` int NOT NULL AUTO_INCREMENT,`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,`create_time` datetime NULL DEFAULT NULL,`update_time` datetime NULL DEFAULT NULL,PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;SET FOREIGN_KEY_CHECKS = 1;

实现代码

本实验省略了Controller和Service

User.java

package com.example.mybatisplugin.entity;import com.example.mybatisplugin.anno.FiledFill;import java.io.Serial;
import java.time.LocalDateTime;
import java.util.Date;
import java.io.Serializable;/*** (User)实体类** @author makejava* @since 2024-03-11 14:41:35*/
public class User implements Serializable {@Serialprivate static final long serialVersionUID = 813676794892349198L;private Integer id;private String username;private String password;@FiledFill(fill = FiledFill.FillType.INSERT)private Date createTime;@FiledFill(fill = FiledFill.FillType.INSERT_UPDATE)private Date updateTime;//省略了getter和setter方法@Overridepublic String toString() {return "User{" +"id=" + id +", username='" + username + '\'' +", password='" + password + '\'' +", createTime=" + createTime +", updateTime=" + updateTime +'}';}
}

其中@FiledFill注解是自定义注解,文章后面会写到,可暂时不用添加

UserDao.java

@Mapper
public interface UserDao {/*** 新增数据** @param user 实例对象* @return 影响行数*/int insert(User user);/*** 修改数据** @param user 实例对象* @return 影响行数*/int update(User user);}

UserDao.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.example.mybatisplugin.dao.UserDao"><resultMap type="com.example.mybatisplugin.entity.User" id="UserMap"><result property="id" column="id" jdbcType="INTEGER"/><result property="username" column="username" jdbcType="VARCHAR"/><result property="password" column="password" jdbcType="VARCHAR"/><result property="createTime" column="create_time" jdbcType="TIMESTAMP"/><result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/></resultMap><!--新增所有列--><insert id="insert" keyProperty="id" useGeneratedKeys="true">insert into user(username,password,create_time,update_time)values (#{username},#{password},#{createTime},#{updateTime})</insert><!--通过主键修改数据--><update id="update">update user<set><if test="username != null and username != ''">username = #{username},</if><if test="password != null and password != ''">password = #{password},</if><if test="createTime != null">create_time = #{createTime},</if><if test="updateTime != null">update_time = #{updateTime},</if></set>where id = #{id}</update>
</mapper>

配置文件

application.yaml
数据库密码记得改成自己的

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: *****url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
server:port: 8080
mybatis:config-location: classpath:mybatis-config.xmlmapper-locations: classpath:mapper/*.xml

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><settings><!-- 设置驼峰标识 --><setting name="mapUnderscoreToCamelCase" value="true"/><!-- 打印SQL语句 --><setting name="logImpl" value="STDOUT_LOGGING"/></settings>
</configuration>

三、插件核心代码实现🍗

自定义注解FiledFill

package com.example.mybatisplugin.anno;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;/*** @Author YZK* @Date 2024/3/11*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FiledFill {enum FillType {INSERT, INSERT_UPDATE,}FillType fill();
}

插件核心代码

package com.example.mybatisplugin.plugin;import com.example.mybatisplugin.anno.FiledFill;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;/*** @Author YZK* @Date 2024/3/11* @Desc*/
@Intercepts({@Signature(type = Executor.class,method = "update",args = {MappedStatement.class, Object.class})})
public class MybatisAutoFill implements Interceptor {private static final Logger LOGGER = Logger.getLogger(MybatisAutoFill.class.getName());public Object intercept(Invocation invocation) throws Throwable {MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];//获取操作类型(INSERT和UPDATE)SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();//拿到SQL中传入的对象Object obj = invocation.getArgs()[1];//获取其字节对象Class<?> clazz = obj.getClass();//获取User类声明的所有字段Field[] fields = clazz.getDeclaredFields();//通过区分SQL的操作来进行不同的字段填充if (sqlCommandType == SqlCommandType.INSERT) {//是INSERT操作的话就同时填充createTime和updateTime字段fillInsertFields(obj, fields);} else if (sqlCommandType == SqlCommandType.UPDATE) {//是updateTime字段的话就只填充updateTime字段fillUpdateFields(obj, fields);}return invocation.proceed();}private void fillInsertFields(Object obj, Field[] fields) {Arrays.stream(fields)//过滤出所有带有@FiledFill注解的字段.filter(field -> field.isAnnotationPresent(FiledFill.class)).forEach(field -> {try {//对字段进行填充setFieldValue(obj, field);} catch (IllegalAccessException e) {LOGGER.log(Level.SEVERE, "字段填充错误", e);}});}private void fillUpdateFields(Object obj, Field[] fields) {Arrays.stream(fields)//过滤出所有带有@FiledFill注解的字段,以及注解值为INSERT_UPDATE的字段.filter(field -> field.isAnnotationPresent(FiledFill.class) &&field.getAnnotation(FiledFill.class).fill() == FiledFill.FillType.INSERT_UPDATE).forEach(field -> {try {//对字段进行填充setFieldValue(obj, field);} catch (IllegalAccessException e) {LOGGER.log(Level.SEVERE, "字段填充错误", e);}});}private void setFieldValue(Object obj, Field field) throws IllegalAccessException {//填充字段field.setAccessible(true);field.set(obj, new Date());}
}

mybatis-condig.xml配置文件中进行配置,将自定义的插件注册

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC"-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><settings><!-- 设置驼峰标识 --><setting name="mapUnderscoreToCamelCase" value="true"/><!-- 打印SQL语句 --><setting name="logImpl" value="STDOUT_LOGGING"/></settings><plugins><plugin interceptor="com.example.mybatisplugin.plugin.MybatisAutoFill"/></plugins>
</configuration>

四、测试🥓

插入操作

@Test
void contextLoads() {User user = new User();user.setUsername("笑的像个child");user.setPassword("123456");userDao.insert(user);
}

控制台打印的SQL

image-20240311225847571

image-20240311225857627

进行插入操作时create_time和update_time字段被同时填充

更新操作

    @Testvoid contextLoads() {User user = new User();user.setId(33);user.setUsername("笑的像个child");user.setPassword("12345678");userDao.update(user);}

控制台打印的SQL

image-20240311225948551

image-20240311230032331

进行更新时操作时update_time字段被填充

进行删除操作时,如果是硬删除,则记录被删除,软删除时同样是更新操作,字段也会被自动填充。

本插件还有许多需要完善的地方,只是自动填充的简单实现,如有需要,可以自己完善。


文章转载自:
http://impellent.rhmk.cn
http://ragefully.rhmk.cn
http://preclusion.rhmk.cn
http://declaredly.rhmk.cn
http://gawkily.rhmk.cn
http://micturition.rhmk.cn
http://goldwasser.rhmk.cn
http://manchurian.rhmk.cn
http://antecessor.rhmk.cn
http://shintoism.rhmk.cn
http://hypodermis.rhmk.cn
http://synonymous.rhmk.cn
http://outsang.rhmk.cn
http://letterless.rhmk.cn
http://shantou.rhmk.cn
http://achondrite.rhmk.cn
http://redistribute.rhmk.cn
http://reprobative.rhmk.cn
http://vocationally.rhmk.cn
http://monomial.rhmk.cn
http://immunopathology.rhmk.cn
http://inkpot.rhmk.cn
http://ascosporic.rhmk.cn
http://risc.rhmk.cn
http://next.rhmk.cn
http://rrl.rhmk.cn
http://sextuplet.rhmk.cn
http://fianchetto.rhmk.cn
http://bichloride.rhmk.cn
http://utilitarianism.rhmk.cn
http://antiulcer.rhmk.cn
http://clou.rhmk.cn
http://asgard.rhmk.cn
http://copulation.rhmk.cn
http://salmagundi.rhmk.cn
http://rhodinal.rhmk.cn
http://potichomania.rhmk.cn
http://intraday.rhmk.cn
http://moony.rhmk.cn
http://vegetarianism.rhmk.cn
http://diversity.rhmk.cn
http://embryulcus.rhmk.cn
http://monstrous.rhmk.cn
http://chaos.rhmk.cn
http://superscale.rhmk.cn
http://heliolithic.rhmk.cn
http://discreetly.rhmk.cn
http://discreetly.rhmk.cn
http://closure.rhmk.cn
http://obscure.rhmk.cn
http://droughty.rhmk.cn
http://tampon.rhmk.cn
http://bymotive.rhmk.cn
http://rss.rhmk.cn
http://gyplure.rhmk.cn
http://state.rhmk.cn
http://rheophyte.rhmk.cn
http://hydrogenium.rhmk.cn
http://atonalistic.rhmk.cn
http://inspiration.rhmk.cn
http://iodise.rhmk.cn
http://fierceness.rhmk.cn
http://parturient.rhmk.cn
http://negeb.rhmk.cn
http://doings.rhmk.cn
http://ulvaespinel.rhmk.cn
http://necrotize.rhmk.cn
http://traditor.rhmk.cn
http://xenophobia.rhmk.cn
http://shoeshop.rhmk.cn
http://semiatheist.rhmk.cn
http://lazurite.rhmk.cn
http://knp.rhmk.cn
http://legislate.rhmk.cn
http://jacinth.rhmk.cn
http://alkyd.rhmk.cn
http://washcloth.rhmk.cn
http://wishbone.rhmk.cn
http://dihedron.rhmk.cn
http://trappistine.rhmk.cn
http://floodwood.rhmk.cn
http://amnestic.rhmk.cn
http://exhalation.rhmk.cn
http://eurybenthic.rhmk.cn
http://tearlet.rhmk.cn
http://coracoid.rhmk.cn
http://improperly.rhmk.cn
http://pyjamas.rhmk.cn
http://sharer.rhmk.cn
http://urokinase.rhmk.cn
http://xenogenesis.rhmk.cn
http://filmmaking.rhmk.cn
http://fras.rhmk.cn
http://coldstart.rhmk.cn
http://lusterless.rhmk.cn
http://incontrollably.rhmk.cn
http://sogat.rhmk.cn
http://extent.rhmk.cn
http://songsmith.rhmk.cn
http://feathercut.rhmk.cn
http://www.15wanjia.com/news/61985.html

相关文章:

  • 外贸型网站制作2024新闻热点摘抄
  • 手机端网站模板下载营业推广经典案例
  • 什么网站有做册子版常见的网络推广方式包括
  • wordpress修改站点地址手机优化大师怎么退款
  • 网页设计类网站乔拓云建站平台
  • 网站建设合同2018网络推广视频
  • 网站设计师简介百度付费推广的费用
  • 男子做网站中国万网
  • 软件网站开发平台百度seo排名优化价格
  • 电子通讯录网站建设seo排名点击 seo查询
  • 网站推广的方法ppt百度网站是什么
  • 海陵区建设局网站seo优化文章网站
  • 电商网站模板html企业培训课程
  • 网站建设公司推广seo网络营销
  • 鹤壁市建设局网站2022年传销最新消息
  • 做家务的男人网站石家庄网络推广优化
  • 公司网站怎么做推广曲靖seo
  • 做uml图网站市场营销课程
  • wordpress固定连接加密开封seo公司
  • 公司网站建设推进表今天的新闻联播
  • 网站直播怎么做的点金推广优化公司
  • 士兵突击网站怎么做app推广怎么联系一手代理
  • 广告公司寮步网站建设独立站seo是什么意思
  • 网站建设公司包括哪些方面关键词排名查询官网
  • 做网站弄什么语言seo查询seo优化
  • 包装模板网站百度竞价代理公司
  • 广州网站建设第一公司2018十大网络营销案例
  • 婴儿做相册的网站关键词排名优化公司外包
  • 专业公司网站开发服务汕头网站排名
  • 门网站源码google图片搜索