Skip to content

Commit

Permalink
随手记搜索时支持包含内容
Browse files Browse the repository at this point in the history
  • Loading branch information
rememberber committed Dec 6, 2024
1 parent 01fd762 commit 12ce96b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface TQuickNoteMapper {
int updateAll(TQuickNote tQuickNote);

List<TQuickNote> selectAllByFilter(String titleFilterKeyWord);

List<TQuickNote> selectAllByFilterContainsContent(String titleFilterKeyWord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class QuickNoteForm {
private JCheckBox commaDoubleQuotesToEnterCheckBox;

private JToggleButton colorButton;
private JCheckBox searchContentCheckBox;

private JToolBar toolBar;
public final static String[] COLOR_KEYS = {
Expand All @@ -122,6 +123,7 @@ private QuickNoteForm() {
colorButton.setEnabled(true);

toolBar = new JToolBar();
searchContentCheckBox = new JCheckBox();
UndoUtil.register(this);
}

Expand Down Expand Up @@ -155,6 +157,9 @@ private static void initUi() {
quickNoteForm.getSearchTextField().putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "搜索");
quickNoteForm.getSearchTextField().putClientProperty(FlatClientProperties.TEXT_FIELD_LEADING_ICON,
new FlatSearchIcon());
quickNoteForm.getSearchContentCheckBox().setToolTipText("包含内容");
quickNoteForm.getSearchTextField().putClientProperty(FlatClientProperties.TEXT_FIELD_TRAILING_COMPONENT, quickNoteForm.getSearchContentCheckBox());

quickNoteForm.getAddButton().setIcon(new FlatSVGIcon("icon/add.svg"));
quickNoteForm.getSaveButton().setIcon(new FlatSVGIcon("icon/save.svg"));
quickNoteForm.getFindButton().setIcon(new FlatSVGIcon("icon/find.svg"));
Expand Down Expand Up @@ -363,7 +368,14 @@ public static void initNoteListTable() {

String titleFilterKeyWord = quickNoteForm.getSearchTextField().getText();
titleFilterKeyWord = "%" + titleFilterKeyWord + "%";
List<TQuickNote> quickNoteList = quickNoteMapper.selectAllByFilter(titleFilterKeyWord);
boolean searchContent = quickNoteForm.getSearchContentCheckBox().isSelected();

List<TQuickNote> quickNoteList;
if (searchContent && StringUtils.isNotBlank(titleFilterKeyWord)) {
quickNoteList = quickNoteMapper.selectAllByFilterContainsContent(titleFilterKeyWord);
} else {
quickNoteList = quickNoteMapper.selectAllByFilter(titleFilterKeyWord);
}

for (TQuickNote tQuickNote : quickNoteList) {
data = new Object[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ public void changedUpdate(DocumentEvent e) {
// QuickNoteForm.initNoteListTable();
}
});

// 搜索框包含内容checkbox变更事件
quickNoteForm.getSearchContentCheckBox().addActionListener(e -> {
QuickNoteForm.initNoteListTable();
});
}

public static void showFindPanel() {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/mapper/TQuickNoteMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
where name like #{titleFilterKeyWord,jdbcType=VARCHAR}
order by modified_time desc
</select>
<select id="selectAllByFilterContainsContent" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_quick_note
where name like #{titleFilterKeyWord,jdbcType=VARCHAR}
or content like #{contentFilterKeyWord,jdbcType=VARCHAR}
order by modified_time desc
</select>
<update id="updateByName" parameterType="com.luoboduner.moo.tool.domain.TQuickNote">
update t_quick_note
<set>
Expand Down

0 comments on commit 12ce96b

Please sign in to comment.