ibatis

Get the id of last inserted record in mybatis

感情迁移 提交于 2019-12-17 18:33:30
问题 I am newbie to mybatis. I am trying to get the id of last inserted record. My database is mysql and my mapper xml is <insert id="insertSelective" parameterType="com.mycom.myproject.db.mybatis.model.FileAttachment" > <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" > SELECT LAST_INSERT_ID() as id </selectKey> insert into fileAttachment <trim prefix="(" suffix=")" suffixOverrides="," > <if test="name != null" > name, </if> <if test="attachmentFileSize != null" > size, </if>

iBatis get executed sql

做~自己de王妃 提交于 2019-12-17 17:56:15
问题 Is there any way where I can get the executed query of iBatis? I want to reuse the query for an UNION query. For example: <sqlMap namespace="userSQLMap"> <select id="getUser" resultClass="UserPackage.User"> SELECT username, password FROM table WHERE id=#value# </select> </sqlMap> And when I execute the query through int id = 1 List<User> userList = queryDAO.executeForObjectList("userSQLMap.getUser",id) I want to get SELECT username, password FROM table WHERE id=1 Is there any way I could get

Ibatis/MyBatis select dynamically without need to create any Pojo / Mapper

坚强是说给别人听的谎言 提交于 2019-12-17 16:26:35
问题 Is there any way to select/update/delete dynamically using Ibatis/MyBatis? When I say "dynamically" it means I don't want to create any POJO/DataMapper at all. Any URL example would be welcomed. 回答1: Yes, just set the resultType attribute to map and the table data will be placed into a HashMap of column names to values. If the query returns more than 1 row, the mapped rows will be put into a List. If you want to select a single column, you can get just that value (as String, int, etc) or as a

The conversion to class java.time.LocalDateTime is unsupported.

会有一股神秘感。 提交于 2019-12-16 19:42:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> mssql-jdbc 对于java8的LocalDate,LocalTime,LocalDatetime的转换异常 先说下解决方法: 1. 降级Mybatis至3.5.0及以下; 2. 或升级mssql-jdbc驱动至7.1.0及以上 原文地址 : https://blog.csdn.net/qq_24505485/article/details/103540439 解决过程 之前实体类使用的是Timestamp 来存储时间,没有错,后来使用了LocalDatetime来存储也没错,再之后我把 Mybatis从3.5.0升级到了3.5.1之后 ,(mssql-jdbc的版本是com.microsoft.sqlserver:mssql-jdbc: 6.4.0.jre8 )LocalDatetime的转换就会抛异常: com.microsoft.sqlserver.jdbc.SQLServerException: The conversion to class java.time.LocalDateTime is unsupported. at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getObject(SQLServerResultSet.java:2249

阿里巴巴微服务架构演进

半世苍凉 提交于 2019-12-15 19:59:15
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 阿里巴巴服务化架构演进 单一应用架构 All In One 整个网站几个应用 前台 web + 后台 ops + tasks 业务 web + service/dao 各自开发 一起集成发布 技术战:Webx、Spring Ibatis、Jboss、Oracle 存在的问题:合并时经常代码冲突、发布相互制约效率低下、应用代码庞大臃肿维护困难。 垂直应用架构 按应用拆分 Service / DAO / Impl 都以二方库 jar 包的形式提供出去 代码拆分,独立部署,流程隔离,技术栈没有太大变化 应用相互之间直接依赖二方库 问题: 升级困难,要全网推动 数据库连接池压力大 分布式服务架构 API 与实现分离 使用 RPC 进行通信,服务端升级方便 各种服务中心出现,会员中心,商品中心,交易中心等 技术栈: Ali-tomcat Pandora Dubbo HSF 存在的问题: 依赖冲突 中间件升级困难 应用配置服务 应用开发效率低下 微服务架构 拥抱微服务,提升开发体验和效率 应用更轻量、开发更简单 配置 编码 开发 调试 部署 技术栈: Pandora Boot Spring Boot 容器隔离Pandora 为什么需要隔离? Pandora的容器架构如下: Pandora 结构与部署形式: 与应用 tgz

Circular reverences in iBatis

柔情痞子 提交于 2019-12-14 02:41:52
问题 I have two classes: class Apple { Worm worm; } class Worm { Apple apple; } They are stored in db in 1:1 fashion: table Apple(id, wormId) table Worm(id) Each apple has only one worm and vice versa. With out of iBatis I can do it simply: Worm worm = new Worm(); Apple apple = new Apple(); worm.setApple(apple); apple.setWorm(worm); How can I do it in ibatis? <resultMap id="Apple" type="Apple"> <result property="id" column="id"/> <result property="worm" column="id" select="getWormByApple"/> <

mybatis连接工厂java类实现

我的梦境 提交于 2019-12-14 00:20:06
写在前面 很久以前在有道云笔记上写的笔记,打算放弃它了,将笔记迁移到这里来。文章可能还有很多不足,请大家谅解,欢迎大佬提意见。 本文使用到的东西 mybatis java 1.正文 package com . etc . util ; import java . io . InputStream ; import java . sql . Connection ; 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 . apache . log4j . lf5 . util . Resource ; //实现获取、释放mybatis数据库连接的工具类 public class MyBatisSessionFactory { //定义常量 private static String CONFIG_FILE_LOCATION = "mybatis-config

Does iBATIS 2.3.x support foreach tag?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 16:23:19
问题 I have a personal website which uses iBATIS 2.3.x. Recently I'm adding a complex searching feature to the site, need to query the data by a list of object, likes: public Class PromotionAttribute { String attributeName; String attributeValue; } The query looks like: select p.* from promotions p join promotion_attributes pa on p.id=pa.id where <foreach item="PromotionAttribute" index="index" collection="list" open="(" separator=" or " close=")"> pa.attribute_name=#{attributeName} and pa

How to map a myBatis result to multiple objects?

好久不见. 提交于 2019-12-13 12:36:39
问题 Is it possible in myBatis 3 to map a single result to multiple objects, ensuring that the objects all reference the same instance? Is there an example of this I could reference? Updated to add more detail: For instance, let's say I store information regarding Contact s for my application in my DB. I want to know if it's possible to use myBatis to map the same instance of a contact to, say, a Listing class, which holds a Contact : public class Listing { private Contact myContact; //getters &

How perform Junit tests with Struts - Ibatis

南笙酒味 提交于 2019-12-13 06:32:02
问题 im using Struts 1.2.x and Ibatis 2.x version for development, so i finish yesterday and now i want to perform test this is my first time trying to work with JUnit, I already make test but in JavaApp not running on server, so how can I simulate or generate mocks with server behavior, and wich mocks are recommended for Struts and Ibatis built-in Environment? for example how can i set accerts for login screen? I know about StrutsTestCase im using it, and about Cactus are for containers and