diff --git a/ace-blog-parent/ace-blog-admin/pom.xml b/ace-blog-parent/ace-blog-admin/pom.xml
index d1a712041f685face951e53e7706735de2d4baf8..63e656ff214d4936a08fb0ba2bbecefdfb922109 100644
--- a/ace-blog-parent/ace-blog-admin/pom.xml
+++ b/ace-blog-parent/ace-blog-admin/pom.xml
@@ -5,11 +5,16 @@
ace-blog-parent
org.springframework.boot
- 1.4.2.RELEASE
+ 1.5.2.RELEASE
4.0.0
ace-blog-admin
+
+ true
+ 1.8
+
+ 1.1.4
1.5.12
@@ -84,17 +89,22 @@
5.1.30
-
-
+
- org.mybatis
- mybatis
- ${mybatis.version}
+ org.springframework.boot
+ spring-boot-starter-data-jpa
- org.mybatis
- mybatis-spring
- ${mybatis.spring.version}
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 1.3.0
@@ -151,8 +161,21 @@
guava
20.0
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jre8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-reflect
+ ${kotlin.version}
+
+ ${project.basedir}/src/main/java
blog-admin
@@ -183,6 +206,41 @@
org.springframework.boot
spring-boot-maven-plugin
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${kotlin.version}
+
+
+ spring
+
+ 1.8
+
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-allopen
+ ${kotlin.version}
+
+
+
\ No newline at end of file
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/BlogAdminBootstrap.java b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/BlogAdminBootstrap.java
index 6910032ddaa5a4d820d6c416c33b31bd41c59264..10afd29b25fa1411cdf6b857447875cdef1b4ea2 100644
--- a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/BlogAdminBootstrap.java
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/BlogAdminBootstrap.java
@@ -1,9 +1,12 @@
package com.github.wxiaoqi.blog.admin;
+import com.github.wxiaoqi.blog.admin.repository.BaseRepositoryFactoryBean;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* ${DESCRIPTION}
@@ -14,6 +17,8 @@ import org.springframework.cloud.netflix.hystrix.EnableHystrix;
@EnableEurekaClient
@EnableHystrix
@SpringBootApplication
+@MapperScan(basePackages = "com.github.wxiaoqi.blog.admin.mapper")
+@EnableJpaRepositories(repositoryFactoryBeanClass = BaseRepositoryFactoryBean.class)
public class BlogAdminBootstrap {
public static void main(String[] args) {
new SpringApplicationBuilder(BlogAdminBootstrap.class).web(true).run(args); }
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/biz/BlogBiz.kt b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/biz/BlogBiz.kt
new file mode 100644
index 0000000000000000000000000000000000000000..a484113daba6b4da3ffbd9574813810a1528bf14
--- /dev/null
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/biz/BlogBiz.kt
@@ -0,0 +1,52 @@
+package com.github.wxiaoqi.blog.admin.biz
+
+import com.github.wxiaoqi.blog.admin.dao.BlogDao
+import com.github.wxiaoqi.blog.admin.entity.Blog
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.data.domain.Page
+import org.springframework.data.domain.Pageable
+import org.springframework.stereotype.Service
+import org.springframework.transaction.annotation.Propagation
+import org.springframework.transaction.annotation.Transactional
+
+/**
+ * 博客服务层
+ * @author colin
+ */
+@Service
+class BlogBiz{
+
+ @Autowired
+ private var blogDao: BlogDao? = null
+
+ /**
+ * 新增/修改
+ * @return 新增/修改后的对象
+ */
+ fun save(blog: Blog): Blog{
+ return blogDao!!.save(blog)
+ }
+
+ /**
+ * 根据id修改名称
+ */
+ @Transactional(rollbackFor = arrayOf(Exception::class),propagation = Propagation.REQUIRED)
+ fun updateNameById(id: Int,name: String){
+ val blog = blogDao!!.findOne(id)
+ //jpa查询出对象后,使用事务进行提交,不需要再写save方法
+ blog.name = name
+ }
+
+ /**
+ * 根据名称like并选出博主年龄大于25岁的
+ * 返回值可为空
+ */
+ fun findByNameLike(name: String): List? {
+ //fiter是kotlin的一个高阶函数,简化了jdk8的lambda表达式的stream().filter
+ return blogDao!!.findByNameContaining(name).filter { it.user != null && it.user.age > 25 }
+ }
+
+ fun findByArticlesTitleIn(titles: List,pageable: Pageable): Page{
+ return blogDao!!.findByArticlesTitleIn(titles,pageable)
+ }
+}
\ No newline at end of file
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MapperConfiguration.java b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MapperConfiguration.java
index 86a3fcf8f4f44f1d8830931365dc5a1635270ff6..a0dbf15b44d56f62ca4a51c4398f78e904b8808e 100644
--- a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MapperConfiguration.java
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MapperConfiguration.java
@@ -15,9 +15,10 @@ import tk.mybatis.spring.mapper.MapperScannerConfigurer;
* @author wanghaobin
* @date 2016年12月15日
* @since 1.7
+ * 使用配置文件配置
*/
-@Configuration
-@AutoConfigureAfter(MybatisConfiguration.class)
+//@Configuration
+//@AutoConfigureAfter(MybatisConfiguration.class)
public class MapperConfiguration implements EnvironmentAware {
private RelaxedPropertyResolver propertyResolver;
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MybatisConfiguration.java b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MybatisConfiguration.java
index a458a1bcb51cdcb09a9cd6df9b53965b0f727a0d..2c49ac01f03331044c4435e6b40a786c4ba0ba2d 100644
--- a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MybatisConfiguration.java
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/config/MybatisConfiguration.java
@@ -28,9 +28,10 @@ import java.util.Properties;
* @author wanghaobin
* @date 2016年12月15日
* @since 1.7
+ * 使用配置文件配置
*/
-@Configuration
-@EnableTransactionManagement
+//@Configuration
+//@EnableTransactionManagement
public class MybatisConfiguration implements EnvironmentAware {
@@ -95,6 +96,9 @@ public class MybatisConfiguration implements EnvironmentAware {
if(StringUtils.isNotBlank(typeAliasesPackage)){
bean.setTypeAliasesPackage(typeAliasesPackage);
}
+ org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
+ configuration.setMapUnderscoreToCamelCase(true); //启用驼峰命名
+ bean.setConfiguration(configuration);
//分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
@@ -108,7 +112,7 @@ public class MybatisConfiguration implements EnvironmentAware {
Interceptor[] plugins = new Interceptor[]{pageHelper};
bean.setPlugins(plugins);
try {
- bean.setMapperLocations(resolver.getResources(xmlLocation));
+// bean.setMapperLocations(resolver.getResources(xmlLocation)); 取消xml引入,使用注解
return bean.getObject();
} catch (Exception e) {
e.printStackTrace();
@@ -140,7 +144,9 @@ public class MybatisConfiguration implements EnvironmentAware {
this.testOnReturn = propertyResolver.getProperty("spring.datasource.testOnReturn");
this.poolPreparedStatements = propertyResolver.getProperty("spring.datasource.poolPreparedStatements");
this.maxOpenPreparedStatements = propertyResolver.getProperty("spring.datasource.maxOpenPreparedStatements");
- this.typeAliasesPackage = propertyResolver.getProperty("mybatis.typeAliasesPackage");
+// this.typeAliasesPackage = propertyResolver.getProperty("mybatis.typeAliasesPackage");
+ //修改扫描包的地址
+ this.typeAliasesPackage = propertyResolver.getProperty("com.github.wxiaoqi.blog.admin.entity");
this.xmlLocation = propertyResolver.getProperty("mybatis.xmlLocation");
}
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogArticleDao.java b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogArticleDao.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d7a06bd05e09e23a3ab8f54224a088b1a005314
--- /dev/null
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogArticleDao.java
@@ -0,0 +1,11 @@
+package com.github.wxiaoqi.blog.admin.dao;
+
+import com.github.wxiaoqi.blog.admin.entity.BlogArticle;
+import com.github.wxiaoqi.blog.admin.repository.BaseRepository;
+
+/**
+ *
+ * @author colin
+ */
+public interface BlogArticleDao extends BaseRepository {
+}
diff --git a/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogDao.java b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogDao.java
new file mode 100644
index 0000000000000000000000000000000000000000..b800137836617f87cc0713eb1bc98facb1707c7a
--- /dev/null
+++ b/ace-blog-parent/ace-blog-admin/src/main/java/com/github/wxiaoqi/blog/admin/dao/BlogDao.java
@@ -0,0 +1,49 @@
+package com.github.wxiaoqi.blog.admin.dao;
+
+import com.github.wxiaoqi.blog.admin.entity.Blog;
+import com.github.wxiaoqi.blog.admin.repository.BaseRepository;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * @author colin
+ */
+public interface BlogDao extends BaseRepository {
+
+ /**
+ * 根据博客中博文的标题在某个范围查询
+ * @param titles 多个标题
+ * @return
+ */
+ Page findByArticlesTitleIn(List titles,Pageable pageable);
+
+ /**
+ * 相当于 name like '%?%'
+ * @param name
+ * @return
+ */
+ List findByNameContaining(String name);
+
+ /**
+ * 使用nativeQuery不能使用jpa的自动分页pageable
+ * @return
+ */
+ @Query(value = "select * from blog where name = ?1",nativeQuery = true)
+ List findBySqlName();
+
+ /**
+ * 使用jdbc查询,需要jdk 1.8
+ * 可以根据需要传入jdbcTemplate也可以传入jpa的entityManager,在service层中@Autowired
+ */
+ default List