Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
MyBatis mapper interface extends other interfaces ,but it can't work
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
470863193@qq.com  
View profile  
 More options May 14 2012, 2:10 am
From: "470863...@qq.com" <470863...@qq.com>
Date: Sun, 13 May 2012 23:10:23 -0700 (PDT)
Local: Mon, May 14 2012 2:10 am
Subject: MyBatis mapper interface extends other interfaces ,but it can't work
Hi team!!

I have a java project use MyBatis and springMVC,may mappers have the
same methods,I want put them in a generic interfaces,so that other
mappers will extend that interface

this is my code:

Base.java:
public abstract Class Base{
  ....

}

User.java
public class User extends Base implements Serializable{
  ....

}

BaseMapper.java:
public interface BaseMapper<T extends Base> {
        public void save(T t) throws Exception;
}

BaseMapper.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.stamp.base.persistence.BaseMapper">
</mapper>

UserMapper.java:
public interface UserMapper extends BaseMapper<User>{

}

UserMapper.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.stamp.user.persistence.UserMapper">
   <insert id="save" parameterType="com.stamp.user.entity.User">
     INSERT INTO tsc_user(login_name ,password) VALUES
(#{loginName},#{password})
   </insert>
</mapper>

this is scan mappers in spring xml:
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.stamp.*.persistence" /


    </bean>
I am sure spring xml is correct

In service I declar BaseMapper<User> baseMapper  and use annotation
@Autowire injection it
when I test my project
exception is throwed :
Could not autowire field: private
com.stamp.base.persistence.BaseMapper
com.stamp.base.service.impl.BaseServiceImpl.baseMapper; nested
exception is java.lang.NullPointerException

what's with it ? I find in this link
http://groups.google.com/group/mybatis-user/browse_thread/thread/c16f...
it seems it OK!

regards.

sence.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick R  
View profile  
 More options May 14 2012, 11:04 pm
From: Rick R <ric...@gmail.com>
Date: Mon, 14 May 2012 23:04:00 -0400
Subject: Re: MyBatis mapper interface extends other interfaces ,but it can't work

Are you sure the issue is related to you using the generic interface
implementation?

I also need to annotate my Mappers with @Repository to have them picked up
as a candidate for auto-wiring.

--
Rick R

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
AntPort  
View profile  
 More options May 15 2012, 3:48 am
From: AntPort <antonioporto...@gmail.com>
Date: Tue, 15 May 2012 00:48:58 -0700 (PDT)
Local: Tues, May 15 2012 3:48 am
Subject: Re: MyBatis mapper interface extends other interfaces ,but it can't work

Can you post your service implementation (and test class)?

Dana ponedjeljak, 14. svibnja 2012. 08:10:23 UTC+2, korisnik 4708...@qq.com
napisao je:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »