Home > Back-end >  @ mapper for @ cannot be injected after the repository
@ mapper for @ cannot be injected after the repository

Time:10-02

Beginners in learning spring boot projects use mybatis was above the dao interface using the @ mapper annotations, no problem, then check it on the website @ mapper annotations are mybatis3.4 version later, so you should think of without @ mapper is to use the @ repository annotations, the following problems, to solve!


CodePudding user response:

Nobody answer about it -- --

CodePudding user response:

We are generally use @ Mapper now if use @ repository can achieve dao, then write their own implementation method! A few questions: are now commonly used @ RestController because Taiwan before and after separation, are now using a RestFul, default is have returned json data 2. @ RequestMapping is now @ GetMapping @ PostMapping

CodePudding user response:

Using the @ repository to write their own corresponding dao mapper configuration file

CodePudding user response:

reference LGX_TvT reply: 3/f
using the @ repository to write their own corresponding dao mapper configuration file
is configured in mybatis configuration files

CodePudding user response:

reference LGX_TvT reply: 3/f
using the @ repository to write their own corresponding dao mapper configuration file
I think is @ the repository is just springIOC agent problem how this interface can automatic injection and mybatis is not as long as the corresponding mapper. The XML change spacename into the interface of qualified name inside have to do is -- -

CodePudding user response:

Scripting languages don't understand, why?

CodePudding user response:

Can add @ MapperScan annotations on startup class interfaces are specified package
For example: @ MapperScan (basePackages={". Com. Tuyou. The user center. The repository. Standard "})

CodePudding user response:

Control layer directly into the dao??? Without the service?

CodePudding user response:

If you want to use @ repository in starting the class add @ MapperScan (" cn. QZZG. *. Mapper ") to the corresponding location specified

CodePudding user response:

Spring when scanning annotations, cancel the scan abstract classes and interfaces, so I can't find you use @ reponsitory annotations of the dao interface, if the idea of using the @ Mapper annotations, when the @autowired, idea will be prompted to find a bean, but does not affect the operation, but I watched and uncomfortable, baidu a heap of aversion methods, including setting instead of warning, later found that a operation, can put the two annotations used at the same time, in this way, the @ Mapper can let you find the bean, @ reponsitory can help you to treatment of obsessive-compulsive disorder,

CodePudding user response:

11 references, round the master replies:
Spring when scanning annotations, cancel the scan abstract classes and interfaces, so I can't find you use @ reponsitory annotations of the dao interface, if the idea of using the @ Mapper annotations, when the @autowired, idea will be prompted to find a bean, but does not affect the operation, but I watched and uncomfortable, baidu a heap of aversion methods, including setting instead of warning, later found that a operation, can put the two annotations used at the same time, in this way, the @ Mapper can let you find bean, @ reponsitory can help you to treatment of obsessive-compulsive disorder,
that's what I did

CodePudding user response:

@ is Mybatis Mapper annotation is used to indicate this is a Mapper, the corresponding xxxMapper. XML is to implement the Mapper, changed @ the repository, you are using a Spring Bean annotations, what do you think?

CodePudding user response:

@ Mapper is used to scan, of course, you can remove, start the class on springboot @ MapperScan (basePackages={} "com. XXX. XXX") to scan

CodePudding user response:

@ Mappler is mybatis annotations, mybatis runtime needs to mapper file can be found, then run the proxy class is constructed to completion, have nothing to do with the Spring, you should use the @ MapperScan mapper interfaces to scan, let mybatis can find these interfaces, then Spring @ ComponetScan will scan these interfaces, so that the Spring can manage these mybatis generated proxy class,
@ the annotation of the Repository is the Spring, and comments on the interface is useless and meaningless,

CodePudding user response:

Start the class with @ MapperScan words and what the bike, the dao on what comments don't have to

CodePudding user response:

@ repository annotations on the implementation class

CodePudding user response:

@ Repository needs to start the class add annotations @ MapperScan (com. XXX. "mapper") are used together
  • Related