-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yanhua13
committed
Jun 1, 2017
0 parents
commit fe9d03c
Showing
28 changed files
with
1,757 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
*~ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.ids | ||
.DS_Store | ||
pom.xml.releaseBackup | ||
release.properties | ||
.idea/ | ||
target/ | ||
.classpath | ||
.project | ||
.settings/ | ||
lib/ | ||
logs/ | ||
target/ | ||
bin/ | ||
.DS_Store | ||
.metadata | ||
*.log | ||
*.log.* | ||
.idea/ | ||
*.iml | ||
.vagrant/ | ||
.#* | ||
config_center_client.log | ||
.svn | ||
rebel.xml | ||
common.properties | ||
important.properties | ||
dev-local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
生鲜项目模板工程 | ||
==================================== | ||
|
||
使用方式详见本项目的wikis : http://git.jd.com/pop-lab/fresh-boot/wikis/home | ||
|
||
> 本模板裁剪自 [hydrabones](http://git.jd.com/pop-lab/hydrabones),hydrabones提供的大部分说明文档依旧有效。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>com.fresh.hydra</groupId> | ||
<artifactId>hydra-center</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<groupId>com.fresh.hydra</groupId> | ||
<artifactId>hydra-center-domain-service</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>hydra-center-domain-service</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>1.4.4.RELEASE</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jd.spring.boot</groupId> | ||
<artifactId>jd-spring-boot-dependencies</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>19.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.24</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>1.4.193</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-all</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fresh.commons</groupId> | ||
<artifactId>commons-data</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.gmavenplus</groupId> | ||
<artifactId>gmavenplus-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generateStubs</goal> | ||
<goal>compile</goal> | ||
<goal>testGenerateStubs</goal> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
51 changes: 51 additions & 0 deletions
51
...-service/src/main/groovy/com/fresh/hydra/center/biz/user/repository/UserRepository.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.fresh.hydra.center.biz.user.repository | ||
|
||
import com.fresh.commons.data.page.PageRequest | ||
import com.fresh.hydra.center.biz.user.domain.User | ||
import com.fresh.hydra.center.biz.user.domain.UserQuery | ||
import org.apache.ibatis.annotations.Delete | ||
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 org.apache.ibatis.annotations.Update | ||
|
||
/** | ||
* Created by yanhua on 2017/2/3. | ||
*/ | ||
@Mapper | ||
public interface UserRepository { | ||
|
||
@Insert("INSERT into T_USER (name,age,addr) VALUES(#{name}, #{age}, #{addr})") | ||
void add(User user); | ||
|
||
@Select("SELECT * FROM T_USER WHERE id = #{id}") | ||
User getById(@Param("id") Long id); | ||
|
||
@Select("""<script>SELECT * FROM T_USER WHERE 1=1 | ||
<if test="query.name != null"> AND name like #{query.name}</if> | ||
<if test="query.addr != null"> AND addr = #{query.addr}</if> | ||
<if test="query.age != null"> AND age = #{query.age}</if> | ||
limit #{page.offset} , #{page.pageSize} | ||
</script> | ||
""") | ||
List<User> findUserList(@Param("query") UserQuery query, @Param("page") PageRequest pageRequest); | ||
|
||
@Select("""<script>SELECT COUNT(id) FROM T_USER WHERE 1=1 | ||
<if test="query.name != null"> AND name like #{query.name}</if> | ||
<if test="query.addr != null"> AND addr = #{query.addr}</if> | ||
<if test="query.age != null"> AND age = #{query.age}</if> | ||
</script> | ||
""") | ||
long count(@Param("query") UserQuery query); | ||
|
||
@Select("SELECT * FROM T_USER WHERE name = #{name}") | ||
User getByName(@Param("name") String name) | ||
|
||
|
||
@Update("UPDATE T_USER SET name=#{user.name}, age=#{user.age}, addr=#{user.addr} WHERE id=#{user.id}") | ||
void update(@Param("user") User user); | ||
|
||
@Delete("DELETE FROM T_USER WHERE id =#{id}") | ||
void delete(@Param("id") Long id); | ||
} |
15 changes: 15 additions & 0 deletions
15
hydra-center-domain-service/src/main/java/com/fresh/hydra/center/biz/user/domain/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.fresh.hydra.center.biz.user.domain; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* 用户 | ||
* Created by yanhua on 2017/1/5. | ||
*/ | ||
@Data | ||
public class User { | ||
private Long id; | ||
private String name; | ||
private Integer age; | ||
private String addr; | ||
} |
13 changes: 13 additions & 0 deletions
13
...center-domain-service/src/main/java/com/fresh/hydra/center/biz/user/domain/UserQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.fresh.hydra.center.biz.user.domain; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* Created by yanhua on 2017/2/3. | ||
*/ | ||
@Data | ||
public class UserQuery { | ||
private String name; | ||
private String addr; | ||
private Integer age; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ter-domain-service/src/main/java/com/fresh/hydra/center/biz/user/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.fresh.hydra.center.biz.user.service; | ||
|
||
import com.fresh.commons.data.page.Page; | ||
import com.fresh.commons.data.page.PageRequest; | ||
import com.fresh.hydra.center.biz.user.domain.User; | ||
import com.fresh.hydra.center.biz.user.domain.UserQuery; | ||
|
||
|
||
/** | ||
* Created by yanhua on 2017/2/3. | ||
*/ | ||
public interface UserService { | ||
Page<User> findUserPage(UserQuery query, PageRequest pageRequest); | ||
|
||
User getUserById(Long id ); | ||
|
||
void updateUser(User user) throws DuplicateUsernameException; | ||
|
||
void deleteUser(Long id); | ||
|
||
public static class DuplicateUsernameException extends Exception{ | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...domain-service/src/main/java/com/fresh/hydra/center/biz/user/service/UserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.fresh.hydra.center.biz.user.service; | ||
|
||
import com.fresh.commons.data.page.Page; | ||
import com.fresh.commons.data.page.PageRequest; | ||
import com.fresh.hydra.center.biz.user.domain.UserQuery; | ||
import com.fresh.hydra.center.biz.user.domain.User; | ||
import com.fresh.hydra.center.biz.user.repository.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by yanhua on 2017/2/3. | ||
*/ | ||
@Service | ||
public class UserServiceImpl implements UserService { | ||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Override | ||
public Page<User> findUserPage(UserQuery query, PageRequest pageRequest) { | ||
List<User> userList = userRepository.findUserList(query, pageRequest); | ||
long count = userRepository.count(query); | ||
Page<User> userPage = new Page<>(); | ||
userPage.setPage(pageRequest.getPage()); | ||
userPage.setSize(pageRequest.getPageSize()); | ||
userPage.setTotalElements(count); | ||
userPage.setContent(userList); | ||
return userPage; | ||
} | ||
|
||
@Override | ||
public User getUserById(Long id) { | ||
return userRepository.getById(id); | ||
} | ||
|
||
@Override | ||
public void updateUser(User user) throws DuplicateUsernameException { | ||
Assert.notNull(user.getId(), "user id is null."); | ||
User u = userRepository.getByName(user.getName()); | ||
if(u != null && !u.getId().equals(user.getId())) { | ||
throw new DuplicateUsernameException(); | ||
} | ||
|
||
userRepository.update(user); | ||
|
||
} | ||
|
||
@Override | ||
public void deleteUser(Long id) { | ||
userRepository.delete(id); | ||
} | ||
|
||
|
||
public void setUserRepository(UserRepository userRepository) { | ||
this.userRepository = userRepository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE TABLE IF NOT EXISTS T_USER( | ||
ID INT NOT NULL AUTO_INCREMENT, | ||
NAME VARCHAR(100) NOT NULL, | ||
AGE INT NOT NULL, | ||
ADDR VARCHAR(200), | ||
PRIMARY KEY ( ID ) | ||
); | ||
|
||
|
||
INSERT INTO T_USER (NAME, AGE, ADDR) VALUES ('Jack', 20, 'BJ'); | ||
INSERT INTO T_USER (NAME, AGE, ADDR) VALUES ('Jones', 18, 'SH'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
这里放置JSF服务层 |
Oops, something went wrong.