Skip to content

Commit 61e2d2d

Browse files
author
BG317958
committed
Spring MVC practise with bootstrap-update
1 parent f37038f commit 61e2d2d

27 files changed

+1281
-879
lines changed

.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 844 additions & 778 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
-38 Bytes
Binary file not shown.

rainbow.iml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
</sourceRoots>
1616
</configuration>
1717
</facet>
18+
<facet type="Spring" name="Spring">
19+
<configuration />
20+
</facet>
1821
</component>
19-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
22+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
2023
<output url="file://$MODULE_DIR$/target/classes" />
2124
<output-test url="file://$MODULE_DIR$/target/test-classes" />
2225
<content url="file://$MODULE_DIR$">

src/main/java/controller/LoginController.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,71 @@
22

33
import domain.UserInfo;
44
import org.apache.log4j.Logger;
5+
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.stereotype.Controller;
67
import org.springframework.ui.ModelMap;
7-
import org.springframework.web.bind.annotation.ModelAttribute;
88
import org.springframework.web.bind.annotation.RequestMapping;
99
import org.springframework.web.bind.annotation.RequestMethod;
1010
import org.springframework.web.bind.annotation.RequestParam;
11-
import org.springframework.web.servlet.ModelAndView;
11+
import org.springframework.web.bind.annotation.SessionAttributes;
12+
import service.LoginService;
13+
14+
import javax.servlet.http.HttpSession;
1215

1316
/**
1417
* Created by pengfei on 2017/9/22.
1518
*/
1619
@Controller
20+
@SessionAttributes("user")
1721
public class LoginController {
1822

19-
private final static Logger logger=Logger.getLogger(LoginController.class);
23+
private final static Logger logger = Logger.getLogger(LoginController.class);
24+
25+
@Autowired
26+
private LoginService loginService;
2027

21-
@RequestMapping(value = "/login", method = RequestMethod.GET)
22-
public String get(){
28+
@RequestMapping(value = "/homePage")
29+
public String get(HttpSession session) {
2330
logger.info("Inside login get method");
24-
return "home";
31+
32+
UserInfo currentUser = (UserInfo) session.getAttribute("user");
33+
logger.info("Current User:" + currentUser.getName());
34+
35+
return "homePage";
2536
}
2637

2738
//public String login(@RequestParam("name") String name, String password, ModelMap model){
2839
//public String login(String name, String password, ModelMap model){
2940

30-
@RequestMapping(value = "/loginHere",method=RequestMethod.POST)
31-
public String login(@RequestParam("name") String name, String password, ModelMap model){
41+
@RequestMapping(value = "/loginHere", method = RequestMethod.POST)
42+
public String login(@RequestParam("name") String name, String password, ModelMap model) {
3243
logger.info("Login controller begin service");
3344

34-
model.addAttribute("password",password);
35-
model.addAttribute("name",name);
45+
UserInfo user = new UserInfo();
46+
user.setName(name);
47+
user.setPassword(password);
3648

37-
if(password==null)
38-
throw new RuntimeException("Password should not be null!");
49+
model.addAttribute("bean", user);
3950

40-
logger.info("Login controller end service!");
51+
if (loginService.checkUserAccess(name, password)) {
52+
logger.info("Login controller end service!");
4153

42-
return "homePage";
54+
user.setPassword("");
55+
model.addAttribute("user", user);
56+
57+
return "redirect:homePage";
58+
} else {
59+
return "login";
60+
}
4361
}
4462

45-
@RequestMapping(value="/toLoginPage",method = RequestMethod.GET)
46-
public String redirect(){
63+
@RequestMapping(value = "/toLoginPage", method = RequestMethod.GET)
64+
public String redirect() {
4765
return "redirect:login";
4866
}
4967

50-
@RequestMapping(value = "/visitStaticPage",method = RequestMethod.GET)
51-
public String visitStaticPage(){
68+
@RequestMapping(value = "/visitStaticPage", method = RequestMethod.GET)
69+
public String visitStaticPage() {
5270

5371
return "redirect:/pages/static.html";
5472
}

src/main/java/dao/UserDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public interface UserDao {
1212

1313
public Object findUser(int userID);
1414

15+
public Object findUser(String userName);
16+
1517
public List findAllUser();
1618
}

src/main/java/dao/UserDaoImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dao;
22

3-
import com.alibaba.fastjson.JSON;
43
import domain.UserInfo;
54
import org.mybatis.spring.support.SqlSessionDaoSupport;
65
import org.springframework.stereotype.Component;
@@ -32,6 +31,12 @@ public Object findUser(int userID) {
3231

3332
}
3433

34+
public Object findUser(String userName) {
35+
UserInfo user = this.getSqlSession().selectOne("USER.findUserByName", userName);
36+
return user;
37+
38+
}
39+
3540
public List findAllUser() {
3641
int cnt = this.getSqlSession().selectOne("USER.count");
3742

0 commit comments

Comments
 (0)