添加JPA支持

This commit is contained in:
Saturneric 2020-01-29 22:51:39 +08:00
parent 37dfe248e3
commit bec6fa41ad
12 changed files with 231 additions and 31 deletions

View File

@ -54,11 +54,18 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,27 @@
package com.codesdream.ase.configure;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfigure {
private String name = "全员育人";
private String englishName = "All Staff Education";
private String version = "0.0.1";
private String organization = "码梦工坊";
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public String getEnglishName() {
return englishName;
}
public String getOrganization() {
return organization;
}
}

View File

@ -0,0 +1,20 @@
package com.codesdream.ase.configure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class GlobalConfigure {
@Resource
AppConfigure appConfigure;
public AppConfigure getAppConfigure() {
return appConfigure;
}
}

View File

@ -1,14 +1,22 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.configure.GlobalConfigure;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.security.Principal;
@Controller
public class ASEController {
@Resource
GlobalConfigure globalConfigure;
@RequestMapping(value = "/")
public String printIndex(){
public String printIndex(Model model, Principal principal){
model.addAttribute("username",principal.getName());
return "index";
}
}

View File

@ -0,0 +1,94 @@
package com.codesdream.ase.model;
import javax.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "user_permit")
public class Permit {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String description;
private String url;
private int pid;
public Permit(){
}
public Permit(String name, String description, String url, int pid) {
this.name = name;
this.description = description;
this.url = url;
this.pid = pid;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getUrl() {
return url;
}
public int getPid() {
return pid;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setUrl(String url) {
this.url = url;
}
public void setPid(int pid) {
this.pid = pid;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Permit permit = (Permit) o;
return id == permit.id &&
pid == permit.pid &&
Objects.equals(name, permit.name) &&
Objects.equals(description, permit.description) &&
Objects.equals(url, permit.url);
}
@Override
public int hashCode() {
return Objects.hash(id, name, description, url, pid);
}
@Override
public String toString() {
return "Permit{" +
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", url='" + url + '\'' +
", pid=" + pid +
'}';
}
}

View File

@ -0,0 +1,12 @@
package com.codesdream.ase.repository;
import com.codesdream.ase.model.Permit;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface PermitRepository extends CrudRepository<Permit, Long> {
}

View File

@ -0,0 +1,9 @@
package com.codesdream.ase.service;
import com.codesdream.ase.model.Permit;
import java.util.List;
public interface IPermitService {
List<Permit> findAll();
}

View File

@ -0,0 +1,18 @@
package com.codesdream.ase.service;
import com.codesdream.ase.model.Permit;
import com.codesdream.ase.repository.PermitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
public class PermitService implements IPermitService {
@Autowired
PermitRepository permitRepository;
@Override
public List<Permit> findAll() {
return (List<Permit>) permitRepository.findAll();
}
}

View File

@ -0,0 +1,5 @@
package com.codesdream.ase.service;
public interface UserService {
}

View File

@ -6,4 +6,12 @@ spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.security.user.name=user
spring.security.user.password=123
spring.security.user.password=123
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=Hy009048

View File

@ -8,7 +8,7 @@
<div th:fragment="content">
<div class="wrapper">
<div th:include="layout::main-header"></div>
<div th:include="layout::side-bar"></div>
<div th:include="layout::side-bar(username=${username})"></div>
<div class="main-panel">
<div class="content">
@ -529,7 +529,6 @@
</div>
<div th:include="layout::footer"></div>
</div>
<div th:include="layout::custom-template"></div>
</div>
</div>

View File

@ -425,7 +425,7 @@
<!-- End Navbar -->
</div>
</div>
<div th:fragment="side-bar">
<div th:fragment="side-bar(username)">
<!-- Sidebar -->
<div class="sidebar sidebar-style-2">
<div class="sidebar-wrapper scrollbar scrollbar-inner">
@ -437,7 +437,8 @@
<div class="info">
<a data-toggle="collapse" href="#collapseExample" aria-expanded="true">
<span>
Hizrian
<!--/*@thymesVar id="username" type="string"*/-->
<span th:text="${username}" ></span>
<span class="user-level">Administrator</span>
<span class="caret"></span>
</span>
@ -448,17 +449,12 @@
<ul class="nav">
<li>
<a href="#profile">
<span class="link-collapse">My Profile</span>
</a>
</li>
<li>
<a href="#edit">
<span class="link-collapse">Edit Profile</span>
<span class="link-collapse">账号设置</span>
</a>
</li>
<li>
<a href="#settings">
<span class="link-collapse">Settings</span>
<span class="link-collapse">系统设置</span>
</a>
</li>
</ul>
@ -469,19 +465,19 @@
<li class="nav-item active">
<a data-toggle="collapse" href="#dashboard" class="collapsed" aria-expanded="false">
<i class="fas fa-home"></i>
<p>Dashboard</p>
<p>概览</p>
<span class="caret"></span>
</a>
<div class="collapse" id="dashboard">
<ul class="nav nav-collapse">
<li>
<a href="../demo1/index.html">
<span class="sub-item">Dashboard 1</span>
<span class="sub-item">总体概览</span>
</a>
</li>
<li>
<a href="../demo2/index.html">
<span class="sub-item">Dashboard 2</span>
<span class="sub-item">系统概览</span>
</a>
</li>
</ul>
@ -491,12 +487,12 @@
<span class="sidebar-mini-icon">
<i class="fa fa-ellipsis-h"></i>
</span>
<h4 class="text-section">Components</h4>
<h4 class="text-section">主要功能</h4>
</li>
<li class="nav-item">
<a data-toggle="collapse" href="#base">
<i class="fas fa-layer-group"></i>
<p>Base</p>
<p>活动计划</p>
<span class="caret"></span>
</a>
<div class="collapse" id="base">
@ -557,7 +553,7 @@
<li class="nav-item">
<a data-toggle="collapse" href="#sidebarLayouts">
<i class="fas fa-th-list"></i>
<p>Sidebar Layouts</p>
<p>创建活动</p>
<span class="caret"></span>
</a>
<div class="collapse" id="sidebarLayouts">
@ -593,7 +589,7 @@
<li class="nav-item">
<a data-toggle="collapse" href="#forms">
<i class="fas fa-pen-square"></i>
<p>Forms</p>
<p>活动列表</p>
<span class="caret"></span>
</a>
<div class="collapse" id="forms">
@ -609,7 +605,7 @@
<li class="nav-item">
<a data-toggle="collapse" href="#tables">
<i class="fas fa-table"></i>
<p>Tables</p>
<p>活动报告</p>
<span class="caret"></span>
</a>
<div class="collapse" id="tables">
@ -630,7 +626,7 @@
<li class="nav-item">
<a data-toggle="collapse" href="#maps">
<i class="fas fa-map-marker-alt"></i>
<p>Maps</p>
<p>请假</p>
<span class="caret"></span>
</a>
<div class="collapse" id="maps">
@ -646,7 +642,7 @@
<li class="nav-item">
<a data-toggle="collapse" href="#charts">
<i class="far fa-chart-bar"></i>
<p>Charts</p>
<p>信箱</p>
<span class="caret"></span>
</a>
<div class="collapse" id="charts">
@ -667,14 +663,14 @@
<li class="nav-item">
<a href="widgets.html">
<i class="fas fa-desktop"></i>
<p>Widgets</p>
<p>权限管理</p>
<span class="badge badge-success">4</span>
</a>
</li>
<li class="nav-item">
<a data-toggle="collapse" href="#submenu">
<i class="fas fa-bars"></i>
<p>Menu Levels</p>
<p>成绩</p>
<span class="caret"></span>
</a>
<div class="collapse" id="submenu">
@ -722,9 +718,6 @@
</ul>
</div>
</li>
<li class="mx-4 mt-2">
<a href="#" class="btn btn-primary btn-block"><span class="btn-label mr-2"> <i class="fa fa-heart"></i> </span>Buy Pro</a>
</li>
</ul>
</div>
</div>
@ -811,17 +804,17 @@
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">
ThemeKita
关于
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
Help
帮助
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
Licenses
许可证
</a>
</li>
</ul>