Skip to content

Commit 8374743

Browse files
authored
Merge pull request #8 from yennanliu/dev-007-course-system-dep-fix
dev-007-course-system-dep-fix : fix dep version make app run OK local in m1 MBA
2 parents ea3adc6 + 08c5fb4 commit 8374743

File tree

11 files changed

+67
-28
lines changed

11 files changed

+67
-28
lines changed

springCourseSystem/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ java -jar <built_jar>
3131
| ----- | -------- | ---- | ----- | ---- |
3232
| Login | http://localhost:8888 | | |
3333
| Register |http://localhost:8888/security/register | | |
34-
| Course | http://localhost:8888/course | | |
35-
36-
34+
| Input new course | http://localhost:8888/course/toInput | | |
3735

3836
## Important Concepts
3937

springCourseSystem/pom.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<parent>
66
<groupId>org.springframework.boot</groupId>
7+
<version>2.7.2</version>
78
<artifactId>spring-boot-starter-parent</artifactId>
89
<!-- <version>2.7.2</version> -->
910
<relativePath/> <!-- lookup parent from repository -->
@@ -15,6 +16,8 @@
1516
<description>spring Course admin System</description>
1617

1718
<properties>
19+
<maven.compiler.source>8</maven.compiler.source>
20+
<maven.compiler.target>8</maven.compiler.target>
1821
</properties>
1922

2023
<dependencies>
@@ -63,11 +66,11 @@
6366
<artifactId>spring-boot-starter-thymeleaf</artifactId>
6467
</dependency>
6568

66-
<dependency>
67-
<groupId>javax.persistence</groupId>
68-
<artifactId>persistence-api</artifactId>
69-
<version>1.0</version>
70-
</dependency>
69+
<!-- <dependency>-->
70+
<!-- <groupId>javax.persistence</groupId>-->
71+
<!-- <artifactId>persistence-api</artifactId>-->
72+
<!-- <version>1.0</version>-->
73+
<!-- </dependency>-->
7174

7275
<dependency>
7376
<groupId>org.springframework</groupId>

springCourseSystem/src/main/java/com/yen/springCourseSystem/CourseSystemApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// book p. 262
44

5-
import org.mybatis.spring.annotation.MapperScan;
5+
import tk.mybatis.spring.annotation.MapperScan; // should use this one!! https://blog.csdn.net/fygkchina/article/details/109159608
66
import org.springframework.boot.SpringApplication;
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
88
import org.springframework.context.annotation.ComponentScan;
@@ -16,7 +16,8 @@ public class CourseSystemApplication {
1616

1717
public static void main(String[] args) {
1818

19-
SpringApplication.run(CourseSystemApplication.class, args);
19+
SpringApplication.run(
20+
CourseSystemApplication.class, args);
2021
}
2122

2223
}

springCourseSystem/src/main/java/com/yen/springCourseSystem/controller/CourseController.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import com.github.pagehelper.PageInfo;
77
import com.yen.springCourseSystem.Util.CourseQueryHelper;
88
import com.yen.springCourseSystem.bean.Course;
9+
import com.yen.springCourseSystem.bean.CourseType;
910
import com.yen.springCourseSystem.service.CourseService;
1011
import com.yen.springCourseSystem.service.CourseTypeService;
12+
import lombok.extern.slf4j.Slf4j;
1113
import org.springframework.beans.factory.annotation.Autowired;
1214
import org.springframework.stereotype.Controller;
1315
import org.springframework.web.bind.annotation.*;
1416
import org.springframework.web.multipart.MultipartFile;
15-
1617
import javax.servlet.ServletOutputStream;
1718
import javax.servlet.http.HttpServletRequest;
1819
import javax.servlet.http.HttpServletResponse;
@@ -24,6 +25,7 @@
2425

2526
@Controller
2627
@RequestMapping("/course")
28+
@Slf4j
2729
public class CourseController {
2830

2931
@Autowired
@@ -33,11 +35,11 @@ public class CourseController {
3335
private CourseTypeService courseTypeService;
3436

3537
@ModelAttribute // TODO : check what's this
36-
public void getCourse(
37-
@RequestParam(value="courseNo", required = false) String courseNo,
38+
public void getCourse(@RequestParam(value="courseNo", required = false) String courseNo,
3839
Map<String, Object> map,
3940
Course course){
4041

42+
log.info(">>> courseNo = {}, map = {}, course = {}", courseNo, map, course);
4143
course = courseService.loadCourseByNo(courseNo);
4244
if (courseNo != null && course != null){
4345
map.put("course", course);
@@ -46,18 +48,22 @@ public void getCourse(
4648

4749
@GetMapping("/toInput")
4850
public String toInput(Map<String, Object> map, Course course){
49-
map.put("courseTypeList", courseTypeService.loadAll());
51+
52+
log.info(">>> map = {}, course = {}", map, course);
53+
List<CourseType> courses = courseTypeService.loadAll();
54+
log.info(">>> courses = {}", courses.toString());
55+
map.put("courseTypeList", courses);
5056
course.setCourseStatus("O");
5157
course.setCourseReqs(new String[]{"a", "b"});
5258
map.put("course", course);
5359
return "course/input_course";
5460
}
5561

5662
@PostMapping(value = "/create")
57-
public String create(
58-
@RequestParam("courseTextBookPic")MultipartFile file,
63+
public String create(@RequestParam("courseTextBookPic")MultipartFile file,
5964
Course course,
6065
Map<String, Object> map) throws IOException {
66+
6167
// read file, transform to binary array
6268
if (file != null){
6369
course.setCourseTextBookPic(file.getBytes());

springCourseSystem/src/main/java/com/yen/springCourseSystem/controller/SecurityController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

1516
@Controller
1617
@RequestMapping("/security")
18+
@Log4j2
1719
public class SecurityController {
1820

1921
@Autowired
@@ -33,28 +35,37 @@ public String toLogin(Map<String, Object> map){
3335
// register page
3436
@RequestMapping("/register")
3537
public String register(){
38+
3639
return "register";
3740
}
3841

3942
// register doc page
4043
@RequestMapping("/readdoc")
4144
public String readdoc(){
45+
4246
return "readdoc";
4347
}
4448

4549
// register method
4650
@RequestMapping("addregister")
4751
public String register(HttpServletRequest request){
52+
4853
String username = request.getParameter("username");
4954
String password = request.getParameter("password");
5055
String password2 = request.getParameter("password2");
56+
57+
log.info(">>> username = {}, password = {}, password2 = {}", username, password, password2);
58+
5159
if (password.equals(password2)){
5260
User userEntity = new User();
5361
userEntity.setUserName(username);
5462
userEntity.setUserPwd(password);
5563
userService.addUser(userEntity);
64+
log.info(">>> login OK");
5665
return "login";
66+
//return "test";
5767
}else{
68+
log.info(">>> login failed, plz try again");
5869
return "register";
5970
}
6071
}

springCourseSystem/src/main/java/com/yen/springCourseSystem/mapper/CourseMapper.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<!-- PK -->
2525
<id property="courseNo" column="course_no"></id>
2626
<!-- other col -->
27-
<result property="" column=""></result>
2827
<result property="courseName" column="course_name"></result>
2928
<result property="courseHours" column="course_hours"></result>
3029
<result property="courseStatus" column="course_status"></result>

springCourseSystem/src/main/java/com/yen/springCourseSystem/service/impl/CourseServiceImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.yen.springCourseSystem.bean.Course;
77
import com.yen.springCourseSystem.mapper.CourseMapper;
88
import com.yen.springCourseSystem.service.CourseService;
9+
import lombok.extern.log4j.Log4j2;
910
import org.springframework.stereotype.Service;
1011

1112
import javax.annotation.Resource;
@@ -15,24 +16,28 @@
1516
import java.util.Map;
1617

1718
@Service
19+
@Log4j2
1820
public class CourseServiceImpl implements CourseService {
1921

2022
@Resource
2123
CourseMapper courseMapper;
2224

2325
@Override
2426
public void addCourse(Course course) {
27+
2528
courseMapper.addCourse(course);
2629
}
2730

2831
@Override
2932
public boolean removeCourseByNo(String courseNo) {
33+
3034
courseMapper.removeCourseByNo(courseNo);
3135
return true;
3236
}
3337

3438
@Override
3539
public void updateCourse(Course course) {
40+
3641
String[] courseReq = course.getCourseReqs();
3742
if (courseReq != null && courseReq.length > 0){
3843
courseMapper.updateCourse(course);
@@ -44,13 +49,14 @@ public void updateCourse(Course course) {
4449

4550
@Override
4651
public Course loadCourseByNo(String courseNo) {
52+
4753
// TODO : re-check this ?
54+
log.info(">>> courseNo = {}", courseNo);
4855
Course course = new Course();
49-
course = null;
56+
//course = null;
5057
if (courseNo != null){
5158
course = courseMapper.loadCourseByNo(courseNo);
5259
}
53-
5460
return course;
5561
}
5662

springCourseSystem/src/main/java/com/yen/springCourseSystem/service/impl/UserServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import com.yen.springCourseSystem.bean.User;
66
import com.yen.springCourseSystem.mapper.UserMapper;
77
import com.yen.springCourseSystem.service.UserService;
8+
import lombok.extern.slf4j.Slf4j;
89
import org.springframework.stereotype.Service;
910

1011
import javax.annotation.Resource;
1112
import java.util.List;
1213

1314
@Service
15+
@Slf4j
1416
public class UserServiceImpl implements UserService {
1517

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

2830
@Override
2931
public void addUser(User user) {
32+
log.info(">>> addUser : user = {}", user);
3033
userMapper.insert(user);
3134
}
3235

springCourseSystem/src/main/resources/templates/course/input_course.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
</head>
99
<body style="padding:8px;">
1010
<h3 class="title">add new course</h3>
11-
<img id="textbookpic"
12-
alt = "default book home page"
13-
width="300"
14-
height="200"
15-
style="float:right" th:src="@{/pics/SpringBoot.png}" /><br/>
11+
<!-- <img id="textbookpic"-->
12+
<!-- alt = "default book home page"-->
13+
<!-- width="300"-->
14+
<!-- height="200"-->
15+
<!-- style="float:right" th:src="@{/pics/SpringBoot.png}" /><br/>-->
1616
<form th:action="@{/course/create}" method="post" enctype="multipart/form-data" th:object="${course}">
1717
<div>
1818
<span>Course No : </span>

springCourseSystem/src/main/resources/templates/login.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div>
1212
<div id="wrapper" style="text-align:center">
1313

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

1717
<form th:action="@{/security/login}" method="post" th:object="${user}">
@@ -31,8 +31,9 @@
3131
</form>
3232
</div>
3333
</div>
34-
<div id="footer">
35-
<div th:include="footer::copy"></div><div th:include="footer::time"></div>
36-
</div>
34+
<!--<div id="footer">-->
35+
<!-- <div th:include="footer::copy"></div>-->
36+
<!-- <div th:include="footer::time"></div>-->
37+
<!--</div>-->
3738
</body>
3839
</html>

0 commit comments

Comments
 (0)