forked from leelance/spring-boot-all
-
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
Showing
11 changed files
with
160 additions
and
16 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 |
---|---|---|
|
@@ -62,4 +62,5 @@ local.properties | |
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
.DS_Store | ||
.log | ||
.log | ||
/target |
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
17 changes: 17 additions & 0 deletions
17
spring-boot-samples/src/main/java/com/lance/repository/UserRepository.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,17 @@ | ||
package com.lance.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.lance.entity.UserEntity; | ||
|
||
public interface UserRepository extends JpaRepository<UserEntity, Long>{ | ||
|
||
/** | ||
* 根据userName查询 | ||
* @author lance | ||
* 2014-6-11下午11:30:31 | ||
* @param userName | ||
* @return | ||
*/ | ||
UserEntity findByEmail(String email); | ||
} |
15 changes: 15 additions & 0 deletions
15
spring-boot-samples/src/main/java/com/lance/service/LoginService.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.lance.service; | ||
|
||
import com.lance.entity.UserEntity; | ||
|
||
public interface LoginService { | ||
|
||
/** | ||
* 用户登录 | ||
* @author lance | ||
* 2014-6-11下午11:26:05 | ||
* @param user | ||
* @return | ||
*/ | ||
UserEntity login(UserEntity user); | ||
} |
49 changes: 49 additions & 0 deletions
49
spring-boot-samples/src/main/java/com/lance/service/LoginServiceImpl.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,49 @@ | ||
package com.lance.service; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.lance.entity.UserEntity; | ||
import com.lance.repository.UserRepository; | ||
import com.lance.utils.EncryptUtils; | ||
import com.lance.utils.ServiceException; | ||
|
||
/** | ||
* 登录信息 | ||
* @author lance | ||
*/ | ||
@Service | ||
public class LoginServiceImpl implements LoginService { | ||
@Autowired | ||
private UserRepository userRepository; | ||
/** | ||
* 用户登录 | ||
* @author lance | ||
* 2014-6-11下午11:26:05 | ||
* @param user | ||
* @return | ||
*/ | ||
public UserEntity login(UserEntity user) { | ||
if(StringUtils.isBlank(user.getEmail())) { | ||
throw new ServiceException("用户名不能为空"); | ||
} | ||
|
||
if(StringUtils.isBlank(user.getPassword())) { | ||
throw new ServiceException("密码不能为空"); | ||
} | ||
|
||
UserEntity userEntity = userRepository.findByEmail(user.getEmail()); | ||
if(null == userEntity){ | ||
throw new ServiceException("用户名不存在"); | ||
} | ||
|
||
String password = EncryptUtils.encryptMD5(user.getPassword()); | ||
if(!StringUtils.equals(password, userEntity.getPassword())){ | ||
throw new ServiceException("密码输入错误"); | ||
} | ||
|
||
return userEntity; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
spring-boot-samples/src/main/java/com/lance/utils/ServiceException.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,26 @@ | ||
package com.lance.utils; | ||
|
||
/** | ||
* 处理service抛出运行时异常处理 | ||
* @author lance | ||
*/ | ||
public class ServiceException extends RuntimeException { | ||
private static final long serialVersionUID = 1389958090308317369L; | ||
|
||
public ServiceException() { | ||
super(); | ||
} | ||
|
||
public ServiceException(String msg, Throwable clause) { | ||
super(msg, clause); | ||
} | ||
|
||
public ServiceException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public ServiceException(Throwable clause) { | ||
super(clause); | ||
} | ||
|
||
} |
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
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
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
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 |
---|---|---|
|
@@ -7,6 +7,6 @@ | |
<title>Insert title here</title> | ||
</head> | ||
<body> | ||
|
||
This is a list page. | ||
</body> | ||
</html> |
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