authorization

master
bseayin 2019-12-28 21:42:08 +08:00
parent 506ab746f7
commit 0b5542b084
25 changed files with 158 additions and 28 deletions

View File

@ -2,6 +2,7 @@ package com.zz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* --run as application mainspringboot
@ -11,6 +12,7 @@ SpringBoot 自带了 tomcat 运行这个main方法 的时候,会同时启
*/
@SpringBootApplication
@EnableScheduling
@ServletComponentScan
public class App {
public static void main(String[] args) {

View File

@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -22,7 +23,13 @@ public class UserController {
@Resource
UserService userService;
@PostMapping("add")
public User add(User user){
System.out.println("add*********");
System.out.println(user);
return userService.add(user);
}
@RequestMapping("login")
public Map login(HttpServletRequest request){
String name=request.getParameter("name");

View File

@ -1,45 +1,92 @@
package com.zz.entity;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.annotations.Proxy;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.HashSet;
import java.util.Set;
@Entity
public class User {
@Table(name="T_USER")
@Proxy(lazy = false)
public class User implements Serializable{
final static long serialVersionUID=23424L;
@Id
@Column(length = 50)
private String id;
private String name;
private String pwd;
private String sex;
private int age;
//用户名
private String username;
private String passwd;
//是否有效 1有效 0锁定
private String status;
//创建时间
private Date createTime;
//使用 @ManyToMany 注解来映射多对多关联关系
//使用 @JoinTable 来映射中间表
//1. name 指向中间表的名字
//2. joinColumns 映射当前类所在的表在中间表中的外键
//2.1 name 指定外键列的列名
//2.2 referencedColumnName 指定外键列关联当前表的哪一列
//3. inverseJoinColumns 映射关联的类所在中间表的外键
// @ManyToMany注释表示Teacher是多对多关系的一端。
// @JoinTable描述了多对多关系的数据表关系。name属性指定中间表名称joinColumns定义中间表与Teacher表的外键关系。
// 中间表Teacher_Student的Teacher_ID列是Teacher表的主键列对应的外键列inverseJoinColumns属性定义了中间表与另外一端(Student)的外键关系。
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
@JoinTable(name = "T_USER_ROLE", joinColumns = { @JoinColumn(name = "u_id") },
inverseJoinColumns = {
@JoinColumn(name = "r_id") })
private Set<Role> roles = new HashSet<Role>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
public String getUsername() {
return username;
}
public void setName(String name) {
this.name = name;
public void setUsername(String username) {
this.username = username;
}
public String getPwd() {
return pwd;
public String getPasswd() {
return passwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getSex() {
return sex;
public String getStatus() {
return status;
}
public void setSex(String sex) {
this.sex = sex;
public void setStatus(String status) {
this.status = status;
}
public int getAge() {
return age;
public Date getCreateTime() {
return createTime;
}
public void setAge(int age) {
this.age = age;
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}

View File

@ -7,7 +7,7 @@ import com.zz.entity.User;
public interface UserRepository extends JpaRepository<User,String>{
public User findByNameAndPwd(String name,String pwd);
public User findByUsernameAndPasswd(String name,String pwd);

View File

@ -15,9 +15,12 @@ public class UserService {
@Resource
UserRepository userRepository;
public User add(User user){
return userRepository.save(user);
}
public User findByNameAndPwd(String name,String pwd){
return userRepository.findByNameAndPwd(name, pwd);
return userRepository.findByUsernameAndPasswd(name, pwd);
};

View File

@ -14,5 +14,10 @@
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.8" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.55" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.guava:guava:19.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.11.3" level="project" />
</component>
</module>

View File

@ -29,6 +29,34 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
</dependencies>

View File

@ -10,6 +10,7 @@ public class Test {
Parent a=new ChildA();
Parent b=new ChildB();
printName(b);
}

View File

@ -12,6 +12,7 @@ public class Task {
public void finishtask(){
//相当于this.total=this.total-1
this.total--;
this.runtime++;
System.out.println("total="+total+"****runtime="+runtime);
}

View File

@ -0,0 +1,35 @@
package com.zz.staticdemo;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @Description:
* @Author: Bsea
* @CreateDate: 2019/12/28
*/
public class ChildTest {
Child child;
@Before
public void init(){
System.out.println("Before 代码每次先执行");
child=new Child();
}
@Test
public void t1(){
//assert 断言 (条件真假)
assert (child.getAge()==18);
}
@Test
public void t2(){
assert (child.add(5,0)==16);
}
}

View File

@ -31,6 +31,7 @@
<module>SpringBootRedis</module>
<module>SpringBootMybatisRedisCache</module>
<module>SpringBootOrder</module>
<module>SpringBootAOP</module>
</modules>
<repositories>