Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
61b20f5d
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
61b20f5d
编写于
3月 27, 2017
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spring boot example dao
上级
71f9dcf0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
158 addition
and
0 deletion
+158
-0
whatsmars-spring-boot/pom.xml
whatsmars-spring-boot/pom.xml
+10
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/DataSourceConfiguration.java
...itlong/whatsmars/spring/boot/DataSourceConfiguration.java
+46
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/MapperScanner.java
.../java/com/itlong/whatsmars/spring/boot/MapperScanner.java
+24
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/MybatisConfig.java
.../java/com/itlong/whatsmars/spring/boot/MybatisConfig.java
+48
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/TestDao.java
...c/main/java/com/itlong/whatsmars/spring/boot/TestDao.java
+22
-0
whatsmars-spring-boot/src/main/resources/prop.properties
whatsmars-spring-boot/src/main/resources/prop.properties
+8
-0
未找到文件。
whatsmars-spring-boot/pom.xml
浏览文件 @
61b20f5d
...
...
@@ -20,6 +20,16 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<artifactId>
mybatis-spring-boot-starter
</artifactId>
<version>
1.1.1
</version>
</dependency>
<dependency>
<groupId>
commons-dbcp
</groupId>
<artifactId>
commons-dbcp
</artifactId>
<version>
1.4
</version>
</dependency>
</dependencies>
<build>
...
...
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/DataSourceConfiguration.java
0 → 100644
浏览文件 @
61b20f5d
package
com.itlong.whatsmars.spring.boot
;
import
org.apache.commons.dbcp.BasicDataSource
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
/**
* Created by Administrator on 2017/3/27.
*/
@Configuration
//这个注解导入刚才增加的jdbc配置文件
@PropertySource
(
"classpath:prop.properties"
)
public
class
DataSourceConfiguration
{
@Value
(
"${jdbc.driver}"
)
private
String
driver
;
@Value
(
"${jdbc.url}"
)
private
String
url
;
@Value
(
"${jdbc.username}"
)
private
String
username
;
@Value
(
"${jdbc.password}"
)
private
String
password
;
@Value
(
"${jdbc.maxActive}"
)
private
int
maxActive
;
@Value
(
"${jdbc.maxIdel}"
)
private
int
maxIdel
;
@Value
(
"${jdbc.maxWait}"
)
private
long
maxWait
;
@Bean
public
BasicDataSource
dataSource
(){
BasicDataSource
dataSource
=
new
BasicDataSource
();
dataSource
.
setDriverClassName
(
driver
);
dataSource
.
setUrl
(
url
);
dataSource
.
setUsername
(
username
);
dataSource
.
setPassword
(
password
);
dataSource
.
setMaxActive
(
maxActive
);
dataSource
.
setMaxIdle
(
maxIdel
);
dataSource
.
setMaxWait
(
maxWait
);
dataSource
.
setValidationQuery
(
"SELECT 1"
);
dataSource
.
setTestOnBorrow
(
true
);
return
dataSource
;
}
}
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/MapperScanner.java
0 → 100644
浏览文件 @
61b20f5d
package
com.itlong.whatsmars.spring.boot
;
import
org.mybatis.spring.mapper.MapperScannerConfigurer
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* Created by Administrator on 2017/3/27.
*/
@Configuration
// 因为这个对象的扫描,需要在MyBatisConfig的后面注入,所以加上下面的注解
@AutoConfigureAfter
(
MybatisConfig
.
class
)
public
class
MapperScanner
{
@Bean
public
MapperScannerConfigurer
mapperScannerConfigurer
()
{
MapperScannerConfigurer
mapperScannerConfigurer
=
new
MapperScannerConfigurer
();
//获取之前注入的beanName为sqlSessionFactory的对象
mapperScannerConfigurer
.
setSqlSessionFactoryBeanName
(
"sqlSessionFactory"
);
//指定xml配置文件的路径
mapperScannerConfigurer
.
setBasePackage
(
"com.framework.msg.mapper"
);
return
mapperScannerConfigurer
;
}
}
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/MybatisConfig.java
0 → 100644
浏览文件 @
61b20f5d
package
com.itlong.whatsmars.spring.boot
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.TransactionManagementConfigurer
;
import
javax.sql.DataSource
;
/**
* Created by Administrator on 2017/3/27.
*/
@Configuration
//加上这个注解,使得支持事务
@EnableTransactionManagement
public
class
MybatisConfig
implements
TransactionManagementConfigurer
{
@Autowired
private
DataSource
dataSource
;
@Override
public
PlatformTransactionManager
annotationDrivenTransactionManager
()
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
(
name
=
"sqlSessionFactory"
)
public
SqlSessionFactory
sqlSessionFactoryBean
()
{
SqlSessionFactoryBean
bean
=
new
SqlSessionFactoryBean
();
bean
.
setDataSource
(
dataSource
);
try
{
return
bean
.
getObject
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
e
);
}
}
@Bean
public
SqlSessionTemplate
sqlSessionTemplate
(
SqlSessionFactory
sqlSessionFactory
)
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
}
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/TestDao.java
0 → 100644
浏览文件 @
61b20f5d
package
com.itlong.whatsmars.spring.boot
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.Map
;
/**
* Created by Administrator on 2017/3/27.
*/
@Mapper
public
interface
TestDao
{
@Select
(
"select * from wx_userinfo;"
)
public
Map
<
String
,
Object
>
find
();
@Insert
(
"insert into wx_userinfo(openid,status,nickname,sex,city,province,country,headimgurl,subscribe_time) "
+
"values(#{id},1,'nick',1,'city','provi','contr','img',now())"
)
public
int
insert
(
@Param
(
"id"
)
int
id
);
}
whatsmars-spring-boot/src/main/resources/prop.properties
0 → 100644
浏览文件 @
61b20f5d
#jdbc
jdbc.driver
=
com.mysql.jdbc.Driver
jdbc.url
=
jdbc:mysql://192.168.137.2:3306/weichat?useUnicode=true&characterEncoding=utf8
jdbc.username
=
root
jdbc.password
=
123456
jdbc.maxActive
=
2335
jdbc.maxIdel
=
120
jdbc.maxWait
=
100
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录