本文共 5785 字,大约阅读时间需要 19 分钟。
package com.example.demo;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;/** * 实体类 * @author linziyu * */@Entity(name="table_user")public class UserEntity { @Id @GeneratedValue private Long id; private String username; private String password; public Long getId() { return id; } public void setId(Long 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; }}
package com.example.demo;import org.springframework.data.repository.CrudRepository;import org.springframework.stereotype.Repository;@Repositorypublic interface UserDao extends CrudRepository{ public UserEntity findByUsernameAndPassword(String username,String password);}
package com.example.demo;import javax.servlet.http.HttpServletRequest;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/front/*")public class IndexController { @Autowired private UserDao userDao; @RequestMapping("/index") public String index() { return "index"; } @RequestMapping("/register") public String register(){ return "register"; } @RequestMapping("/addregister") public String register(HttpServletRequest request){ String username = request.getParameter("username"); String password = request.getParameter("password"); String password2 = request.getParameter("password2"); if (password.equals(password2)){ UserEntity userEntity = new UserEntity(); userEntity.setUsername(username); userEntity.setPassword(password); userDao.save(userEntity); return "index"; }else { return "register"; } } @RequestMapping("/login") public String login(){ return "login"; } @RequestMapping("/addlogin") public String login(HttpServletRequest request){ String username = request.getParameter("username"); String password = request.getParameter("password"); UserEntity userEntity = userDao.findByUsernameAndPassword(username,password); String str = ""; if (userEntity !=null){ str = "index"; }else { str = "login"; } return str; } }
server.port=8082spring.datasource.url = jdbc:mysql://localhost:3306/flask1spring.datasource.username = rootspring.datasource.password = 123spring.datasource.driverClassName = com.mysql.jdbc.Driver# Specify the DBMSspring.jpa.database = MYSQL# Show or not log for each sql queryspring.jpa.show-sql = true# Hibernate ddl auto (create, create-drop, update)spring.jpa.hibernate.ddl-auto = update# Naming strategy\uFF01spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy# stripped before adding them to the entity manager)spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect#\u5F00\u53D1\u65F6\u5EFA\u8BAE\u5173\u95ED\u7F13\u5B58spring.thymeleaf.cache=falsespring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=utf-8spring.thymeleaf.content-type=text/html
4.0.0 com.example login 0.0.1-SNAPSHOT jar login Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.7.RELEASE UTF-8 UTF-8 1.7 org.springframework.boot spring-boot-devtools true true org.springframework.boot spring-boot-starter mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-maven-plugin
Title
Insert title here
转载地址:http://wxcqb.baihongyu.com/