Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix MapperScan import, fix login html syntax, add log
  • Loading branch information
yennanliu committed Oct 10, 2022
commit fbb07d1635fbc3e75c0499d07f9b8de0c6f2026f
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// book p. 262

import org.mybatis.spring.annotation.MapperScan;
import tk.mybatis.spring.annotation.MapperScan; // should use this one!! https://blog.csdn.net/fygkchina/article/details/109159608
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.yen.springCourseSystem.bean.User;
import com.yen.springCourseSystem.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -14,6 +15,7 @@

@Controller
@RequestMapping("/security")
@Log4j2
public class SecurityController {

@Autowired
Expand All @@ -33,28 +35,37 @@ public String toLogin(Map<String, Object> map){
// register page
@RequestMapping("/register")
public String register(){

return "register";
}

// register doc page
@RequestMapping("/readdoc")
public String readdoc(){

return "readdoc";
}

// register method
@RequestMapping("addregister")
public String register(HttpServletRequest request){

String username = request.getParameter("username");
String password = request.getParameter("password");
String password2 = request.getParameter("password2");

log.info(">>> username = {}, password = {}, password2 = {}", username, password, password2);

if (password.equals(password2)){
User userEntity = new User();
userEntity.setUserName(username);
userEntity.setUserPwd(password);
userService.addUser(userEntity);
log.info(">>> login OK");
return "login";
//return "test";
}else{
log.info(">>> login failed, plz try again");
return "register";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.yen.springCourseSystem.bean.User;
import com.yen.springCourseSystem.mapper.UserMapper;
import com.yen.springCourseSystem.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

@Resource
Expand All @@ -27,6 +29,7 @@ public List<User> loadUserByUserName(String userName) {

@Override
public void addUser(User user) {
log.info(">>> addUser : user = {}", user);
userMapper.insert(user);
}

Expand Down
9 changes: 5 additions & 4 deletions springCourseSystem/src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div>
<div id="wrapper" style="text-align:center">

<img id="login" width="100" height="20" th:src="@{/pics/logo.png}" />
<!-- <img id="login" width="100" height="20" th:src="@{/pics/logo.png}" />-->
<div id = "f_title">Course Admin Login</div><br>

<form th:action="@{/security/login}" method="post" th:object="${user}">
Expand All @@ -31,8 +31,9 @@
</form>
</div>
</div>
<div id="footer">
<div th:include="footer::copy"></div><div th:include="footer::time"></div>
</div>
<!--<div id="footer">-->
<!-- <div th:include="footer::copy"></div>-->
<!-- <div th:include="footer::time"></div>-->
<!--</div>-->
</body>
</html>
11 changes: 11 additions & 0 deletions springCourseSystem/src/main/resources/templates/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<h1>THIS IS TEST HTML !!!</h1>
</head>
<body>

</body>
</html>