mybtis 逆向
mbg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration> <!--
targetRuntime= MyBatis3Simple:生成简单版的CRUD
MyBatis3:豪华版
-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator> <!-- jdbcConnection:指定如何连接到目标数据库 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis?allowMultiQueries=true"
userId="root"
password="000000">
</jdbcConnection> <!-- -->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <!-- javaModelGenerator:指定javaBean的生成策略
targetPackage="test.model":目标包名
targetProject="\MBGTestProject\src":目标工程
-->
<javaModelGenerator targetPackage="com.pojo"
targetProject=".\src">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <!-- sqlMapGenerator:sql映射生成策略: -->
<sqlMapGenerator targetPackage="com.mapper"
targetProject=".\src">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator> <!-- javaClientGenerator:指定mapper接口所在的位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.mapper"
targetProject=".\src">
<property name="enableSubPackages" value="false" />
</javaClientGenerator> <!-- 指定要逆向分析哪些表:根据表要创建javaBean -->
<table schema="" tableName="employee"></table>
</context>
</generatorConfiguration>
测试代码:
@Test
public void testMbg() throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("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);
}
生成包结构:

配置mybatis-conf.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>
<properties resource="dbconfig.properties"></properties>
<!-- <settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="jdbcTypeForNull" value="NULL"/> 显式的指定每个我们需要更改的配置的值,即使他是默认的。防止版本更新带来的问题
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
</settings> -->
<!-- <typeAliases>
<package name="com.pojo"/>
</typeAliases> -->
<environments default="_mysql">
<environment id="_mysql">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
</environments>
<mappers>
<!-- 扫描mapper包 -->
<package name="com.mapper"/>
</mappers>
</configuration>
测试类:
package test; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import com.mapper.EmployeeMapper;
import com.pojo.Employee;
import com.pojo.EmployeeExample;
import com.pojo.EmployeeExample.Criteria; public class MyBatisTest { public SqlSessionFactory getSqlSessionFactory() throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
return new SqlSessionFactoryBuilder().build(inputStream);
} @Test
public void testMbg() throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("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);
} @Test
public void testInsert() throws IOException{
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession openSession = sqlSessionFactory.openSession();
try{
EmployeeMapper employeeMapper = openSession.getMapper(EmployeeMapper.class);
Employee employee = new Employee(5,"EEE","EEE");
int i = employeeMapper.insert(employee);
System.out.println(i);
openSession.commit();
}finally{
openSession.close();
}
}
@Test
public void testSelect() throws IOException{ SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
EmployeeExample employeeExample = new EmployeeExample();
Criteria criteria = employeeExample.createCriteria();
criteria.andIdEqualTo(1);
List<Employee> employees = employeeMapper.selectByExample(employeeExample);
for (Employee employee : employees) {
System.out.println(employee.toString());
}
} finally {
sqlSession.close();
} }
@Test
public void testUpdata() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
EmployeeExample employeeExample = new EmployeeExample();
// 1.
Employee employee = employeeMapper.selectByPrimaryKey(1);
employee.setGender("acd");
employeeMapper.updateByPrimaryKey(employee);
// 2.
//如果传入字段不空为才更新,在批量更新中使用此方法,不需要先查询再更新
//itemsMapper.updateByPrimaryKeySelective(record);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
@Test
public void testDelete() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
EmployeeExample employeeExample = new EmployeeExample(); employeeMapper.deleteByPrimaryKey(5);
sqlSession.commit();
} finally {
sqlSession.close();
}
}
}
mybtis 逆向的更多相关文章
- 【腾讯Bugly干货分享】移动App入侵与逆向破解技术-iOS篇
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/577e0acc896e9ebb6865f321 如果您有耐心看完这篇文章,您将懂 ...
- [.NET逆向] 破解NET的四大神器
原本这篇文章可以更早一星期写出来与大家分享,由于某方面的原因耽搁到现在,心里竟有那么一点好像对不住大家的感觉.这当然与神器有关,因为我发现利用这四大神器我似乎觉得几乎所有的NET程序破解都不在话下了 ...
- iOS-Block总结 && 全面解析逆向传值
1.block的特点: block是C语言: block是一种数据类型.可以当做参数,也可以用做返回值:--总之,对比int的用法用即可(当然,定义的时候,最好跟函数对比): ...
- Reverse Core 第一部分 代码逆向技术基础
@date: 2016/10/14 <逆向工程核心原理>笔记 记录书中较重要的知识,方便回顾 ps. 因有一些逆向基础,所以我本来就比较熟悉的知识并未详细记录 第一章 关于逆向工程 目标, ...
- 【DWR系列02】-DWR逆向Ajax即服务器推送
.literal { background-color: #f2f2f2; border: 1px solid #cccccc; padding: 1px 3px 0; white-space: no ...
- php正则逆向引用与子模式分析
先看一个例子: <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1 ...
- 【逆向篇】分析一段简单的ShellCode——从TEB到函数地址获取
其实分在逆向篇不太合适,因为并没有逆向什么程序. 在http://www.exploit-db.com/exploits/28996/上看到这么一段最简单的ShellCode,其中的技术也是比较常见的 ...
- 浅谈Android应用保护(一):Android应用逆向的基本方法
对于未进行保护的Android应用,有很多方法和思路对其进行逆向分析和攻击.使用一些基本的方法,就可以打破对应用安全非常重要的机密性和完整性,实现获取其内部代码.数据,修改其代码逻辑和机制等操作.这篇 ...
- iOS程序逆向Mac下常用工具——Reveal、HopperDisassemble、IDA
原文在此 一.Reveal 1 一般使用 Reveal是ITTY BITTY发布的UI分析工具,可以很直观的查看App的UI布局.如下图所示: Reveal是需要付费的,需要89美元, ...
随机推荐
- extjs中Store和grid的刷新问题
问题1:Store.load() 和Store.setproxy()区别 问题2:修改后的Grid 更新: Store.reload() 问题3,store删除后刷新会出问题 Store移除一行:St ...
- 原生javascript实现call、apply和bind的方法
var context = {id: 12}; function fun (name, age) { console.log(this.id, name, age) } bind bind() 方法会 ...
- webpack4前端工程化教程(一)
-本文作为webpack小白入门文章,会详细地介绍webpack的用途.具体的安装步骤.注意事项.一些基本的配置项,并且会以一个具体的项目实例来介绍如何使用webpack.另外,本文会简单地介绍一些最 ...
- NOIP专题复习1 图论-最短路
一.知识概述 今天我们要复习的内容是图论中的最短路算法,我们在这里讲3种最短路求法,分别是:floyd,dijkstra,spfa. 那么我们从几道例题来切入今天讲解的算法. 二.典型例题 1.热浪 ...
- [Thu Summer Camp2016]补退选
题目描述不说了. 题解: Trie+vector…… Trie存学生,vector存答案. 极为无脑但无脑到让人怀疑 代码: #include<cmath> #include<vec ...
- PHP 获取LDAP服务器Schema数据
最近工作中一直在与LDAP打交道,在官方推荐的client-apis里,可以很容易找到每个语言对应的API,进而与LDAP服务器交互.但是在用ApacheDirectoryStudio时,这个软件竟然 ...
- RNNCell使用
目录 Recap input dim, hidden dim SimpleRNNCell Single layer RNN Cell Multi-Layers RNN RNN Layer Recap ...
- selenium--driver.switchTo()-----转
https://www.cnblogs.com/clairejing/p/9499223.html 在自动化测试中,会遇到多窗口.多iframe.多alert的情况.此时,会使用driver.swit ...
- C语言学习6
int i; 定义整形变量i int *p; p为指向整型数据的指针变量 int a[n]: 定义整形数组a,他有n个元素 int *p[n]: 定义指针数组p,它有n个指向整型数据的指针元素组 ...
- 杭电 2803 The MAX(sort)
Description Giving N integers, V1, V2,,,,Vn, you should find the biggest value of F. Input Each tes ...