弹幕下载

master
潘啟华 6 years ago
parent a024c69641
commit 80f7b5dde6
  1. 80
      db/src/main/java/db/model/bilibili/WordModel.java
  2. 48
      sql/new.sql
  3. 7
      web/src/main/java/web/controller/BaseController.java
  4. 5
      web/src/main/java/web/controller/BiliController.java
  5. 5
      web/src/main/java/web/controller/TableController.java
  6. 11
      web/src/main/java/web/controller/WordController.java
  7. 2
      web/src/main/java/web/service/BaseService.java
  8. 4
      web/src/main/resources/config.properties
  9. 2
      web/src/main/webapp/WEB-INF/jsp/menu.jsp
  10. 6
      web/src/main/webapp/WEB-INF/jsp/test.jsp
  11. 27
      web/src/test/java/spring/SpringMVCTest.java

@ -0,0 +1,80 @@
package db.model.bilibili;
import db.annotation.Aliyun;
import db.model.AbstractModel;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Aliyun
@Entity
@Table(name = "word")
public class WordModel extends AbstractModel {
private int id;
private String courseName;
private String kana;
private String chinese;
@Id
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "course_name", nullable = false, length = 32)
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
@Basic
@Column(name = "kana", nullable = false, length = 32)
public String getKana() {
return kana;
}
public void setKana(String kana) {
this.kana = kana;
}
@Basic
@Column(name = "chinese", nullable = true, length = 32)
public String getChinese() {
return chinese;
}
public void setChinese(String chinese) {
this.chinese = chinese;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WordModel wordModel = (WordModel) o;
return id == wordModel.id &&
Objects.equals(courseName, wordModel.courseName) &&
Objects.equals(kana, wordModel.kana) &&
Objects.equals(chinese, wordModel.chinese);
}
@Override
public int hashCode() {
return Objects.hash(id, courseName, kana, chinese);
}
@Override
public Serializable primaryKey() {
return getId();
}
}

@ -1,20 +1,36 @@
--
#菜单
create table menu
(
id int auto_increment--
primary key,
href varchar(32) not null,--
menu_name varchar(10) not null,--
icon varchar(20) null,--
parent_id int not null,--id
menu_level int not null,--
sort int not null,--
constraint menu_href_uindex
unique (href)
id int auto_increment,#自增主键
href varchar(32) not null,#菜单超链接
menu_name varchar(10) not null,#菜单名
icon varchar(20) null,#菜单图标
parent_id int not null,#父菜单id
menu_level int not null,#菜单树深度
sort int not null,#排序
constraint menu_href_uindex unique (href)
)
engine=InnoDB
;
--thrift服务器表
create
alter table menu add primary key(id);
#thrift服务器表
create table thrift
(
ip varchar(15),
port int not null,
timeout int default 3000
);
ALTER TABLE thrift ADD PRIMARY KEY (ip, port );
#数据源表
create table datasource
(
db_id varchar(32) not null,
hostname varchar(32) not null,
db_port int(5) not null,
username varchar(10) not null,
db_password varchar(10) not null,
db_name varchar(10) not null,
annotation varchar(32) not null,
db_desc varchar(20) null
)
;
ALTER TABLE datasource ADD PRIMARY KEY (db_id);

@ -51,6 +51,7 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten
}
}
@RequestMapping(value = "C",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.POST)
public JsonResult save(T model){
JsonResult result=new JsonResult();
result.setAction(DBAction.C);
@ -64,7 +65,7 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten
return result;
}
@RequestMapping(value = "C",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.GET)
@RequestMapping(value = "R",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.GET)
public JsonResult get(T model){
JsonResult<T> result=new JsonResult();
result.setAction(DBAction.R);
@ -79,7 +80,7 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten
}
@ResponseBody
@RequestMapping(value = "batch_C",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.GET)
@RequestMapping(value = "batch_R",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.GET)
public JsonResult get(A queryCommand, @RequestParam(defaultValue = "0") int firstResult,@RequestParam(defaultValue = "0") int maxResults){
JsonResult<List> result=new JsonResult();
result.setAction(DBAction.R);
@ -93,6 +94,7 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten
return result;
}
@RequestMapping(value = "U",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.POST)
public JsonResult update(T model){
JsonResult result=new JsonResult();
result.setAction(DBAction.U);
@ -106,6 +108,7 @@ public abstract class BaseController<T extends AbstractModel,A extends T,E exten
return result;
}
@RequestMapping(value = "D",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = RequestMethod.POST)
public JsonResult delete(T model){
JsonResult result=new JsonResult();
result.setAction(DBAction.D);

@ -1,13 +1,8 @@
package web.controller;
import db.form.DBAction;
import db.model.AbstractModel;
import web.service.BiliService;
public abstract class BiliController<T extends AbstractModel> extends BaseController<T,T,BiliService>{
@Override
protected boolean checkAction(DBAction action) {
return false;
}
}

@ -56,11 +56,6 @@ public abstract class TableController<T extends AbstractModel,A extends T,E exte
protected abstract B getNewTable();
@Override
protected boolean checkAction(DBAction action) {
return false;
}
protected List find(A command, Integer firstResult,Integer maxResults){
return service.find(getDetachedCriteria(command), firstResult, maxResults);
}

@ -0,0 +1,11 @@
package web.controller;
import db.model.bilibili.WordModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/word")
public class WordController extends BiliController<WordModel> {
}

@ -49,7 +49,7 @@ public abstract class BaseService{
}
public final <T extends AbstractModel> void delete(T command) throws DataAccessException{
getHibernateTemplate().delete(command);
getHibernateTemplate().delete(get(command));
}
public final List find(DetachedCriteria criteria, int firstResult,int maxResults) throws DataAccessException{

@ -1,7 +1,7 @@
#hibernate\u914D\u7F6E
db_url=jdbc:mysql://mysql.sukura.top:8635/rootdb?serverTimezone=UTC&useSSL=false
db_url=jdbc:mysql://sukura.top:3306/bilibili?serverTimezone=UTC&useSSL=false
db_username=sukura
db_password=Luffy9412!
db_password=12345678
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver

@ -115,7 +115,7 @@
}
$(function () {
$.get('/menu/batch_C',function(json){
$.get('/menu/batch_R',function(json){
addMenu(json['data']);
});

@ -22,14 +22,14 @@
$(function () {
$("#demo").tmpl([{type: 'primary'}, {type: 'secondary'}, {type: 'success'}, {type: 'danger'}, {type: 'warning'}, {type: 'info'}, {type: 'light'}, {type: 'dark'}]).appendTo('#div_demo');
console.info("${spring:mvcUrl('MC#get#0').build()}");
});
</script>
</head>
<body>
<div id="div_demo" hidden>
<svg aria-hidden="true" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-w-16 fa-spin fa-lg"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z" class=""></path></svg>
<div id="div_demo">
<%--<svg aria-hidden="true" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-w-16 fa-spin fa-lg"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z" class=""></path></svg>--%>
</div>
</body>

@ -6,6 +6,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -18,6 +19,8 @@ import org.springframework.web.context.WebApplicationContext;
import web.config.AppConfig;
import web.config.SpringConfig;
import javax.transaction.Transactional;
//让测试运行于SpringMVC
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitWebConfig
@ -44,10 +47,32 @@ public class SpringMVCTest {
@Test
public void get() throws Exception {
ResultActions resultActions=mockMvc.perform(MockMvcRequestBuilders.get("/menu/batch_C"));
ResultActions resultActions=mockMvc.perform(MockMvcRequestBuilders.get("/menu/batch_R"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
@Transactional
public void save() throws Exception {
ResultActions resultActions=mockMvc.perform(MockMvcRequestBuilders.post("/word/C").param("courseName","123").param("kana","456").param("chinese","789"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
@Transactional
@Rollback(false)
public void update() throws Exception{
ResultActions resultActions=mockMvc.perform(MockMvcRequestBuilders.post("/word/U").param("id","1").param("courseName","123").param("kana","666").param("chinese","666"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
@Test
@Transactional
@Rollback(false)
public void delete() throws Exception{
ResultActions resultActions=mockMvc.perform(MockMvcRequestBuilders.post("/word/D").param("id","1"));
resultActions.andDo(MockMvcResultHandlers.print()).andReturn();
}
}

Loading…
Cancel
Save