- 浏览: 1117201 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1055)
- quartz定时任务 (1)
- json (9)
- 接口 (1)
- http (1)
- sccket (2)
- xmlbean (1)
- webservice (1)
- flex (1)
- sitemesh (2)
- json组装 (2)
- 存储过程 (6)
- ajax后台返回前台上下问 (3)
- flect反射机制 (1)
- 页面列表 (1)
- oracal结果集合并 (1)
- lucene (1)
- 读取配置文件工具 (1)
- 框架整合 (1)
- jms (3)
- 断点续传 (1)
- 页面之间的传值 (1)
- jpa (6)
- sql (8)
- jsp跳转 (1)
- jsp (6)
- jquery (2)
- ui (1)
- js与jsp之间的值的交互应用 (1)
- js空值判断 (1)
- Ajax (9)
- web-inf 编译目录 (1)
- 多线程 (9)
- 资料 (0)
- oracal (4)
- 多线程webservice (1)
- ztree (1)
- 加载与内容的变化 (1)
- 页面的公用变量 (1)
- web-inf目录结构 (1)
- 登陆系列 (1)
- jass应用于webservice认证 (2)
- 路径问题 (1)
- list合并 (1)
- list map中的value获取 (2)
- 标签tag (4)
- 方法 (1)
- 树形数据及其渲染 (1)
- require js 回调 (1)
- tab 页面切换 (2)
- 计时获取验证码 (1)
- 模式 (6)
- easyui (3)
- dialog (2)
- 乱码问题 (1)
- spring (29)
- sqlserver (1)
- iis,netframework (0)
- iis (1)
- netframework (1)
- 处理乱码问题 (1)
- struts-ajax (0)
- ,理论,了;,; (0)
- 排错方法 (1)
- hibernate (1)
- 二级缓存 (1)
- portal (1)
- date类型 (0)
- jvm out of memery StackOverflowError (1)
- echart数据填充 (0)
- echart (1)
- jmv (1)
- 学习 (0)
- java基础 (1)
- oracle性能优化 (1)
- 数据库三范式 (1)
- easy UI (1)
- oracle11g (1)
- form (3)
- servlet (2)
- spring mvc (1)
- htm5 (0)
- ibatise (1)
- 序列化 (1)
- tomcat双认证 (1)
- maven Lib (1)
- tomcat eclipse (2)
- ehcache (1)
- http 代替 ajax (2)
- rest (6)
- script脚本占位模板 (1)
- strust 标签 el表达式 (1)
- js bo (1)
- 公司资料 (0)
- js return (1)
- spring 第三方插件的工具类 (1)
- linux (10)
- linux 克隆 (1)
- linux xshell连接 (1)
- yum expect (1)
- linux 应用命令 (1)
- yum 缓存rmp包 (1)
- yum 本地库离线安装 (2)
- yum错误 (1)
- jsp页面用定时调用 (1)
- ajax setup (2)
- Exception,RuntimeException (1)
- 对话框 dialog (1)
- maven (17)
- PropertyPlaceholderConfigurer properties文件 (1)
- 错误集 (1)
- mybatise (0)
- 拦截器filter (1)
- http get post 区别 (1)
- rest 客户端两种返回的数据处理方式 (1)
- listener (2)
- maven工程 (1)
- ContainerResponseFilter (1)
- ajax action 打印任意实体类jsp (1)
- yum svn mvn (1)
- 分页 (1)
- angularjs (1)
- memcached (1)
- git (12)
- yyyyyyyy (0)
- oracal安装 (4)
- jaxwswebservice (1)
- spring bean (1)
- 排方法 (0)
- java 生成pdf (2)
- 创建目录 (1)
- 下载与生产pdf文件 (1)
- base64 (2)
- 配置文件 (2)
- blob (1)
- pdf (1)
- yum linux 安装Oracle (1)
- excl 插入数据库 (1)
- 搭建框架 (1)
- .classpath和jdk jre (1)
- mybatise 配置文件通配 (1)
- 用Maven插件生成Mybatis代码 (2)
- springmvc值的传递 (1)
- js jsp html (1)
- ajax跨域 (1)
- javamail (0)
- 提交复杂格式json数据 (1)
- get中文乱码/post (1)
- 弹出框,承载弹出链接----页面,显示大图 (1)
- @RequestBody list bean (1)
- 隐藏域 (1)
- 多页保存 (1)
- form 校验 (1)
- 注册,上传图片 (1)
- 登录验证 (1)
- 全局的异常处理 (0)
- 异常捕获,显示在页面 (0)
- mybatise事物配置 (1)
- maven compile (1)
- 时间格式 (1)
- js 跳转页面 (1)
- pringsecurity 角色授资源要重启服务 (0)
- Retrofi restfull (1)
- session过期推出,直接点击退出,退出 (0)
- 参数放于requestbody (1)
- maven本地仓库jar包 (1)
- 编译环境出错jdk1.6 1,7 (1)
- jsonarray ---json数组格式 (1)
- java后台文件上传,接受的2种方式 (0)
- 生成保存图片 (1)
- 权限mysql数据库Md5加密sql (1)
- mysql一对多关联查询 (1)
- mysql批量更新 (0)
- oracle in exists 区别 (1)
- https (1)
- linux发布脚本 (1)
- dubbo zookeepr (1)
- request.getParameter() (1)
- request.setAttribute() (1)
- @RequestMapping @ResponseBody (1)
- @RequestMapping @responsebody src控件 后台如何写入src值 (1)
- dwz (8)
- lib jar maven (1)
- web服务访问名称 (1)
- mvc返回内容设置,拦截 (1)
- @ResponseBody 返回json处理 (1)
- 视图,函数,存储过程 (1)
- <context:annotation-config/> (1)
- <context:component-scan/> (1)
- xml路劲通配 (2)
- 杂项 (1)
- dubbo (34)
- redis (25)
- mybatis (34)
- springmvc (15)
- js (7)
- sprinvmvc (1)
- 设计理念 (1)
- 工程 (1)
- 其他 (149)
- 导出,下载 (1)
- session (4)
- token (1)
- Exception处理 (2)
- 注解 (2)
- 框架 (3)
- shrio (1)
- login (1)
- 项目结构设计 (1)
- mybatis两种关联查询 (1)
- mybaits (2)
- 迭代模式 (1)
- oralce树形数据结构构建 (2)
- 树形结构的jsp展现 (1)
- filter intecept(Struts) (1)
- 树形结构数据的提交 (1)
- @RequestBody @RequestParam (1)
- div (1)
- equals重写 (1)
- 程序设计 (1)
- f多层for循环跳出 (1)
- 看源码 (0)
- 权限系统普遍通性 (1)
- 设计程序 (1)
- 动态拼接元素样式问题 (1)
- sql迭代 (1)
- debug断点 (1)
- spring mvc 扫描注解(ioc (1)
- di) (1)
- jdk (2)
- cglib (1)
- mybatis 多层括号(超过三层)解析不了 (1)
- tiles (2)
- cacheManager缓存的切换 (1)
- jsp,xml中el表达式等占位符中的数据操作 (1)
- jpa 及spring data jpa开发 (1)
- compareTo equals toString (1)
- 子页面用父页面js (1)
- jsp相对路径自加问题 (1)
- bean之间的相互拷贝 (1)
- DECODE (2)
- 泛型 (2)
- NVL (1)
- jsp jstl函数 用标签声明页面变量,供jstl使用,时间格式问题 (1)
- form表单切换action值 (1)
- response.getWriter().write()功能优于springMvc的返回 (1)
- 快速复制构建项目 (1)
- activeMq (15)
- cache (2)
- sql获取序列号 (1)
- 上传 (2)
- tfs (1)
- jsp标签 (2)
- qita (1)
- 触发器 (1)
- Exception (1)
- mybais (1)
- 标签 (1)
- connect by (1)
- for ... in (1)
- map转化为list (1)
- 树形结构list构建(树形实体) (1)
- 左侧菜单的设计 (1)
- response.getWriter().write() (1)
- eclipse打断点之后断无效 (1)
- 直接访问/web-inf/下的页面 (1)
- clob (1)
- freemark (1)
- 框架的设计 (1)
- get方式处理乱码 (1)
- Request的getParameter和getAttribute方法的区别 (1)
- cas (9)
- 时间格式问题 (1)
- ResponseUtil.writeToResponse (1)
- 树形数据的反选 (1)
- spring data jpa (1)
- jsp异常提示 (1)
- jquery js (1)
- eclipse (1)
- 乱码 (1)
- Json OBJETC (1)
- PROCEDURE (1)
- pl/sql oracle (1)
- 设计 (1)
- el表达式 (3)
- iframe (1)
- map (1)
- jsp中调用Java (1)
- response.getWriter().write() ajax (1)
- mybatis xml 传入参数 (0)
- response与request在返回时作用区别 (1)
- spring cache (1)
- 模型驱动 (1)
- 关于mybatis传空值的处理 (1)
- 日志配置 (1)
- mapper (1)
- mapper mybatis (1)
- mapper mybatis-spring spring-data-jpa (1)
- js插件 (1)
- spring-data-jpa (2)
- 字节流转化过程 (1)
- 数据库 (11)
- jsp页面 (1)
- 局域网络访问问题 (1)
- plsql (2)
- response (1)
- plsq (1)
- Proxool (1)
- cas security (1)
- 系统配置化 (1)
- 集群 (4)
- springboot (24)
- 设计模式 (5)
- 通知 (1)
- 架构 (48)
- zookeeper (5)
- mvc框架 (1)
- 事物隔离策略 (1)
- jvm (8)
- 调研 (1)
- Java工具类 (1)
- 并发容器 (3)
- 多线程管理器 (4)
- 简历 (0)
- 查询 (1)
- 集群工具 (1)
- springMcv (1)
- ConcurrentHashMap (1)
- hashtable (1)
- cac (1)
- 树形结构 (1)
- 定时任务 (1)
- tortoiseGit (2)
- struts (11)
- shiro (31)
- log4j (3)
- struts2 (2)
- 编码 (1)
- request (3)
- Nginx (14)
- tomcat (1)
- idea (12)
- mvc (2)
- BeanUtils (2)
- image (1)
- mino (1)
- httpClient (1)
- volecity (1)
- swagger (3)
- 调错 (0)
- data (1)
- log (1)
- shell (1)
- 事物 (3)
- junit (1)
- RestTemplate (2)
- 线程 (0)
- Exception异常处理 (1)
- Exception异常注解 (1)
- lock (1)
- HashMap (1)
- 面试 (0)
- rabbitMq (1)
- rainCat (1)
- 其它 (1)
- activemq消息传送机制以及ACK机制详解 (0)
- mysql (7)
- fildder (1)
- UML (1)
- 校验 (1)
- 反射 (1)
- 切面 (1)
- springioc (1)
- urule2 (0)
- skywalking (1)
- urule (2)
- docker (2)
- 前端 (1)
- bootstrap (1)
- eureka (2)
- springcloud (16)
- jenkins (2)
- springsecurity (1)
- 数据结构 (4)
- gradle (1)
- mycat (3)
- nacos (1)
- canary (1)
- 线程池 (1)
- solr (1)
- resteasy (2)
- BI (1)
- dfs (2)
- elasticsearch (1)
- ruby (1)
- logstash (1)
- clickhouse (2)
- davinci (15)
- java (1)
- davinvi (1)
- fastdfs (1)
- vue (1)
- 《将博客搬至CSDN》 (1)
最新评论
-
nizhipeng123:
private SessionFactory sessio ...
用map接收参数的几个注意的问题
/////mybatise
spring中集成
OperationLog.java实体
OperationLog.xml 配xml,sql与类没有明显的绑定关系,只是一般一个类一个,有体现的话在标签内
OperationLogLS.java*ls 找xml 方法为xml中标签
OperationLogRest operationLogLS.insertOne(operationLog);
====================================================
spring中集成mybatise
sqlConfiguration.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="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="true" />
<setting name="aggressiveLazyLoading" value="false" />
<setting name="multipleResultSetsEnabled" value="false" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="autoMappingBehavior" value="PARTIAL" />
<setting name="defaultExecutorType" value="SIMPLE" />
<setting name="defaultStatementTimeout" value="2000" />
</settings>
</configuration>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlConfiguration.xml" />//总配置文件
<property name="mapperLocations" value="classpath*:com/certusnet/nfv/**/mapper/*.xml" />//各个实体对应文件OperationLog.xml
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"
scope="prototype" autowire="constructor">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<bean id="baseService" class="com.certusnet.nfv.mano.BaseService"
scope="prototype" autowire="byName" abstract="true">
<property name="sqlSession" ref="sqlSession" />
</bean>
<bean id="operationLogLS" class="com.certusnet.nfv.mano.common.logic.OperationLogLS" scope="prototype"
autowire="byName" parent="baseService">
</bean>
========================================================
OperationLog.java
package com.certusnet.nfv.mano.common.model;
public class OperationLog
{
private long id = 0;
private String userId = null;
private String eventId = null;
private String subsystem = null;
private String operateType = null;
private String requestContent = null;
private String responseStatus = null;
private String responseContent = null;
private String createTime = null;
private String eventName;
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String getEventId()
{
return eventId;
}
public void setEventId(String eventId)
{
this.eventId = eventId;
}
public String getSubsystem()
{
return subsystem;
}
public void setSubsystem(String subsystem)
{
this.subsystem = subsystem;
}
public String getOperateType()
{
return operateType;
}
public void setOperateType(String operateType)
{
this.operateType = operateType;
}
public String getRequestContent()
{
return requestContent;
}
public void setRequestContent(String requestContent)
{
this.requestContent = requestContent;
}
public String getResponseStatus()
{
return responseStatus;
}
public void setResponseStatus(String responseStatus)
{
this.responseStatus = responseStatus;
}
public void setResponseStatus(ResponseStatus responseStatus)
{
this.responseStatus = responseStatus.getValue();
}
public String getResponseContent()
{
return responseContent;
}
public void setResponseContent(String responseContent)
{
this.responseContent = responseContent;
}
public void setResponseContent(String content, Throwable e)
{
StringBuffer sbContent = new StringBuffer(content);
sbContent.append("\r\n").append(e.getMessage());
for(StackTraceElement element : e.getStackTrace())
{
sbContent.append("\r\n").append(element.toString());
}
responseContent = new String(sbContent);
}
public String getCreateTime()
{
return createTime;
}
public void setCreateTime(String createTime)
{
this.createTime = createTime;
}
private String startTime = null;
private String endTime = null;
public String getStartTime()
{
return startTime;
}
public void setStartTime(String startTime)
{
this.startTime = startTime;
}
public String getEndTime()
{
return endTime;
}
public void setEndTime(String endTime)
{
this.endTime = endTime;
}
public enum ResponseStatus
{
SUCCESS("ok"), FAILURE("failed");
private String value = null;
private ResponseStatus(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}
}
==================================================
OperationLog.xml
namespace="com.certusnet.nfv.mano.common.mapper.OperationLog"这个是xml路径不是类
由于不是有明显改的对应关系,所以实体类更类似于bo,可以是组合型的bo
<?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.certusnet.nfv.mano.common.mapper.OperationLog">
<sql id="allColumns">
o.id,user_id as userId,ename.event_id as eventId,subsystem,operate_type as operateType,request_content as requestContent,
response_status as responseStatus,response_content as responseContent,create_time as createTime,ename.event_name as eventName
</sql>
<sql id="dynamicKeyConditions">
<where>
<trim suffixOverrides="and">
<if test="id > 0">id=#{id} and</if>
<if test="eventId != null">event_id=#{eventId} and</if>
<if test="startTime != null">create_time>=#{startTime} and</if>
<if test="endTime != null">create_time<=#{endTime} and</if>
</trim>
</where>
</sql>
<sql id="pageConditions">
<where>
<trim suffixOverrides="and">
<if test="userId != null">user_id=#{userId} and</if>
<if test="eventId != null">event_id=#{eventId} and</if>
<if test="subsystem != null">subsystem=#{subsystem} and</if>
<if test="operateType != null">operate_type=#{operateType} and</if>
<if test="startTime != null">create_time>=#{startTime} and</if>
<if test="endTime != null">create_time<=#{endTime} and</if>
</trim>
</where>
<if test="orderField != null">order by ${orderField}</if>
<if test="orderType == 1">desc</if>
<if test="startNum >= 0 and pageSize > 0">limit ${startNum}, ${pageSize}</if>
</sql>
<select id="selectOne" parameterType="com.certusnet.nfv.mano.common.model.OperationLog" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log <include refid="dynamicKeyConditions" />
</select>
<!-- <select id="selectList" parameterType="long" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log <include refid="dynamicKeyConditions" />
</select> -->
<select id="selectList" parameterType="long" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log o LEFT JOIN event_id_name ename on o.event_id=ename.event_id <include refid="dynamicKeyConditions" />
</select>
<select id="selectPage" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log o LEFT JOIN event_id_name ename on o.event_id=ename.event_id <include refid="pageConditions" />
</select>
<select id="countAll" resultType="int">
select count(id) from operation_log <include refid="pageConditions" />
</select>
<sql id="dynamicInsertColumns">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">id,</if>
<if test="userId != null">user_id,</if>
<if test="eventId != null">event_id,</if>
<if test="subsystem != null">subsystem,</if>
<if test="operateType != null">operate_type,</if>
<if test="requestContent != null">request_content,</if>
<if test="responseStatus != null">response_status,</if>
<if test="responseContent != null">response_content,</if>
<if test="createTime != null">create_time</if>
</trim>
</sql>
<sql id="dynamicInsertColumnsEvent">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">id,</if>
<if test="eventId != null">event_id,</if>
<if test="eventName != null">event_name</if>
</trim>
</sql>
<sql id="dynamicInsertValues">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">#{id},</if>
<if test="userId != null">#{userId},</if>
<if test="eventId != null">#{eventId},</if>
<if test="subsystem != null">#{subsystem},</if>
<if test="operateType != null">#{operateType},</if>
<if test="requestContent != null">#{requestContent},</if>
<if test="responseStatus != null">#{responseStatus},</if>
<if test="responseContent != null">#{responseContent},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</sql>
<sql id="dynamicInsertValuesEvent">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">#{id},</if>
<if test="eventId != null">#{eventId},</if>
<if test="eventName != null">#{eventName},</if>
</trim>
</sql>
<insert id="insertOne" parameterType="com.certusnet.nfv.mano.common.model.OperationLog">
insert into operation_log <include refid="dynamicInsertColumns" /> values <include refid="dynamicInsertValues" />
<selectKey resultType="long" order="AFTER" keyProperty="id">
<if test="id <= 0">select last_insert_id() as id</if>
<if test="id > 0">select #{id} as id</if>
</selectKey>
</insert>
<insert id="insertEvent" parameterType="com.certusnet.nfv.mano.common.model.EventNameId">
insert into event_id_name <include refid="dynamicInsertColumnsEvent" /> values <include refid="dynamicInsertValuesEvent" />
<selectKey resultType="long" order="AFTER" keyProperty="id">
<if test="id <= 0">select last_insert_id() as id</if>
<if test="id > 0">select #{id} as id</if>
</selectKey>
</insert>
</mapper>
==================================================================
OperationLogLS.java
package com.certusnet.nfv.mano.common.logic;
import java.util.List;
import com.certusnet.nfv.mano.BaseService;
import com.certusnet.nfv.mano.Constants;
import com.certusnet.nfv.mano.common.logicapi.IOperationLogLS;
import com.certusnet.nfv.mano.common.model.EventNameId;
import com.certusnet.nfv.mano.common.model.OperationLog;
import com.certusnet.nfv.mano.common.pojo.OperLogQuery;
public class OperationLogLS extends BaseService implements IOperationLogLS
{
//配置文件路径
private static final String path = Constants.MAPPER_COMMON + OperationLog.class.getSimpleName();
//getSqlSession().selectList sqlsession这些方法的选择根据操作类型和返回类型path + ".selectOne(对应xml中的路径)"
public OperationLog selectOne(OperationLog parameter) throws Exception
{
if((parameter == null) || (parameter.getId() <= 0))
{
throw new NullPointerException("Indexed fields are all null");
}
return getSqlSession().selectOne(path + ".selectOne", parameter);
}
public List<OperationLog> selectMore(OperationLog parameter) throws Exception
{
return getSqlSession().selectList(path + ".selectList", parameter);
}
public int insertOne(OperationLog parameter) throws Exception
{
if(parameter == null)
{
throw new NullPointerException("Empty parameter");
}
if(parameter.getCreateTime() == null)
{
parameter.setCreateTime(Constants.formatTimeStamp());
}
return getSqlSession().insert(path + ".insertOne", parameter);
}
public List<OperationLog> selectPage(OperLogQuery operlogQuery) throws Exception
{
return getSqlSession().selectList(path + ".selectPage", operlogQuery);
}
public int countAll(OperLogQuery operlogQuery) throws Exception
{
return getSqlSession().selectOne(path + ".countAll", operlogQuery);
}
@Override
public int insertEventOne(EventNameId parameter) throws Exception {
if(parameter == null)
{
throw new NullPointerException("Empty parameter");
}
return getSqlSession().insert(path + ".insertEvent", parameter);
}
}
package com.certusnet.nfv.mano;
import org.apache.ibatis.session.SqlSession;
/**
* 数据库操作基类
*/
public abstract class BaseService(供注入sqlsession)
{
private SqlSession sqlSession;
public SqlSession getSqlSession()
{
return sqlSession;
}
public void setSqlSession(SqlSession sqlSession)
{
this.sqlSession = sqlSession;
}
}
package com.certusnet.nfv.mano.common.logicapi;
import java.util.List;
import com.certusnet.nfv.mano.common.model.EventNameId;
import com.certusnet.nfv.mano.common.model.OperationLog;
import com.certusnet.nfv.mano.common.pojo.OperLogQuery;
public interface IOperationLogLS(供面向接口编程,外界调用)
{
public OperationLog selectOne(OperationLog parameter) throws Exception;
public List<OperationLog> selectMore(OperationLog parameter) throws Exception;
public int insertOne(OperationLog parameter) throws Exception;
public List<OperationLog> selectPage(OperLogQuery operlogQuery) throws Exception;
public int countAll(OperLogQuery operlogQuery) throws Exception;
public int insertEventOne(EventNameId parameter) throws Exception;
}
//////////接口中应用:
operationLogLS.insertOne(operationLog);
//应用
@Component
@Path("/")//接着web.xml中设置的rest的第二层路径
public class OperationLogRest
{
private static Logger LOG = Logger.getLogger(OperationLogRest.class);
@Autowired(required=true)
private IOperationLogLS operationLogLS;
@POST
@Path("logs/generation")
@Produces(ContentType.APPLICATION_JSON_UTF_8)
@Consumes(ContentType.APPLICATION_JSON_UTF_8)
public long saveOperationLog(@Context HttpServletRequest request) throws ManoException
{
try
{
OperationLog operationLog = new OperationLog();
operationLog.setEventId(request.getParameter("Event-Id"));
operationLog.setOperateType(request.getParameter("Operate-Type"));
operationLog.setRequestContent(request.getParameter("Request-Content"));
operationLog.setSubsystem(request.getParameter("Subsystem"));
operationLog.setUserId(request.getParameter("User-Id"));
operationLog.setResponseContent(request.getParameter("Response-Content"));
operationLog.setResponseStatus(request.getParameter("Response-Status"));
operationLogLS.insertOne(operationLog);
return operationLog.getId();
}
catch (Exception ex)
{
LOG.error(ex.getMessage(), ex);
throw new ManoException(ex);
}
}
}
spring中集成
OperationLog.java实体
OperationLog.xml 配xml,sql与类没有明显的绑定关系,只是一般一个类一个,有体现的话在标签内
OperationLogLS.java*ls 找xml 方法为xml中标签
OperationLogRest operationLogLS.insertOne(operationLog);
====================================================
spring中集成mybatise
sqlConfiguration.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="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="true" />
<setting name="aggressiveLazyLoading" value="false" />
<setting name="multipleResultSetsEnabled" value="false" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="autoMappingBehavior" value="PARTIAL" />
<setting name="defaultExecutorType" value="SIMPLE" />
<setting name="defaultStatementTimeout" value="2000" />
</settings>
</configuration>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlConfiguration.xml" />//总配置文件
<property name="mapperLocations" value="classpath*:com/certusnet/nfv/**/mapper/*.xml" />//各个实体对应文件OperationLog.xml
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"
scope="prototype" autowire="constructor">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<bean id="baseService" class="com.certusnet.nfv.mano.BaseService"
scope="prototype" autowire="byName" abstract="true">
<property name="sqlSession" ref="sqlSession" />
</bean>
<bean id="operationLogLS" class="com.certusnet.nfv.mano.common.logic.OperationLogLS" scope="prototype"
autowire="byName" parent="baseService">
</bean>
========================================================
OperationLog.java
package com.certusnet.nfv.mano.common.model;
public class OperationLog
{
private long id = 0;
private String userId = null;
private String eventId = null;
private String subsystem = null;
private String operateType = null;
private String requestContent = null;
private String responseStatus = null;
private String responseContent = null;
private String createTime = null;
private String eventName;
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String getEventId()
{
return eventId;
}
public void setEventId(String eventId)
{
this.eventId = eventId;
}
public String getSubsystem()
{
return subsystem;
}
public void setSubsystem(String subsystem)
{
this.subsystem = subsystem;
}
public String getOperateType()
{
return operateType;
}
public void setOperateType(String operateType)
{
this.operateType = operateType;
}
public String getRequestContent()
{
return requestContent;
}
public void setRequestContent(String requestContent)
{
this.requestContent = requestContent;
}
public String getResponseStatus()
{
return responseStatus;
}
public void setResponseStatus(String responseStatus)
{
this.responseStatus = responseStatus;
}
public void setResponseStatus(ResponseStatus responseStatus)
{
this.responseStatus = responseStatus.getValue();
}
public String getResponseContent()
{
return responseContent;
}
public void setResponseContent(String responseContent)
{
this.responseContent = responseContent;
}
public void setResponseContent(String content, Throwable e)
{
StringBuffer sbContent = new StringBuffer(content);
sbContent.append("\r\n").append(e.getMessage());
for(StackTraceElement element : e.getStackTrace())
{
sbContent.append("\r\n").append(element.toString());
}
responseContent = new String(sbContent);
}
public String getCreateTime()
{
return createTime;
}
public void setCreateTime(String createTime)
{
this.createTime = createTime;
}
private String startTime = null;
private String endTime = null;
public String getStartTime()
{
return startTime;
}
public void setStartTime(String startTime)
{
this.startTime = startTime;
}
public String getEndTime()
{
return endTime;
}
public void setEndTime(String endTime)
{
this.endTime = endTime;
}
public enum ResponseStatus
{
SUCCESS("ok"), FAILURE("failed");
private String value = null;
private ResponseStatus(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}
}
==================================================
OperationLog.xml
namespace="com.certusnet.nfv.mano.common.mapper.OperationLog"这个是xml路径不是类
由于不是有明显改的对应关系,所以实体类更类似于bo,可以是组合型的bo
<?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.certusnet.nfv.mano.common.mapper.OperationLog">
<sql id="allColumns">
o.id,user_id as userId,ename.event_id as eventId,subsystem,operate_type as operateType,request_content as requestContent,
response_status as responseStatus,response_content as responseContent,create_time as createTime,ename.event_name as eventName
</sql>
<sql id="dynamicKeyConditions">
<where>
<trim suffixOverrides="and">
<if test="id > 0">id=#{id} and</if>
<if test="eventId != null">event_id=#{eventId} and</if>
<if test="startTime != null">create_time>=#{startTime} and</if>
<if test="endTime != null">create_time<=#{endTime} and</if>
</trim>
</where>
</sql>
<sql id="pageConditions">
<where>
<trim suffixOverrides="and">
<if test="userId != null">user_id=#{userId} and</if>
<if test="eventId != null">event_id=#{eventId} and</if>
<if test="subsystem != null">subsystem=#{subsystem} and</if>
<if test="operateType != null">operate_type=#{operateType} and</if>
<if test="startTime != null">create_time>=#{startTime} and</if>
<if test="endTime != null">create_time<=#{endTime} and</if>
</trim>
</where>
<if test="orderField != null">order by ${orderField}</if>
<if test="orderType == 1">desc</if>
<if test="startNum >= 0 and pageSize > 0">limit ${startNum}, ${pageSize}</if>
</sql>
<select id="selectOne" parameterType="com.certusnet.nfv.mano.common.model.OperationLog" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log <include refid="dynamicKeyConditions" />
</select>
<!-- <select id="selectList" parameterType="long" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log <include refid="dynamicKeyConditions" />
</select> -->
<select id="selectList" parameterType="long" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log o LEFT JOIN event_id_name ename on o.event_id=ename.event_id <include refid="dynamicKeyConditions" />
</select>
<select id="selectPage" resultType="com.certusnet.nfv.mano.common.model.OperationLog">
select <include refid="allColumns" /> from operation_log o LEFT JOIN event_id_name ename on o.event_id=ename.event_id <include refid="pageConditions" />
</select>
<select id="countAll" resultType="int">
select count(id) from operation_log <include refid="pageConditions" />
</select>
<sql id="dynamicInsertColumns">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">id,</if>
<if test="userId != null">user_id,</if>
<if test="eventId != null">event_id,</if>
<if test="subsystem != null">subsystem,</if>
<if test="operateType != null">operate_type,</if>
<if test="requestContent != null">request_content,</if>
<if test="responseStatus != null">response_status,</if>
<if test="responseContent != null">response_content,</if>
<if test="createTime != null">create_time</if>
</trim>
</sql>
<sql id="dynamicInsertColumnsEvent">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">id,</if>
<if test="eventId != null">event_id,</if>
<if test="eventName != null">event_name</if>
</trim>
</sql>
<sql id="dynamicInsertValues">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">#{id},</if>
<if test="userId != null">#{userId},</if>
<if test="eventId != null">#{eventId},</if>
<if test="subsystem != null">#{subsystem},</if>
<if test="operateType != null">#{operateType},</if>
<if test="requestContent != null">#{requestContent},</if>
<if test="responseStatus != null">#{responseStatus},</if>
<if test="responseContent != null">#{responseContent},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</sql>
<sql id="dynamicInsertValuesEvent">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id > 0">#{id},</if>
<if test="eventId != null">#{eventId},</if>
<if test="eventName != null">#{eventName},</if>
</trim>
</sql>
<insert id="insertOne" parameterType="com.certusnet.nfv.mano.common.model.OperationLog">
insert into operation_log <include refid="dynamicInsertColumns" /> values <include refid="dynamicInsertValues" />
<selectKey resultType="long" order="AFTER" keyProperty="id">
<if test="id <= 0">select last_insert_id() as id</if>
<if test="id > 0">select #{id} as id</if>
</selectKey>
</insert>
<insert id="insertEvent" parameterType="com.certusnet.nfv.mano.common.model.EventNameId">
insert into event_id_name <include refid="dynamicInsertColumnsEvent" /> values <include refid="dynamicInsertValuesEvent" />
<selectKey resultType="long" order="AFTER" keyProperty="id">
<if test="id <= 0">select last_insert_id() as id</if>
<if test="id > 0">select #{id} as id</if>
</selectKey>
</insert>
</mapper>
==================================================================
OperationLogLS.java
package com.certusnet.nfv.mano.common.logic;
import java.util.List;
import com.certusnet.nfv.mano.BaseService;
import com.certusnet.nfv.mano.Constants;
import com.certusnet.nfv.mano.common.logicapi.IOperationLogLS;
import com.certusnet.nfv.mano.common.model.EventNameId;
import com.certusnet.nfv.mano.common.model.OperationLog;
import com.certusnet.nfv.mano.common.pojo.OperLogQuery;
public class OperationLogLS extends BaseService implements IOperationLogLS
{
//配置文件路径
private static final String path = Constants.MAPPER_COMMON + OperationLog.class.getSimpleName();
//getSqlSession().selectList sqlsession这些方法的选择根据操作类型和返回类型path + ".selectOne(对应xml中的路径)"
public OperationLog selectOne(OperationLog parameter) throws Exception
{
if((parameter == null) || (parameter.getId() <= 0))
{
throw new NullPointerException("Indexed fields are all null");
}
return getSqlSession().selectOne(path + ".selectOne", parameter);
}
public List<OperationLog> selectMore(OperationLog parameter) throws Exception
{
return getSqlSession().selectList(path + ".selectList", parameter);
}
public int insertOne(OperationLog parameter) throws Exception
{
if(parameter == null)
{
throw new NullPointerException("Empty parameter");
}
if(parameter.getCreateTime() == null)
{
parameter.setCreateTime(Constants.formatTimeStamp());
}
return getSqlSession().insert(path + ".insertOne", parameter);
}
public List<OperationLog> selectPage(OperLogQuery operlogQuery) throws Exception
{
return getSqlSession().selectList(path + ".selectPage", operlogQuery);
}
public int countAll(OperLogQuery operlogQuery) throws Exception
{
return getSqlSession().selectOne(path + ".countAll", operlogQuery);
}
@Override
public int insertEventOne(EventNameId parameter) throws Exception {
if(parameter == null)
{
throw new NullPointerException("Empty parameter");
}
return getSqlSession().insert(path + ".insertEvent", parameter);
}
}
package com.certusnet.nfv.mano;
import org.apache.ibatis.session.SqlSession;
/**
* 数据库操作基类
*/
public abstract class BaseService(供注入sqlsession)
{
private SqlSession sqlSession;
public SqlSession getSqlSession()
{
return sqlSession;
}
public void setSqlSession(SqlSession sqlSession)
{
this.sqlSession = sqlSession;
}
}
package com.certusnet.nfv.mano.common.logicapi;
import java.util.List;
import com.certusnet.nfv.mano.common.model.EventNameId;
import com.certusnet.nfv.mano.common.model.OperationLog;
import com.certusnet.nfv.mano.common.pojo.OperLogQuery;
public interface IOperationLogLS(供面向接口编程,外界调用)
{
public OperationLog selectOne(OperationLog parameter) throws Exception;
public List<OperationLog> selectMore(OperationLog parameter) throws Exception;
public int insertOne(OperationLog parameter) throws Exception;
public List<OperationLog> selectPage(OperLogQuery operlogQuery) throws Exception;
public int countAll(OperLogQuery operlogQuery) throws Exception;
public int insertEventOne(EventNameId parameter) throws Exception;
}
//////////接口中应用:
operationLogLS.insertOne(operationLog);
//应用
@Component
@Path("/")//接着web.xml中设置的rest的第二层路径
public class OperationLogRest
{
private static Logger LOG = Logger.getLogger(OperationLogRest.class);
@Autowired(required=true)
private IOperationLogLS operationLogLS;
@POST
@Path("logs/generation")
@Produces(ContentType.APPLICATION_JSON_UTF_8)
@Consumes(ContentType.APPLICATION_JSON_UTF_8)
public long saveOperationLog(@Context HttpServletRequest request) throws ManoException
{
try
{
OperationLog operationLog = new OperationLog();
operationLog.setEventId(request.getParameter("Event-Id"));
operationLog.setOperateType(request.getParameter("Operate-Type"));
operationLog.setRequestContent(request.getParameter("Request-Content"));
operationLog.setSubsystem(request.getParameter("Subsystem"));
operationLog.setUserId(request.getParameter("User-Id"));
operationLog.setResponseContent(request.getParameter("Response-Content"));
operationLog.setResponseStatus(request.getParameter("Response-Status"));
operationLogLS.insertOne(operationLog);
return operationLog.getId();
}
catch (Exception ex)
{
LOG.error(ex.getMessage(), ex);
throw new ManoException(ex);
}
}
}
发表评论
-
mybatis中进行三目判断,不同sql结果累加union(尤其对于多种等效权限,资源的准备)
2019-10-21 13:49 1787mybatis中进行三目判断,不同sql结果累加uni ... -
mybatis-generator
2019-10-16 20:42 339mybatis代码生成 1,pom配置插件,2,配置生成文件 ... -
Mybatis中#{}与${}区别
2019-06-20 11:30 499动态 sql 是 mybatis 的主要特性之一,在 ma ... -
mybatis 通用 mapper 使用时抛出TypeVariableImpl ClassCastException
2018-10-18 16:56 1140Caused by: java.lang.RuntimeE ... -
mybatis反向工程的基本思路
2018-10-11 14:36 588mybatis反向工程的基本思路: 加载反向注入配 ... -
mybatis中使用if标签比较两个字符串是否相等
2018-06-29 16:57 1965<!-- 此处使用if比较是否相等 --> ... -
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found
2018-06-28 10:54 1781错误提示: org.apache.ibatis.bind ... -
批量更新两种方法实践
2018-06-27 18:17 1097mybatis执行批量更新up ... -
mybatis批量插入
2018-06-26 18:22 579mybatis批量插入 注意类型就是list ... -
spring集成mybatis实现mysql读写分离
2018-03-30 16:51 804前言 在网站的用户达到一定规模后,数据库因为 ... -
Java MyBatis 插入数据库返回主键
2017-12-28 18:43 2073Java MyBatis 插入数据库返回主键 ... -
mybatis 时间区间比较
2017-12-15 16:13 15072mybatis 时间区间比较 jdbcType=T ... -
Mybatis 示例之 SelectKey ,mysql数据库设置自增也需连用生产主键
2017-12-13 17:22 2263SelectKey在Mybatis中是为了解决Insert ... -
mybatis-generetor生成插件
2017-11-16 17:05 915mybatis-generetor生成插件 ... -
mybatis 的mapper文件解析规律
2017-06-19 11:15 790mybatis 的mapper文件解析规律,只会解析出一层 ... -
与不同框架整合时mybatis的使用区别 (对比activeMQ,见其他类似标题两篇)
2017-02-14 17:06 903与不同框架整合时mybatis的使用区别 (对比active ... -
与不同框架整合时mybatis的使用区别 (对比redis)
2017-02-14 15:57 933与不同框架整合时mybatis的使用区别 (对比redis) ... -
与不同框架整合时mybatis的使用区别
2017-02-13 15:26 1278与不同框架整合时mybatis的使用区别1,mapper,2 ... -
mybatis的管理映射
2016-12-27 13:22 808mybatis的管理映射: 主查询有结果才会促发子查询 ... -
mybatis 模糊查询与函数连用%需不需要拼接问题
2016-12-26 11:37 1139mybatis 模糊查询与函数连用%需不需要拼接问题 1, ...
相关推荐
在 Java Web 开发中,Spring 框架被广泛使用,它提供了全面的企业级应用开发解决方案,包括事务管理、数据访问、依赖注入等。整合 MyBatis 与 Spring,可以构建出更加灵活且易于维护的项目结构。 MyBatis-Spring 是...
SpringMVC和MyBatis是两个非常流行的Java开发框架,它们在企业级Web应用中有着广泛的应用。SpringMVC作为Spring框架的一部分,主要用于处理HTTP请求和响应,而MyBatis则是一个优秀的持久层框架,专注于数据库操作。...
MyBatis和Spring框架是Java开发中非常重要的两个组件,它们在企业级应用开发中扮演着核心角色。MyBatis是一个优秀的持久层框架,它解决了Java中的数据访问问题,而Spring则是一个全面的企业级应用框架,提供了依赖...
【Spring+MyBatis简单架构】是Web开发中一种常见的技术组合,主要应用于构建轻量级的企业级应用。Spring作为一款全面的Java企业级应用框架,提供了依赖注入、AOP(面向切面编程)、事务管理等多种功能,而MyBatis则...
【标题】"springMVC+mybatise+maven的eclipse框架" 描述了一个基于Java的Web开发架构,这是在Eclipse集成开发环境下构建的一种高效、模块化且可维护的项目结构。在这个框架中,Spring MVC负责处理HTTP请求并协调应用...
综上所述,"struts2+spring+mybatise实现PhoneBook电话簿信息管理系统"是一个涵盖了前端交互、后端服务和数据存储的完整项目,展示了Java EE开发中的典型技术和实践。这个项目不仅锻炼了开发者对三大框架的理解和...
"Spring Cloud+mybatise + mysql 自动化代码生成工具"是这样一种解决方案,它能够帮助开发者按照预设规则自动生成常见的Controller、Service以及mapping配置文件等基础类,从而显著提升开发效率。 首先,我们来详细...
1. 基于 SQL 语句编程,相当灵活,不会对应用程序或者数据库的现有设计造成任何影响,SQL 写在 XML 里,解除 sql 与程序代码的耦合,便于统一管理。 2. 与 JDBC 相比,减少了 50%以上的代码量,消除了 JDBC 大量冗余...
首先,Spring Boot是基于Spring框架的高度模块化、简化配置的开发工具,它简化了初始化、配置和运行Spring应用的过程。在Spring Boot中,我们可以通过声明式配置或者Java配置来管理数据源。 MyBatis是一个轻量级的...
Struts2、Spring和MyBatis是Java Web开发中常用的三大框架,它们组合起来可以构建高效、可维护的Web应用程序。在这个"电话簿信息管理网站"项目中,开发者利用这三者的优势,实现了对电话簿数据的存储、查询、更新和...
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。在本项目中,我们将深入探讨如何使用 ...在实际开发中,你可以根据自己的需求调整 SQL 语句,添加更复杂的业务逻辑,以满足各种应用场景。
在实际应用中,MBG不仅可以生成基本的CRUD操作,还可以根据配置生成复杂的查询方法,比如分页查询、多条件组合查询等。通过合理配置,MBG可以适应各种项目需求,使得代码更加规范,开发流程更加高效。 总结起来,...
这个实例将帮助你理解如何构建一个完整的Java Web应用程序,从依赖管理到业务逻辑处理。 **Maven** 是一个项目管理和构建工具,它的核心功能是管理项目的依赖关系。在本实例中,你需要配置Maven环境以运行项目。这...
SpringMVC、Activiti 和 MySQL 是企业级应用开发中常用的技术栈,它们分别在不同的领域发挥着关键作用。本文将详细介绍这些技术以及如何将它们整合到一个项目中。 首先,让我们了解一下这三个技术的基础: 1. **...
在【压缩包子文件的文件名称列表】中,只有一个文件名为"myBatise001",这可能是项目的主要源代码包或者是一个重要的模块。在这个包中,我们可以预期找到以下内容: 1. **Mapper接口**:这些接口定义了数据库操作的...
其核心特性包括自动配置、内嵌Web服务器(如Tomcat)以及“起步依赖”等,使得开发者能够快速地创建一个独立运行的、生产级别的Java应用。 二、MyBatis介绍与集成 MyBatis是一个优秀的持久层框架,它支持定制化SQL...
MyBatis 3.2.3 是一个流行的Java持久层框架,它简化了数据库操作,提供了灵活的映射机制,使得开发人员能够更方便地处理SQL、存储过程...通过理解并熟练运用这些知识点,开发人员可以构建出高性能、易维护的Java应用。
这将涉及几个关键步骤,确保你的应用程序能够正确地读取和操作Oracle数据库中的数据。 首先,我们需要在Spring Boot项目中添加MyBatis和Oracle数据库驱动的依赖。在你的`pom.xml`文件中,你需要引入以下两个依赖: ...