数据源依赖

druid官方文档:https://github.com/alibaba/druid/wiki/常见问题

                <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.19</version>
</dependency>

mybatis相关依赖及插件配置

<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--通用mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.5</version>
</dependency>
<!--pagehelper 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> <!-- 要打包了这个生成代码要禁止掉,本地开发开启-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<dependencies>
<!--
配置这个依赖主要是为了等下在配置mybatis-generator.xml的时候可以不用配置 classPathEntry 这样的一个属性,
避免代码的耦合度太高-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!-- 自动生成的配置 -->
<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>

对应的application.properties配置:

## 数据库访问配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf-8
spring.datasource.username = root
spring.datasource.password = root # 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
# 配置获取连接等待超时的时间
spring.datasource.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.timeBetweenEvictionRunsMillis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.filters=stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
#spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
#spring.datasource.useGlobalDataSourceStat=true #指定 domain bean所在包
mybatis.type-aliases-package=com.dudu.domain
#指定 mapper 映射文件
mybatis.mapperLocations=classpath:mapper/*.xml #mapper
#mappers 多个接口时逗号隔开
mapper.mappers=com.dudu.util.MyMapper
mapper.not-empty=false
mapper.identity=MYSQL #pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

bean 配置

@Configuration
public class DruidConfig {
private Logger logger = LoggerFactory.getLogger(DruidConfig.class); @Value("${spring.datasource.url:#{null}}")
private String dbUrl;
@Value("${spring.datasource.username: #{null}}")
private String username;
@Value("${spring.datasource.password:#{null}}")
private String password;
@Value("${spring.datasource.driverClassName:#{null}}")
private String driverClassName;
@Value("${spring.datasource.initialSize:#{null}}")
private Integer initialSize;
@Value("${spring.datasource.minIdle:#{null}}")
private Integer minIdle;
@Value("${spring.datasource.maxActive:#{null}}")
private Integer maxActive;
@Value("${spring.datasource.maxWait:#{null}}")
private Integer maxWait;
@Value("${spring.datasource.timeBetweenEvictionRunsMillis:#{null}}")
private Integer timeBetweenEvictionRunsMillis;
@Value("${spring.datasource.minEvictableIdleTimeMillis:#{null}}")
private Integer minEvictableIdleTimeMillis;
@Value("${spring.datasource.validationQuery:#{null}}")
private String validationQuery;
@Value("${spring.datasource.testWhileIdle:#{null}}")
private Boolean testWhileIdle;
@Value("${spring.datasource.testOnBorrow:#{null}}")
private Boolean testOnBorrow;
@Value("${spring.datasource.testOnReturn:#{null}}")
private Boolean testOnReturn;
@Value("${spring.datasource.poolPreparedStatements:#{null}}")
private Boolean poolPreparedStatements;
@Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize:#{null}}")
private Integer maxPoolPreparedStatementPerConnectionSize;
@Value("${spring.datasource.filters:#{null}}")
private String filters;
@Value("{spring.datasource.connectionProperties:#{null}}")
private String connectionProperties; /**
* Druid 连接池配置
*
* @return
*/
@Bean
@Primary
public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource(); datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
//configuration
if (initialSize != null) {
datasource.setInitialSize(initialSize);
}
if (minIdle != null) {
datasource.setMinIdle(minIdle);
}
if (maxActive != null) {
datasource.setMaxActive(maxActive);
}
if (maxWait != null) {
datasource.setMaxWait(maxWait);
}
if (timeBetweenEvictionRunsMillis != null) {
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
if (minEvictableIdleTimeMillis != null) {
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
if (validationQuery != null) {
datasource.setValidationQuery(validationQuery);
}
if (testWhileIdle != null) {
datasource.setTestWhileIdle(testWhileIdle);
}
if (testOnBorrow != null) {
datasource.setTestOnBorrow(testOnBorrow);
}
if (testOnReturn != null) {
datasource.setTestOnReturn(testOnReturn);
}
if (poolPreparedStatements != null) {
datasource.setPoolPreparedStatements(poolPreparedStatements);
}
if (maxPoolPreparedStatementPerConnectionSize != null) {
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
} if (connectionProperties != null) {
datasource.setConnectionProperties(connectionProperties);
} List<Filter> filters = new ArrayList<>();
filters.add(statFilter());
filters.add(wallFilter());
datasource.setProxyFilters(filters); return datasource;
} /**
* 注册 servlet
*
* @return
*/
@Bean
public ServletRegistrationBean druidServlet() {
ServletRegistrationBean servletRegistrationBean =
new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); //控制台管理用户,加入下面2行 进入druid后台就需要登录
servletRegistrationBean.addInitParameter("loginUsername", "admin");
servletRegistrationBean.addInitParameter("loginPassword", "admin");
return servletRegistrationBean;
} /**
* 注册 filter
*
* @return
*/
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions",
"*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
filterRegistrationBean.addInitParameter("profileEnable", "true");
return filterRegistrationBean;
} @Bean
public StatFilter statFilter() {
StatFilter statFilter = new StatFilter();
//slowSqlMillis用来配置SQL慢的标准,执行时间超过slowSqlMillis的就是慢。
statFilter.setLogSlowSql(true);
//SQL合并配置
statFilter.setMergeSql(true);
//slowSqlMillis的缺省值为3000,也就是3秒。
statFilter.setSlowSqlMillis(1000);
return statFilter;
} @Bean
public WallFilter wallFilter() {
WallFilter wallFilter = new WallFilter();
//允许执行多条SQL
WallConfig config = new WallConfig();
config.setMultiStatementAllow(true);
wallFilter.setConfig(config);
return wallFilter;
}
}

通用Mapper配置 主要配置

通用Mapper插件网址:https://github.com/abel533/Mapper

可以放在 utils包中

public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> {
//FIXME 特别注意,该接口不能被扫描到,否则会出错
}

这里实现一个自己的接口,继承通用的mapper,关键点就是这个接口不能被扫描到,不能跟dao这个存放mapper文件放在一起。

最后在启动类中通过MapperScan注解指定扫描的mapper路径:

@SpringBootApplication
@EnableTransactionManagement // 启注解事务管理,等同于xml配置方式的 <tx:annotation-driven />
@MapperScan(basePackages = "com.dudu.dao", markerInterface = MyMapper.class)
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

MyBatis Generator配置

mybatis-generator.xml文件,该配置文件用来自动生成表对应的Model,Mapper以及xml,该文件位于src/main/resources下面

Mybatis Geneator 详解: http://blog.csdn.net/isea533/article/details/42102297

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration> <!--加载配置文件,为下面读取数据库信息准备-->
<properties resource="application.properties"/> <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<!-- 自定义通用 mapper 接口-->
<property name="mappers" value="com.dudu.util.MyMapper"/>
<!-- caseSensitive 默认false,当数据库表名区分大小写时,可以将该属性设置为true-->
<property name="caseSensitive" value="true"/>
</plugin> <!-- 阻止生成自动注释 -->
<commentGenerator>
<property name="javaFileEncoding" value="UTF-8"/>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator> <!--数据库链接地址账号密码-->
<jdbcConnection driverClass="${spring.datasource.driver-class-name}"
connectionURL="${spring.datasource.url}"
userId="${spring.datasource.username}"
password="${spring.datasource.password}">
</jdbcConnection> <javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!--生成Model类存放位置-->
<javaModelGenerator targetPackage="com.dudu.domain" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator> <!--生成Dao类存放位置-->
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.dudu.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!--生成对应表及类名 去掉Mybatis Generator生成的一堆 example
-->
<table tableName="LEARN_RESOURCE" domainObjectName="LearnResource" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true"/>
</table>
</context>
</generatorConfiguration>

其中tk.mybatis.mapper.generator.MapperPlugin很重要,用来指定通用Mapper对应的文件,这样我们生成的mapper都会继承这个通用Mapper

  • 可以直接通过命令:mvn mybatis-generator:generate
  • 通用maven 插件形式

生成代码如下:

domain

@Table(name = "learn_resource")
public class LearnResource {
/**
* ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; /**
* 作者
*/
private String author; /**
* 描述
*/
private String title; /**
* 地址链接
*/
private String url; /**
* 获取ID
*
* @return id - ID
*/
public Long getId() {
return id;
} /**
* 设置ID
*
* @param id ID
*/
public void setId(Long id) {
this.id = id;
} /**
* 获取作者
*
* @return author - 作者
*/
public String getAuthor() {
return author;
} /**
* 设置作者
*
* @param author 作者
*/
public void setAuthor(String author) {
this.author = author == null ? null : author.trim();
} /**
* 获取描述
*
* @return title - 描述
*/
public String getTitle() {
return title;
} /**
* 设置描述
*
* @param title 描述
*/
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
} /**
* 获取地址链接
*
* @return url - 地址链接
*/
public String getUrl() {
return url;
} /**
* 设置地址链接
*
* @param url 地址链接
*/
public void setUrl(String url) {
this.url = url == null ? null : url.trim();
}
}

dao mapper


public interface LearnResourceMapper extends MyMapper<LearnResource> { /**
* 自定义新增接口
*
* @param map
* @return
*/
List<LearnResource> queryLearnResouceList(Map<String, Object> map);
}

mapper 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.dudu.dao.LearnResourceMapper"> <resultMap id="BaseResultMap" type="com.dudu.domain.LearnResource">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="author" jdbcType="VARCHAR" property="author"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="url" jdbcType="VARCHAR" property="url"/>
</resultMap> <!--自定义新增接口-->
<select id="queryLearnResouceList" resultType="com.dudu.domain.LearnResource">
SELECT * from learn_resource where 1=1
<if test="author != null and author!= ''">
and author like CONCAT('%',#{author},'%')
</if>
<if test="title != null and title!= ''">
and title like CONCAT('%',#{title},'%')
</if>
order by id desc
</select>
</mapper>

定义service 层

通用 service 定义:

具体可以查看这里了解:https://gitee.com/free/Mapper2/blob/master/wiki/mapper/4.Spring4.md

/**
* 通用接口
*/
@Service
public interface IService<T> { T selectByKey(Object key); int save(T entity); int delete(Object key); int updateAll(T entity); int updateNotNull(T entity); List<T> selectByExample(Object example); //TODO 其他...
} /**
* 通用Service 实现
*
* @param <T>
*/
public abstract class BaseService<T> implements IService<T> { @Autowired
protected Mapper<T> mapper; public Mapper<T> getMapper() {
return mapper;
} @Override
public T selectByKey(Object key) {
//说明:根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号
return mapper.selectByPrimaryKey(key);
} @Override
public int save(T entity) {
//说明:保存一个实体,null的属性也会保存,不会使用数据库默认值
return mapper.insert(entity);
} @Override
public int delete(Object key) {
//说明:根据主键字段进行删除,方法参数必须包含完整的主键属性
return mapper.deleteByPrimaryKey(key);
} @Override
public int updateAll(T entity) {
//说明:根据主键更新实体全部字段,null值会被更新
return mapper.updateByPrimaryKey(entity);
} @Override
public int updateNotNull(T entity) {
//根据主键更新属性不为null的值
return mapper.updateByPrimaryKeySelective(entity);
} @Override
public List<T> selectByExample(Object example) {
//说明:根据Example条件进行查询
//重点:这个查询支持通过Example类指定查询列,通过 selectProperties方法指定查询列
return mapper.selectByExample(example);
}
} // 具体业务的 service 接口
public interface LearnService extends IService<LearnResource> { List<LearnResource> queryLearnResouceList(Page<LeanQueryLeanListReq> page); void deleteBatch(Long[] ids);
} // 具体业务的 service 实现接口
@Service
public class LearnServiceImpl extends BaseService<LearnResource> implements LearnService { @Autowired
private LearnResourceMapper learnResourceMapper; @Override
public void deleteBatch(Long[] ids) {
Arrays.stream(ids).forEach(id -> learnResourceMapper.deleteByPrimaryKey(id));
} @Override
public List<LearnResource> queryLearnResouceList(Page<LeanQueryLeanListReq> page) {
PageHelper.startPage(page.getPage(), page.getRows());
return learnResourceMapper.queryLearnResouceList(page.getCondition());
}
}

controller 层

@Controller
@RequestMapping("/learn")
public class LearnController extends AbstractController {
private Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired
private LearnService learnService; @RequestMapping("")
public String learn(Model model) {
model.addAttribute("ctx", getContextPath() + "/");
return "learn-resource";
} /**
* 查询教程列表
*
* @param page
* @return
*/
@RequestMapping(value = "/queryLeanList", method = RequestMethod.POST)
@ResponseBody
public AjaxObject queryLearnList(Page<LeanQueryLeanListReq> page) {
List<LearnResource> learnList = learnService.queryLearnResouceList(page);
PageInfo<LearnResource> pageInfo = new PageInfo<LearnResource>(learnList);
return AjaxObject.ok().put("page", pageInfo);
} /**
* 新添教程
*
* @param learn
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public AjaxObject addLearn(@RequestBody LearnResource learn) {
learnService.save(learn);
return AjaxObject.ok();
} /**
* 修改教程
*
* @param learn
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public AjaxObject updateLearn(@RequestBody LearnResource learn) {
learnService.updateNotNull(learn);
return AjaxObject.ok();
} /**
* 删除教程
*
* @param ids
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public AjaxObject deleteLearn(@RequestBody Long[] ids) {
learnService.deleteBatch(ids);
return AjaxObject.ok();
}
} **
* 前台传的分页参数 分页工具类
*
* @param <T>
*/
public class Page<T> implements Serializable {
private int page; //当前页
private int rows; //每页多少条
private static final long serialVersionUID = 1L;
private List<T> records = Collections.emptyList();
private Map<String, Object> condition; public int getPage() {
return page;
} public void setPage(int page) {
this.page = page;
} public int getRows() {
return rows;
} public void setRows(int rows) {
this.rows = rows;
} public static long getSerialVersionUID() {
return serialVersionUID;
} public List<T> getRecords() {
return records;
} public void setRecords(List<T> records) {
this.records = records;
} public Map<String, Object> getCondition() {
return condition;
} public void setCondition(Map<String, Object> condition) {
this.condition = condition;
}
}

service 没有被事物管理

  • 在 业务 service 类上加 @Transactional 或 方法上加 @Transactional 即可,数据库连接将被事物管理
  • 事务日志如下:
10:30:10.818 logback [http-nio-8090-exec-3] DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Read [class [Ljava.lang.Long;] as "application/json;charset=UTF-8" with [com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@3b22e32f]
10:30:10.822 logback [http-nio-8090-exec-3] DEBUG o.s.t.a.AnnotationTransactionAttributeSource - Adding transactional method 'com.dudu.service.impl.LearnServiceImpl.deleteBatch' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
10:30:10.822 logback [http-nio-8090-exec-3] DEBUG o.s.j.d.DataSourceTransactionManager - Creating new transaction with name [com.dudu.service.impl.LearnServiceImpl.deleteBatch]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
10:30:10.822 logback [http-nio-8090-exec-3] DEBUG o.s.j.d.DataSourceTransactionManager - Acquired Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f82a880] for JDBC transaction
10:30:10.822 logback [http-nio-8090-exec-3] DEBUG o.s.j.d.DataSourceTransactionManager - Switching JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f82a880] to manual commit
10:30:10.830 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - **Creating a new SqlSession**
10:30:10.831 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5454410e]
10:30:10.833 logback [http-nio-8090-exec-3]**DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f82a880] will be managed by Spring**
10:30:10.833 logback [http-nio-8090-exec-3] DEBUG c.d.d.L.deleteByPrimaryKey - ==> Preparing: DELETE FROM learn_resource WHERE id = ?
10:30:10.848 logback [http-nio-8090-exec-3] DEBUG c.d.d.L.deleteByPrimaryKey - ==> Parameters: 1031(Long)
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG c.d.d.L.deleteByPrimaryKey - <== Updates: 1
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG c.a.druid.pool.PreparedStatementPool - {conn-10005, pstmt-20002} enter cache
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5454410e]
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5454410e]
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5454410e]
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG org.mybatis.spring.SqlSessionUtils - Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5454410e]
10:30:10.850 logback [http-nio-8090-exec-3] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
10:30:10.850 logback [http-nio-8090-exec-3] **DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f82a880]**
10:30:10.852 logback [http-nio-8090-exec-3] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5f82a880] after transaction
10:30:10.852 logback [http-nio-8090-exec-3] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource

spring-boot-通用mapper的更多相关文章

  1. spring boot扫描mapper文件

    一个简单的功能,百度查的都是XX,谷歌万岁. 因为扫描不到自动生成的mapper就无法注入到service 方案一.@Mapper 如果Mapper文件所在的包和你的配置mapper的项目的pom定义 ...

  2. Spring boot 通用配置文件模板

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  3. spring boot 中@Mapper和@Repository的区别

    0--前言 @Mapper和@Repository是常用的两个注解,两者都是用在dao上,两者功能差不多,容易混淆,有必要清楚其细微区别: 1--区别 @Repository需要在Spring中配置扫 ...

  4. Spring Boot自定义Mapper的SQL语句

    代码如下: 先创建一个Provider类: public class RptEbankFsymtTranflowingProvider { public String select(String or ...

  5. spring boot 下 mapper接口与xml文件映射问题

    1. @MapperScan @MapperScan("com.streamax.ums.business.dao") 注解扫描的包路径是否有问题 2. 目录结构 mapper接口 ...

  6. 使用Spring Boot搭建应用开发框架(一) —— 基础架构

    Spring的简史 第一阶段:XML配置,在Spring1.x时代,使用Spring开发满眼都是xml配置的Bean,随着项目的扩大,我们需要把xml配置文件分放到不同的配置文件里,那时候需要频繁的在 ...

  7. Spring Boot 整合 Druid

    Spring Boot 整合 Druid 概述 Druid 是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池.插件框架和 SQL 解析器组成.该项目主要是为了扩展 JDBC 的一些限制,可以让程 ...

  8. Spring Boot 系列教程3-MyBatis

    MyBatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache 迁移到了google code,并且改名为MyBatis .2013年11月迁移到Git ...

  9. Spring Boot 集成日志logback + 控制台打印SQL

    一: 控制台打印SQL application.properties中添加如下即可在控制台打印sql logging.level.com.fx.fxxt.mapper=debug 二:日志 因为Spr ...

  10. Spring Boot打包瘦身 Docker 使用全过程 动态配置、日志记录配置

    springBoot打包的时候代码和jar包打包在同一个jar包里面,会导致jar包非常庞大,在不能连接内网的时候调试代码,每次只改动了java代码就需要把所有的jar包一起上传,导致传输文件浪费了很 ...

随机推荐

  1. 探秘SpringAop(一)_介绍以及使用详解

    常用的编程范式 AOP 是什么 是一种编程方式,不是编程语言 解决特定问题,不能解决所有的问题 OOP的补充,不是代替 AOP 初衷 DRY: Don't repeat yourself(代码重复) ...

  2. Linux进程调度策略的发展和演变(转)

    转发:http://blog.csdn.net/gatieme/article/details/51701149  1 前言 1.1 进程调度 内存中保存了对每个进程的唯一描述, 并通过若干结构与其他 ...

  3. MachineLearning Exercise 7 : K-means Clustering and Principle Component Analysis

    findClosestCentroids.m m = size(X,); :m [value index] = min(sum((repmat(X(i,:),K,)-centroids).^,)); ...

  4. Java 继承和多态

                                                        Java  继承和多态 Java 继承 继承的概念 继承是java面向对象编程技术的一块基石,因 ...

  5. jsp中的下载链接

    1.下载链接jsp界面(a链接直接链文件可以看出文件在服务器中的路径,用servlet处理的链接则看不出) <%@ page language="java" contentT ...

  6. 【刷题】洛谷 P1519 穿越栅栏 Overfencing

    题目描述 描述 农夫John在外面的田野上搭建了一个巨大的用栅栏围成的迷宫.幸运的是,他在迷宫的边界上留出了两段栅栏作为迷宫的出口.更幸运的是,他所建造的迷宫是一个“完美的”迷宫:即你能从迷宫中的任意 ...

  7. [BJOI2017]树的难题 点分治 线段树

    题面 [BJOI2017]树的难题 题解 考虑点分治. 对于每个点,将所有边按照颜色排序. 那么只需要考虑如何合并2条链. 有2种情况. 合并路径的接口处2条路径颜色不同 合并路径的接口处2条路径颜色 ...

  8. Android Room使用详解

    使用Room将数据保存在本地数据库 Room提供了SQLite之上的一层抽象, 既允许流畅地访问数据库, 也充分利用了SQLite. 处理大量结构化数据的应用, 能从在本地持久化数据中极大受益. 最常 ...

  9. Java之IO流(字节流,字符流)

    IO流和Properties IO流 IO流是指计算机与外部世界或者一个程序与计算机的其余部分的之间的接口.它对于任何计算机系统都非常关键, 因而所有 I/O 的主体实际上是内置在操作系统中的.单独的 ...

  10. 前端学习 -- Css -- 兄弟元素选择器

    为一个元素后边的元素设置css样式: 语法:前一个 + 后一个. 作用:可以选中一个元素后紧挨着的指定的兄弟元素. 为一个元素后边的所有相同元素设置css样式: 语法:前一个 ~ 后边所有. < ...