English 中文(简体)
Mybatis 3.0.5 插入/更新说明,同时提供多种投入
原标题:Mybatis 3.0.5 insert/update statement mapping with multiple inputs

也许我没有明显的东西,但我无法得到一个简单的地图,以成功执行。

Using the following interface

public interface CustomItemMapper 
{
    Integer insert(CustomItem item, @Param("extra") String someparam);
}

以及以下XML绘图

  <insert id="insert" useGeneratedKeys="false" parameterType="map" keyProperty="id">
    insert into CustomItem (id, column2, column3, column4, column5, column6)
        values (#{id}, #{field2}, #{field3}, #{field4}, #{field5}, #{extra})
  </insert>

and this code

SqlSessionFactory sqlSessionFactory = (SqlSessionFactory) servletContext.getAttribute("SqlSessionFactory");
SqlSession session = sqlSessionFactory.openSession();
try 
{ 
    CustomItemMapper mapper = session.getMapper(CustomItemMapper.class); 
    mapper.update(item);
    session.commit();
} 
finally 
{ 
    session.close(); 
} 

I get the following debug output:

Checked out connection 368716606 from pool.
ooo Connection Opened
==>  Executing: insert into CustomItem (id, column2, column3, column4, column5, column6) values (?, ?, ?, ?, ?, ?) 
==> Parameters: null, null, null, null, null, actual_value_of_extra(String)
xxx Connection Closed
Returned connection 368716606 to pool.

之后是例外(不能进入id栏)。

因此,适当传递的唯一价值是额外供应的扼杀。 我已经核实,实地名称正确无误,此时此刻,物体不作废,这些田地都适当居住。

I also tried using parameterType="CustomItem" instead of parameterType="map" but the result did not change.

I would appreciate if someone could let me know what I am missing here.

Thanks in advance.

PS:我也把发言插入同一个问题。

最佳回答

你们需要把其他参数的名称列入你的地图仪。 I m 假设习俗是 Java豆,获得实地方法1等。 如前所述,改变你的参数类型,使之不成图。

http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBoQFjA&url=http://mybatis.googlecode.com/svn/trunk/doc/en/MyBatis-3-User-Guide.pdf&rct=j&q=mybatis%2020user%20guide&=1MOp7KayEsgPO=ZIpjpg。

You can pass multiple parameters to a mapper method. If you do, they will be named by their position in the parameter list by default, for example: #{1}, #{2} etc. If you wish to change the name of the parameters (multiple only), then you can use the @Param(“paramName”) annotation on the parameter.

因此,改变你的地图,

public interface CustomItemMapper 
{
    Integer insert(@Param("item")CustomItem item, @Param("extra") String someparam);
}

页: 1

 <insert id="insert" useGeneratedKeys="false" parameterType="map" keyProperty="id">
    insert into CustomItem (id, column2, column3, column4, column5, column6)
        values (#{id}, #{item.field1}, #{item.field2}, #{item.field3}, #{item.field4}, #{extra})
  </insert>
问题回答

如果您将<代码>CustomItem的示例输入update(,则将 类型当然应当是完全合格的类别名称,而不是>map>——只有在你通过<代码>javautil时,方可使用。 页: 1





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...