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

src/main/java/domain/UserInfo.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class UserInfo {
1010
private String comment;
1111
private String password;
1212
private String email;
13+
private String create;
14+
private String update;
1315

1416
public UserInfo() {
1517

@@ -69,4 +71,21 @@ public void setEmail(String email) {
6971
}
7072

7173

74+
public String getCreate() {
75+
return create;
76+
}
77+
78+
public void setCreate(String create) {
79+
this.create = create;
80+
}
81+
82+
public String getUpdate() {
83+
return update;
84+
}
85+
86+
public void setUpdate(String update) {
87+
this.update = update;
88+
}
89+
90+
7291
}

src/main/java/service/IUserService.java renamed to src/main/java/service/LoginService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
/**
88
* Created by pengfei on 2017/9/12.
99
*/
10-
public interface IUserService {
10+
public interface LoginService {
1111

1212
public void addUser(UserInfo info);
1313

1414
public void deleteUser(UserInfo info);
1515

1616
public UserInfo queryUser(UserInfo info);
17+
18+
public boolean checkUserAccess(String userName, String pwd);
1719
}

src/main/java/service/UserServiceImpl.java renamed to src/main/java/service/LoginServiceImpl.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
/**
1212
* Created by pengfei on 2017/9/12.
1313
*/
14-
@Service("newUserService")
15-
public class UserServiceImpl implements IUserService {
14+
15+
@Service("LoginService")
16+
public class LoginServiceImpl implements LoginService {
1617

1718
@Autowired
1819
private RedisCache redisCache;
@@ -48,4 +49,14 @@ public UserInfo queryUser(UserInfo info) {
4849
System.out.println("DB got");
4950
return user;
5051
}
52+
53+
public boolean checkUserAccess(String userName, String pwd){
54+
UserInfo user=(UserInfo) userDao.findUser(userName);
55+
56+
if (user ==null ||!user.getPassword().equals(pwd)){
57+
return false;
58+
}else{
59+
return true;
60+
}
61+
}
5162
}

src/main/java/service/UserService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Created by pengfei on 2017/9/2.
1212
*/
13+
@Service("UserService")
1314
public class UserService {
1415

1516
private UserDao userDao;

src/main/resources/mybatis/application.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
</tx:advice>
2929

3030
<aop:config>
31-
<aop:pointcut id="createOperation"
32-
expression="execution(* dao.StudentDaoImpl.declarativeTxTest(..))"/>
31+
<aop:pointcut id="createOperation" expression="execution(* dao.StudentDaoImpl.declarativeTxTest(..))"/>
3332

3433
<aop:advisor advice-ref="txAdvice" pointcut-ref="createOperation"/>
3534
</aop:config>
@@ -38,7 +37,7 @@
3837
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
3938
<property name="url" value="jdbc:mysql://localhost:3306/rainbow"></property>
4039
<property name="username" value="root"></property>
41-
<property name="password" value="mysql"></property>
40+
<property name="password" value="jack_bai"></property>
4241
</bean>
4342

4443
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
@@ -51,9 +50,6 @@
5150
</bean>
5251

5352
<bean id="userDAO" class="dao.UserDaoImpl" parent="abstractDAO"/>
54-
<bean id="userService" class="service.UserService">
55-
<property name="userDao" ref="userDAO"></property>
56-
</bean>
5753

5854
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
5955
<property name="maxIdle" value="25"/>
@@ -65,7 +61,7 @@
6561

6662
<bean id="pool" class="redis.clients.jedis.JedisPool">
6763
<constructor-arg index="0" ref="poolConfig"/>
68-
<constructor-arg index="1" value="localhost"/>
64+
<constructor-arg index="1" value="10.45.4.45"/>
6965
<constructor-arg index="2" value="6379"/>
7066
<constructor-arg index="3" value="2000"/>
7167
</bean>

src/main/resources/mybatis/user-mapper.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
select * from userinfo where id= #{id}
2121
</select>
2222

23+
<select id="findUserByName" resultType="domain.UserInfo" >
24+
select * from userinfo where name = #{name}
25+
</select>
26+
2327
<insert id="insertUser" parameterType="domain.UserInfo" useGeneratedKeys="true" keyProperty="id">
2428
insert into userinfo (name,salary,comment) values (#{name},#{salary},#{comment})
2529
</insert>

0 commit comments

Comments
 (0)