4.0.0
login
login
1.0-SNAPSHOT
junit
junit
4.11
test
org.slf4j
slf4j-api
1.7.12
ch.qos.logback
logback-core
1.1.1
ch.qos.logback
logback-classic
1.1.1
mysql
mysql-connector-java
5.1.35
runtime
c3p0
c3p0
0.9.1.2
org.mybatis
mybatis
3.3.0
org.mybatis
mybatis-spring
1.2.3
taglibs
standard
1.1.2
jstl
jstl
1.2
com.fasterxml.jackson.core
jackson-databind
2.5.4
javax.servlet
javax.servlet-api
3.1.0
org.springframework
spring-core
4.2.0.RELEASE
org.springframework
spring-beans
4.2.0.RELEASE
org.springframework
spring-context
4.2.0.RELEASE
org.springframework
spring-jdbc
4.2.0.RELEASE
org.springframework
spring-tx
4.2.0.RELEASE
org.springframework
spring-web
4.2.0.RELEASE
org.springframework
spring-webmvc
4.2.0.RELEASE
org.springframework
spring-test
4.2.0.RELEASE
log4j
log4j
1.2.16
src/main/java
**/*.xml
false
② web.xml
log4jConfigLocation
classpath:log4j.properties
org.springframework.web.util.Log4jConfigListener
login
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
login
/
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/
③ applicationContext.xml
③ springmvc.xml
④ mybatis.xml
⑤ db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456
⑥ log4j.properties
log4j.rootLogger=INFO,Console,File
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n
#普通文件日志
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.File=logs/ssm.log
log4j.appender.File.MaxFileSize=10MB
#输出日志,如果换成DEBUG表示输出DEBUG以上级别日志
log4j.appender.File.Threshold=ALL
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n
二、java类
① 实体类(model.java)
package com.hehui.model;
/**
* Created by Administrator on 2019/6/12 0012.
*/
public class User {
private int id;
private String username;
private String password;
private String phone;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", phone='" + phone + '\'' +
'}';
}
}
② 持久层(Usermapper.java)
package com.hehui.dao;
import com.hehui.model.User;
import org.apache.ibatis.annotations.Param;
/**
* Created by Administrator on 2019/6/12 0012.
*/
public interface UserMapper {
//注册
public int regist(User user);
//登录
public User login(@Param("username") String username,@Param("password") String password);
}
UserMapper.xml
insert into user (username,password,phone) values(#{username},#{password},#{phone})
③ UserService.java
public interface UserService {
public int regist(User user);
public User login(String username,String password);
}
UserServiceImp.java
@Service
public class UserServiceImp implements UserService{
@Autowired(required = false)
UserMapper userMapper;
public int regist(User user) {
return userMapper.regist(user);
}
public User login(String username, String password) {
return userMapper.login(username,password);
}
}
④控制层(UserController.java)
@Controller
public class UserController {
@Autowired
UserService userService;
@RequestMapping("/regist")
public String regist(@RequestParam(value = "username",required = false) String username, @RequestParam(value = "password",required = false) String password, @RequestParam(value = "repassword",required = false)String repassword,@RequestParam(value = "phone",required = false) String phone, Model model) {
if (password.equals(repassword)) {
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setPhone(phone);
System.out.println(user);
if (userService.regist(user) > 0) {
model.addAttribute("msg", "注册成功");
return "login";
} else {
model.addAttribute("msg", "注册失败");
return "regist";
}
} else {
model.addAttribute("msg", "密码不一致");
return "regist";
}
}
@RequestMapping("/login")
public String loign(@RequestParam(value = "username",required = false) String username,@RequestParam(value = "password",required = false) String password,Model model){
User user = userService.login(username,password);
System.out.println(username);
System.out.println(password);
System.out.println("+++++++++++"+user);
if (user != null){
model.addAttribute("msg","登录成功");
return "success";
}else {
model.addAttribute("msg","登录失败");
return "login";
}
}
}
三、页面
① regist.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
%>
注册
注册信息
② login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
%>
登录
登录
③ index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
$Title$
css(就做了个居中)
.box{
text-align: center;
width: 500px;
height: 400px;
position:fixed;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}