Panda學習筆記4——多表功能開發(2)後端介面開發
進行功能性的開發,主要涉及到:
序號 | 型別 | 名稱 |
---|---|---|
1 | DTO | CodeRulesTest1Header |
2 | DTO | CodeRulesTest1Line |
3 | Mapper | CodeRulesTest1HeaderMapper |
4 | Mapper | CodeRulesTest1LineMapper |
5 | SysCodeRuleTest1Cache | |
6 | Service | ICodeRulesTest1HeaderService |
7 | Service | ICodeRulesTest1LineService |
8 | ServiceImpl | CodeRulesTest1HeaderServiceImpl |
9 | ServiceImpl | CodeRulesTest1LineServiceImpl |
10 | Controller | CodeRulesTest1HeaderController |
11 | Controller | CodeRulesTest1LineController |
12 | Screen | code/rule/test1/codeRulesTest1.screen |
13 | Screen | code/rule/test1/codeRulesTest1Edit.screen |
編寫DTO
完整示例如下:
//擴充套件欄位註解
@ExtensionAttribute(disable=true)
//對映資料庫表
@Table(name = "sys_code_rules_test1_header")
public class CodeRulesTest1Header extends BaseDTO{
//每一個欄位都需要新增其對應的靜態屬性欄位
public static final String FIELD_HEADER_ID="headerId";
public static final String FIELD_RULE_CODE="ruleCode";
public static final String FIELD_RULE_NAME="ruleName";
public static final String FIELD_DESCRIPTION="description";
public static final String FIELD_ENABLE_FLAG="enableFlag";
//主鍵註解
@Id
//主鍵自增長註解,對於自增長、序列(SEQUENCE)型別的主鍵,需要添加註解@GeneratedValue
@GeneratedValue
@Where
//數字型別主鍵的欄位型別統一採用 Long
private Long headerId; //頭ID
@NotEmpty
@Length(max = 50)
@Where
@OrderBy("ASC")
private String ruleCode; //編碼規則CODE
@Length(max = 50)
@Where
private String ruleName; //名稱
@Length(max = 255)
private String description; //描述
@Length(max = 5)
private String enableFlag; //啟用標誌
//非資料庫欄位需要新增@Transient
@Transient
//與CodeRulesTest1Line關聯起來
@Children
private List<CodeRulesTest1Line> lines;
public Long getHeaderId() {
return headerId;
}
public void setHeaderId(Long headerId) {
this.headerId = headerId;
}
public String getRuleCode() {
return ruleCode;
}
public void setRuleCode(String ruleCode) {
this.ruleCode = ruleCode;
}
public String getRuleName() {
return ruleName;
}
public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getEnableFlag() {
return enableFlag;
}
public void setEnableFlag(String enableFlag) {
this.enableFlag = enableFlag;
}
public List<CodeRulesTest1Line> getLines() {
return lines;
}
public void setLines(List<CodeRulesTest1Line> lines) {
this.lines = lines;
}
}
//擴充套件欄位註解
@ExtensionAttribute(disable=true)
//對映資料庫表
@Table(name = "sys_code_rules_test1_line")
public class CodeRulesTest1Line extends BaseDTO{
public static final String FIELD_LINE_ID = "lineId";
public static final String FIELD_HEADER_ID = "headerId";
public static final String FIELD_FILED_TYPE = "filedType";
public static final String FIELD_FILED_VALUE = "filedValue";
public static final String FIELD_FIELD_SEQUENCE = "fieldSequence";
public static final String FIELD_DATE_MASK = "dateMask";
public static final String FIELD_SEQ_LENGTH = "seqLength";
public static final String FIELD_START_VALUE = "startValue";
public static final String FIELD_CURRENT_VALUE = "currentValue";
public static final String FIELD_REST_FREQUENCY = "resetFrequency";
public static final String FIELD_REST_DATE = "resetDate";
public static final String FIELD_STEP_NUMBER = "stepNumber";
//主鍵註解
@Id
//主鍵自增長註解,對於自增長、序列(SEQUENCE)型別的主鍵,需要添加註解@GeneratedValue
@GeneratedValue
//數字型別主鍵的欄位型別統一採用 Long
private Long lineId; //行ID
@Where
private Long headerId; //編碼頭ID
@NotEmpty
@Length(max = 10)
private String filedType; //編碼段型別
@Length(max = 100)
private String filedValue; //編碼段值
@OrderBy
private Long fieldSequence; //序號
@Length(max = 50)
private String dateMask; //日期掩碼
private Long seqLength; //序列長度
private Long startValue; //序列開始值
private Long currentValue; //序列號段當前值
@Length(max = 10)
private String resetFrequency; //重置頻率
private Date resetDate; //上次重置日期
private Long stepNumber; //索引更新步長
//非資料庫欄位需要新增@Transient
@Transient
private String ruleCode; //編碼規則CODE
public Long getLineId() {
return lineId;
}
public void setLineId(Long lineId) {
this.lineId = lineId;
}
public Long getHeaderId() {
return headerId;
}
public void setHeaderId(Long headerId) {
this.headerId = headerId;
}
public String getFiledType() {
return filedType;
}
public void setFiledType(String filedType) {
this.filedType = filedType;
}
public String getFiledValue() {
return filedValue;
}
public void setFiledValue(String filedValue) {
this.filedValue = filedValue;
}
public Long getFieldSequence() {
return fieldSequence;
}
public void setFieldSequence(Long fieldSequence) {
this.fieldSequence = fieldSequence;
}
public String getDateMask() {
return dateMask;
}
public void setDateMask(String dateMask) {
this.dateMask = dateMask;
}
public Long getSeqLength() {
return seqLength;
}
public void setSeqLength(Long seqLength) {
this.seqLength = seqLength;
}
public Long getStartValue() {
return startValue;
}
public void setStartValue(Long startValue) {
this.startValue = startValue;
}
public Long getCurrentValue() {
return currentValue;
}
public void setCurrentValue(Long currentValue) {
this.currentValue = currentValue;
}
public String getResetFrequency() {
return resetFrequency;
}
public void setResetFrequency(String resetFrequency) {
this.resetFrequency = resetFrequency;
}
public Date getResetDate() {
return resetDate;
}
public void setResetDate(Date resetDate) {
this.resetDate = resetDate;
}
public Long getStepNumber() {
return stepNumber;
}
public void setStepNumber(Long stepNumber) {
this.stepNumber = stepNumber;
}
public String getRuleCode() {
return ruleCode;
}
public void setRuleCode(String ruleCode) {
this.ruleCode = ruleCode;
}
}
編寫Mapper
涉及到多表操作時,先定義Mapper介面方法,然後通過 Mapper.xml
去寫多表sql
來實現。
Mapper介面
//繼承了通用Mapper介面之後,就具備了一些單表的增刪改查操作
public interface CodeRulesTest1HeaderMapper extends Mapper<CodeRulesTest1Header> {
}
//繼承了通用Mapper介面之後,就具備了一些單表的增刪改查操作
public interface CodeRulesTest1LineMapper extends Mapper<CodeRulesTest1Line> {
int deleteByHeaderId(CodeRulesTest1Line line);
}
Mapper.xml
CodeRulesTest1LineMapper
介面對應的Mapper.xml
實現如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hand.hap.code.rule.mapper.CodeRulesTest1LineMapper">
<!--
id:在select標籤中,resultMap指定的值即為此處id所設定的值
type:用於配置查詢列所對映到的Java物件型別
-->
<resultMap id="BaseResultMap" type="com.hand.hap.code.rule.dto.CodeRulesTest1Line">
<!--
id:一個id結果,標記結果為id(唯一值)
result:注入到Java物件屬性的普通結果
column:從資料庫中得到的列名,或者是列的別名
property:對映到列結果的屬性
jdbcType:列對應的資料庫型別
-->
<id column="line_id" property="lineId" jdbcType="DECIMAL" />
<result column="header_id" property="headerId" jdbcType="DECIMAL" />
<result column="filed_type" property="filedType" jdbcType="VARCHAR" />
<result column="filed_value" property="filedValue" jdbcType="VARCHAR" />
<result column="field_sequence" property="fieldSequence" jdbcType="DECIMAL" />
<result column="date_mask" property="dateMask" jdbcType="VARCHAR" />
<result column="seq_length" property="seqLength" jdbcType="DECIMAL" />
<result column="start_value" property="startValue" jdbcType="DECIMAL" />
<result column="current_value" property="currentValue" jdbcType="DECIMAL" />
<result column="reset_frequency" property="resetFrequency" jdbcType="VARCHAR" />
<result column="reset_date" property="resetDate" jdbcType="DATE" />
</resultMap>
<delete id="deleteByHeaderId" parameterType="com.hand.hap.code.rule.dto.CodeRulesTest1Line">
DELETE FROM
sys_code_rules_test1_line
WHERE header_id=#{headerId,jdbcType=DECIMAL}
</delete>
</mapper>
Cache
實現類
//繼承HashStringRedisCache,將一整個表的資料,存放到一個 hash 結構中,每個例項,在 redis 中僅有一條記錄:一個 hash 結構
public class SysCodeRuleTest1Cache extends HashStringRedisCache<List<CodeRulesTest1Line>> {
private final static String SEQ_CATEGORY = "seq:";
private final Logger logger = LoggerFactory.getLogger(SysCodeRuleTest1Cache.class);
private String allEnableRuleSqlid = CodeRulesTest1HeaderMapper.class.getName()+".select";
private String codeRuleLineSqlId = CodeRulesTest1LineMapper.class.getName()+".select";
@Autowired
private CodeRulesTest1LineMapper lineMapper;
{
//setType(List.class);
setLoadOnStartUp(true);
}
public void removeSeq(String key) {
//刪除序列快取
getRedisTemplate().execute((RedisCallback<Object>) (connection) -> {
return connection.del(strSerializer.serialize(getSeqFullKey(key)));
});
}
public void reload(CodeRulesTest1Header header){
CodeRulesTest1Line lineCondition= new CodeRulesTest1Line();
lineCondition.setHeaderId(header.getHeaderId());
try (SqlSession sqlSession = getSqlSessionFactory().openSession()) {
List<CodeRulesTest1Line> lines = sqlSession.selectList(codeRuleLineSqlId, lineCondition);
//根據序號排序
lines.sort((a, b) -> a.getFieldSequence().compareTo(b.getFieldSequence()));
setValue(header.getRuleCode(), lines);
lines.forEach(line -> {
//處理序列情況
if (CodeRuleConstants.FIELD_TYPE_SEQUENCE.equalsIgnoreCase(line.getFiledType())) {
line.setRuleCode(header.getRuleCode());
byte[] fullSeqKey = strSerializer.serialize(getSeqFullKey(header.getRuleCode()));
loadSeq(line, fullSeqKey);
}
});
}catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("reolad code rule cache exception: ", e);
}
}
}
public void updateLine(CodeRulesTest1Line line){
List<CodeRulesTest1Line> lines = getValue(line.getRuleCode());
int index = 0;
for(CodeRulesTest1Line t : lines){
if(t.getLineId().equals(line.getLineId())){
lines.set(index,line);
}
index ++;
}
setValue(line.getRuleCode(),lines);
}
public Long incr(CodeRulesTest1Line line){
byte[] fullSeqKey = strSerializer.serialize(getSeqFullKey(line.getRuleCode()));
loadSeq(line,fullSeqKey);
return (Long) getRedisTemplate().execute((RedisCallback<Object>) (connection) -> {
return connection.incr(fullSeqKey);
});
}
public Long decr(CodeRulesTest1Line line){
byte[] fullSeqKey = strSerializer.serialize(getSeqFullKey(line.getRuleCode()));
//loadSeq(line,fullSeqKey);
return (Long) getRedisTemplate().execute((RedisCallback<Object>) (connection) -> {
return connection.decr(fullSeqKey);
});
}
public void reset(CodeRulesTest1Line line){
//高併發情況,避免重複重置,再次檢查是否需要重置(重新從快取中拿到當前序列資訊,檢查重置日期是否已經被更新)
synchronized (line.getRuleCode().intern()) {
boolean isRest = true;
List<CodeRulesTest1Line> lineList = getValue(line.getRuleCode());
for (CodeRulesTest1Line rulesLine : lineList) {
相關推薦
Panda學習筆記4——多表功能開發(2)後端介面開發
進行功能性的開發,主要涉及到:
序號
型別
名稱
1
DTO
CodeRulesTest1Header
2
DTO
CodeRulesTest1Line
3
Mapper
CodeRulesTest1HeaderMapper
4
Ma
ArcGIS API for JavaScript3.x 學習筆記[4] 加載底圖(三)【Open Street Map開放街道地圖】
asc 裏的 指定 訪問 utf-8 gis sca utf 同方 Open Street Map
OpenStreetMap(簡稱OSM,中文是開放街道地圖)是一個網上地圖協作計劃,目標是創造一個內容自由且能讓所有人編輯的世界地圖。
OSM是一款由網絡大眾共同打造的免費開
機器學習筆記4:正則化(Regularization)
機器學習筆記4:正則化(Regularization)
Andrew Ng機器學習課程學習筆記4
過擬合與欠擬合 線性擬合時,有兩種擬合效果不好的情況,分別是過擬合與欠擬合。 過擬合(overfitting),也叫高方差(variance)。主要是擬合曲線過於彎曲,雖然
React學習筆記之react進階篇(2)
-s state ops category strong tro 服務 ive 周期 2.組件與服務器通信
組件的生命周期分為三個階段:掛載階段->更新階段->卸載階段,本文主要集中講述掛載和更新階段組件如何和服務器進行通信。
1.組件掛載階段通信
《C語言程式設計:現代方法(第2版)(K.N.King 著)》學習筆記九:格式化輸入/輸出(2)
3.2 scanf 函式
就如同 printf 函式用特定的格式顯示輸出一樣,scanf 函式也根據特定的格式讀取輸入。像 printf 函式的格式串一樣,scanf 函式的格式串也可以包含普通字元
GO學習筆記——GO語言整合工具GoLand(2)
既然開始下定決心要學GO語言了,先從安裝做起吧。
安裝的過程很簡單,百度上一搜大把的教程,我這裡就不做搬運工了,可以自己去百度上搜怎麼安裝。
不過這裡我要說明一下,百度上的教程裡的那個環境變數的設定,有一個GOPATH環境變數,這個環境變數其實我們初學者在學基礎語法的時候
數字語音訊號處理學習筆記——語音訊號的數字模型(2)
版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/u013538664/article/details/25126095 2.3 語音的聽覺機理
&nb
【MATLAB 學習筆記】 SimMechanics 流程攻略 (2)
本章主要內容:
1. 製作斜坡上以及懸掛的彈簧阻尼系統;
2. 用m檔案修改系統中的引數,達到可程式設計控制的目的。
====================================================================
首先研究一下各個
tensorflow學習筆記——使用TensorFlow操作MNIST資料(2)
tensorflow學習筆記——使用TensorFlow操作MNIST資料(1)
一:神經網路知識點整理
1.1,多層:使用多層權重,例如多層全連線方式
以下定義了三個隱藏層的全連線方式的神經網路
跟我一起玩Win32開發(2):完整的開發流程
上一篇中我給各位說了一般人認為C++中較為難的東西——指標。其實對於C++,難點當然不侷限在指標這玩意兒上,還有一些有趣的概念,如模板類、虛基類、純虛擬函式等,這些都是概念性的東西,幾乎每一本C++書上都會介紹,而平時我們除了會接觸到純虛擬函式外,其他的不多用。純虛擬函式,
《Oracle大資料解決方案》學習筆記4——選擇Appliance的理由(Why an Appliance?)
雖然這章的內容有點像Oracled的市場宣傳資料,但也因此學習了一些大資料相關硬體的知識。
1. Oracle大資料機(Big Data Appliance)X3-2硬體規格(全機架配置,18個節點)
2. Oracle大資料機全機架配置環境規格
3. Orac
Django學習筆記(18)——BBS+Blog專案開發(2)主體思路及流程
這篇部落格主要完成一個BBS+Blog專案,那麼主要是模仿部落格園的部落格思路,使用Django框架進行練習。
準備:專案需求分析
在做一個專案的時候,我們首先做的就是談清楚專案需求,功能需求,然後才開始寫,要是沒有和產品經理聊清楚需求,到時候改的話就非常非常麻煩。
那此次寫專案的話,我會嚴
Andrew Ng機器學習筆記+Weka相關算法實現(四)SVM和原始對偶問題
優化問題 坐標 出了 變量 addclass fun ber 找到 線性
這篇博客主要解說了Ng的課第六、七個視頻,涉及到的內容包含,函數間隔和幾何間隔、最優間隔分類器 ( Optimal Margin
Classifier)、原始/對偶問題 ( Pr
python學習筆記表達式和運算符(一)
python表達式和運算符什麽是表達式?1+2*3 就是一個表達式,這裏的加號和乘號叫做運算符,1、2、3叫做操作數。1+2*3 經過計算後得到的結果是7,就1+2*3 = 7。我們可以將計算結果保存在一個變量裏,ret = 1-2*3 。 所以表達式就是由操作數和運算符組成的一句代碼或語句,表達式可以求值,
HTML學習筆記 CSS樣式 第六節 (原創)
Y軸 重復 eight -i tac 圖片 500px itl idt <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title&
ArcGIS API for JavaScript3.x 學習筆記[3] 加載底圖(一)【天地圖(經緯度版)】
矢量地圖 說明 tiled spa 過程 相同 服務器列表 text 服務
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5
ArcGIS API for JavaScript3.x 學習筆記[5] 加載底圖(四)【高德在線地圖】
alex apt arcgis lex 添加 declare 學習 created ade
/**
* Created by WanderGIS on 2015/7/15.
*/
define(["dojo/_base/declare",
"esri/geom
【安全牛學習筆記】手動漏洞挖掘(四)
security+ 漏洞 信息安全 手動漏洞挖掘本地文件包含lfi 查看文件 代碼執行 <?php echo shell_exec($_GET[‘cmd‘]);?> Apache access.log遠程文件包含rfi 出現概率少於lfi,
【安全牛學習筆記】SQLMAP自動註入(二)
信息安全 security+ SQLMAP自動註入(二)-REQUEST和SQLMAP自動註入(三)-OPTIMIZATIONSQLMAP自動註入02-----REQUEST--delay 每次http(s)請求之間延遲時間,浮點數,單位為秒,默認無延遲--timeout 請求超時時間,
Angular5學習筆記 - 虛擬RestfulApi配置與使用(六)
window com scripts mac restfu alt 新建 服務 src 一、安裝json-server功能
#windows
cnpm install json-server -g
#Mac & Linux
sudo npm install j