Springboot+mybatis批量更新报错不明白这个哪里错了

本人也是学习springboot不久,其良好的约定简化了配置,让我爱不释手,相比于jfinal,springboot感觉更好一点,当然这是本人意见,不喜勿喷。我在学习中也遇到了各种问题,也查找了各种资料,在这里就给大家说一下,希望大牛口下留情。
首先新建一个maven项目,我采用的是eclipse,安装了springsource-tool-suite,如果你电脑没安装也不影响,只需要建立相应的目录就行,如果想安装可以参考这篇文章
新建好项目 目录结构如下
当然我的已经是完整的了,你的目录参照这个,然后我们一步一步的填充
(1)新建实体类,代码如下
package com.qbd.
import java.io.S
public class User implements Serializable{
private static final long serialVersionUID = 1L;
private int
private int
public int getUpower() {
public void setUpower(int upower) {
this.upower =
public int getUid() {
public void setUid(int uid) {
this.uid =
public String getUname() {
public void setUname(String uname) {
this.uname =
public String getUpassword() {
public void setUpassword(String upassword) {
this.upassword =
(2)新建UserMapper.xml注意:它放在src/main/resources/mapper下代码如下
&?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"&
namespace="com.qbd.dao.UserDao"&
id="find" parameterType="Map" resultMap="StudentResult"&
select * from user
test="uname!=null and uname!='' "&
and uname like #{uname}
test="start!=null and size!=null"&
limit #{start},#{size}
id="findbyid" parameterType="Integer" resultMap="StudentResult"&
select * from user where uid=#{uid}
id="getTotal" parameterType="Map" resultType="Long"&
select count(*) from user
test="uname!=null and uname!='' "&
and uname like #{uname}
id="getUser" resultMap="StudentResult" parameterType="com.qbd.model.User"&
select *from user where uname=#{uname} and upassword=#{upassword}
id="delete" parameterType="Integer"&
delete from user where uid=#{uid}
id="update" parameterType="com.qbd.model.User"&
update user
test="uname!=null"&
uname=#{uname},
test="upassword!=null"&
upassword=#{upassword},
test="upower!=null"&
upower=#{upower},
where uid=#{uid}
id="add" parameterType="com.qbd.model.User"&
insert into user values(null,#{uname},#{upassword},#{upower})
type="com.qbd.model.User" id="StudentResult"&
property="uid" column="uid"/&
property="uname" column="uname"/&
property="upassword" column="upassword"/&
(3)新建UserDao代码如下
package com.qbd.
import java.util.L
import java.util.M
import com.qbd.model.U
public interface UserDao {
public List&User& getAll();
public User getUser(User user);
public int delete(int id);
public int update(User user);
public int add(User user);
public List&User& find(Map&String,Object& map);
public List&User& findbyid(Integer uid);
public Long getTotal(Map&String,Object& map);
(4)然后分别新建service和serviceimpl,代码如下
package com.qbd.
import java.util.L
import java.util.M
import com.qbd.model.U
public interface UserService {
public List&User& getAll();
public User getUser(User user);
public int delete(int id);
public int update(User user);
public int add(User user);
public List&User& find(Map&String,Object& map);
public Long getTotal(Map&String,Object& map);
package com.qbd.
import java.util.L
import java.util.M
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.S
import com.qbd.dao.UserD
import com.qbd.model.U
import com.qbd.service.UserS
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userD
public List&User& getAll() {
return userDao.getAll();
public User getUser(User user) {
return userDao.getUser(user);
public int delete(int id) {
return userDao.delete(id);
public int update(User user) {
return userDao.update(user);
public int add(User user) {
return userDao.add(user);
public List&User& find(Map&String, Object& map) {
return userDao.find(map);
public Long getTotal(Map&String, Object& map) {
return userDao.getTotal(map);
(5)新建controller
package com.qbd.
import java.util.HashM
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.A
import org.springframework.stereotype.C
import org.springframework.web.bind.annotation.ModelA
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RequestP
import org.springframework.web.bind.annotation.RestC
import com.qbd.model.U
import com.qbd.service.UserS
import com.qbd.utils.PageB
import com.qbd.utils.StringU
@Controller
public class UserController {
private UserService userS
public UserService getUserService() {
return userS
@Autowired
public void setUserService(UserService userService) {
this.userService = userS
@RequestMapping("/userlist")
public Map&String, Object& getAll(String page, String rows, @ModelAttribute User user) throws Exception {
PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
Map&String, Object& map = new HashMap&String, Object&();
map.put("uname", StringUtil.formatLike(user.getUname()));
map.put("start", pageBean.getStart());
map.put("size", pageBean.getPageSize());
List&User& userList = userService.find(map);
Long total = userService.getTotal(map);
map.clear();
map.put("total", total);
map.put("users", userList);
return map;
@RequestMapping("/list")
public Map&String, Object& List() throws Exception {
Map&String, Object& map = new HashMap&String, Object&();
map.put("uname", null);
map.put("start", null);
map.put("size", null);
List&User& userList = userService.find(map);
Long total = userService.getTotal(map);
map.clear();
map.put("total", total);
map.put("users", userList);
return map;
@RequestMapping("/usersave")
public Map&String, Object& save(@ModelAttribute User user) throws Exception {
Map&String, Object& map = new HashMap&String, Object&();
int resultTotal = 0;
if (user.getUid() == 0) {
resultTotal = userService.add(user);
resultTotal = userService.update(user);
if (resultTotal & 0) {
map.put("success", "保存成功");
map.put("success", "保存失败");
return map;
@RequestMapping("/userdelete")
public Map&String, Object& delete(@RequestParam(value = "deluids") String ids) throws Exception {
String[] idsStr = ids.split(",");
for (int i = 0; i & idsStr. i++) {
userService.delete(Integer.parseInt(idsStr[i]));
Map&String, Object& map = new HashMap&String, Object&();
map.put("success", "删除成功");
@RequestMapping("/index")
public String index() {
return "index";
(6)完成这些,证明你的基本编码已经完成,然而并没有配置,那么如何采用简单的springboot的配置那,首先在src/main/resources新建
application.properties内容如下
# 项目contextPath,一般在正式发布版本中,我们不配置
#server.context-path=/springbootmybatis
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
server.error.path=/error
# 服务端口
server.port=8888
# session最大超时时间(分钟),默认为30
server.session.timeout=60
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
# server.address=192.168.16.11
# tomcat最大线程数,默认为200
server.tomcat.max-threads=800
# tomcat的URI编码
server.tomcat.uri-encoding=UTF-8
# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
server.tomcat.basedir=D:/log/springboot-tomcat-tmp
#数据库配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ssm
spring.datasource.username=root
spring.datasource.password=root
# mybatis_config
mybatis.mapper-locations=classpath:mapper
(7)然后编写启动类来加载这些东西
package com.
import org.mybatis.spring.annotation.MapperS
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
import org.springframework.boot.builder.SpringApplicationB
import org.springframework.boot.web.support.SpringBootServletI
@SpringBootApplication
@MapperScan(basePackages = "com.qbd.dao")
public class SpringbootMybatisApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisApplication.class, args);
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootMybatisApplication.class);
然后运行,访问就可以得到结果。如果想要源代码可以点这个链接
springboot+mybatis 搭建环境
Springboot
mybatis 环境搭建
springBoot 就是讲一些基础的框架集合起来,提供默认的配置,减少人为的配置。不用
springBoot 而用
spring 也是...
springBoot+Mybatis整合小案例《一》
最近,突然对springBoot感兴趣,看了网上的各种大牛的教程,写出了几个完整的小Demo,因为自己也是初学者,所以将自己其中的一个小案例的配置过程来写一下,希望对和我一样的初学者能提供一点参考(不...
Spring Boot + MyBatis 快速入门
这几天学习了下Spring Boot,想记录下来以备以后复习查看用。Spring Boot极度简化了以往XML配置的复杂繁琐,只需简单的几行配置就可以搭建一个Web工程,大大节省了开发时间。环境准备
Springboot+mybatis搭建(以尽可能简单的,外加注释的方式)
感悟:写这篇文章的目的是网上很多相关的创建资料,但是我愣是没看懂,为什么呢,因为有很多没有注释的,对一知半解的我根本不懂,所以,我去了springboot的官网,看了一宿,终于搞到了半知半解。之后,我...
springboot+mybatis+SpringSecurity 实现用户角色数据库管理(一)
本文使用springboot+mybatis+SpringSecurity 实现用户权限数据库管理实现用户和角色用数据库存储,而资源(url)和权限的对应采用硬编码配置。 也就是角色可以访问的权限通过...
没有更多推荐了,spring boot+spring MVC+Mybatis项目中只有一个@Repository错误_spring吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:14,757贴子:
spring boot+spring MVC+Mybatis项目中只有一个@Repository错误收藏
主要报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentController': Injection of resource nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stuFunctionImpl': Injection of resource nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.DAO.interfaces.StuFunctionDAO' available: expected single matching bean but found 2: stuFunctionDAOImpl,stuFunctionDAO下面是相应service层代码:package com.service.import java.util.ArrayLimport java.util.HashMimport java.util.Limport java.util.Mimport javax.annotation.Rimport org.json.JSONOimport org.springframework.beans.factory.annotation.Aimport org.springframework.beans.factory.annotation.Qimport org.springframework.stereotype.Simport com.DAO.interfaces.StuFunctionDAO;import com.DAO.interfaces.TeaFunctionDAO;import com.model.Aimport com.model.Pimport com.model.InfoCimport com.service.interfaces.StuF@Servicepublic class StuFunctionImpl implements StuFunction {@Resourceprivate StuFunctionDAO stuDAO;@Resourceprivate TeaFunctionDAO teaDAO;-------------------------功能代码}dao层接口:import java.util.Limport java.util.Mimport org.springframework.stereotype.Rimport com.model.Apublic interface StuFunctionDAO{----------------------------------------------功能代码}dao实现类:import java.util.Limport java.util.Mimport javax.annotation.Rimport org.springframework.stereotype.Rimport com.DAO.interfaces.StuFunctionDAO;import com.model.A@Repositorypublic class StuFunctionDAOImpl implements StuFunctionDAO {@Resourceprivate StuFunctionDAO stuDAO;}我去掉dao实现类的@Repository注解后就能运行,但是也使用不了dao中的方法了。我在项目中也有其他的dao接口和实现类,都正常没有报错,唯独这个报错,请大神帮忙解决!!!
大哥,你解决了没有,我也遇到了
为啥要写dao实现类啊
登录百度帐号springboot加mybatis配置出现这个错 mapper是没有问题的 有哪个大佬知道_百度贴吧
springboot加mybatis配置出现这个错 mapp
springboot加mybatis配置出现这个错 mapper是没有问题的 有哪个大佬知道
spring boot
集成mybaties
没有你写的这么复杂吧
贴吧热议榜
使用签名档&&
保存至快速回贴我没有币了只能写在这里了,望路过的大神帮忙解决一下。。。
我的问题就是springboot整合mybatis的时候,在dao层进行测试的时候(在service直接注入dao也是这个错),报异常,异常下面图片有详细的,我就不描述了,dao接口加了@Repository这个注解,按理说应该是已经注入了的,只是不知道启动的时候为什么会报错,求大神路过解决一下~~~~~~~~~
下面贴出我的相关代码图片:项目模块架构:
Application代码:
Dao代码(Mapper):
test测试代码:
测试异常:(这个可能看不清,麻烦 右击图片--在新标签页中打开图片)
test、application、dao文件存放的位置:
解决SpringBoot中的dao实例无法自动注入(@autowire)问题
由于对springboot不熟悉,我在一个小bug上边卡了很久。
mapper接口一定要加注解@Mapper!!! 加@Component没用!!!否则spring无法识别mapper对应的bean,...
SpringBoot集成Mybatis时无法扫描Mapper问题
使用mybatis官方提供的starter与SpringBoot做整合
org.mybatis.spring.boot
mybatis-spring-b...
SpringBoot整合Mybatis无法注入dao
在springBoot启动类或在Mybatis类上添加注解@MapperScan,标识扫描dao接口所在的包...
springboot整合mybatis mapper注入时显示could not autowire的解决
springboot整合mybatis mapper注入时显示could not autowire的错误,不影响使用,但是看着不爽,如下图:
解决方法,在mapper加一个注解。如下图所示:
Springboot mapper注入失败
今天写毕设的时候,发现一个问题,就是dao层的接口bean注入失败,经查询发现:SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!“Applicat...
关于SpringBoot bean无法注入的问题(与文件包位置有关)
问题场景描述整个项目通过Maven构建,大致结构如下:
核心Spring框架一个module spring-boot-base
service和dao一个module server-core
提供系统...
springMVC mybatis dao接口(mapper接口)注入失败
报的错误是:
No qualifying bean of
type [com.*.*.*.*.*.dao.UserDao] found
dependency: expected a...
springboot dao层注解失败
springboot dao层注解失败springboot 项目编译报错
报错信息如下Field ulevelDao in demo.service.impl.UlevelServiceImpl r...
springBoot 注解失败
application中无法扫描其他包下的文件导致注解失败
给class添加@MapperScan(&com.guoan.demo.mapper&)强制扫描制定包
应注意application启动...
SpringBoot+Mybatis整合报,service注入失败,dao注入失败,
问题:com.sun.org.apache.xerces.internal.impl.XMLEntityScanner$1
会导致,报,service注入失败,dao注入失败,
学习spri...
没有更多推荐了,Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:247)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:184)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:42)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
这是因为spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。解决方案:在application.properties里配置:spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
公司刚开发一个ssm架构的项目,同事推荐了mybatis的一个插件,发现上手容易,高效简洁。下面是官方的文档: 传送门请进我的demo目录:注意SpringBoot的启动类的位置
1.首先添加po...
Spring boot 官网并没有提供集成Mybatis示例,CSND上还是有很多相关技术文章,都可借鉴,下面是自己集成,可做参考。
1.pom.xml添加mybatis和数据连接池相关依赖,个人...
当业务的访问量(数据库的查询)非常大时,为了降低数据库的压力,希望有多个数据库进行负载均衡,避免所有的查询都集中在一台数据库,造成数据库压力过大。mysql支持一主多从,即在写库的数据库发生变动时,会...
1、Maven构建Spring Boot创建Maven Web工程,引入spring-boot-starter-parent依赖
原文地址 http://blog.csdn.net/sinat_/article/details/
spring-boot 注解配置mybatis+druid(新...
没有更多推荐了,}

我要回帖

更多关于 boot报错 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信