Commit dbebeccc by 胡明森

检索标签

parent 343cb12e
package cn.meteor.beyondclouds.modules.tag.api; package cn.meteor.beyondclouds.modules.tag.api;
import cn.meteor.beyondclouds.core.api.Response; import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import cn.meteor.beyondclouds.modules.tag.exception.TagServiceException; import cn.meteor.beyondclouds.modules.tag.exception.TagServiceException;
import cn.meteor.beyondclouds.modules.tag.form.CreateTagForm; import cn.meteor.beyondclouds.modules.tag.form.CreateTagForm;
import cn.meteor.beyondclouds.modules.tag.service.ITagService; import cn.meteor.beyondclouds.modules.tag.service.ITagService;
...@@ -8,12 +9,10 @@ import io.swagger.annotations.Api; ...@@ -8,12 +9,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List;
/** /**
* @author 胡明森 * @author 胡明森
...@@ -48,4 +47,14 @@ public class TagApi { ...@@ -48,4 +47,14 @@ public class TagApi {
} }
} }
@ApiOperation("检索标签")
@GetMapping("/tags/{keywords}")
public Response<List<Tag>> searchTags(@PathVariable("keywords") String keywords) {
List<Tag> tags = tagService.searchTags(keywords);
return Response.success(tags);
}
} }
...@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.tag.entity.Tag; ...@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
/** /**
* <p> * <p>
* 标签表 Mapper 接口 * 标签表 Mapper 接口
...@@ -16,4 +18,6 @@ import org.springframework.stereotype.Component; ...@@ -16,4 +18,6 @@ import org.springframework.stereotype.Component;
public interface TagMapper extends BaseMapper<Tag> { public interface TagMapper extends BaseMapper<Tag> {
Tag getTags(String tagName, Integer tagType); Tag getTags(String tagName, Integer tagType);
List<Tag> searchTags(String keywords);
} }
...@@ -6,4 +6,8 @@ ...@@ -6,4 +6,8 @@
select * from tag where tag_name=#{tagName} and tag_type=#{tagType} select * from tag where tag_name=#{tagName} and tag_type=#{tagType}
</select> </select>
<select id="searchTags" resultType="cn.meteor.beyondclouds.modules.tag.entity.Tag">
select * from tag where tag_name like CONCAT('%',#{keywords},'%')
</select>
</mapper> </mapper>
...@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.tag.entity.Tag; ...@@ -4,6 +4,8 @@ import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import cn.meteor.beyondclouds.modules.tag.exception.TagServiceException; import cn.meteor.beyondclouds.modules.tag.exception.TagServiceException;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* <p> * <p>
* 标签表 服务类 * 标签表 服务类
...@@ -20,4 +22,6 @@ public interface ITagService extends IService<Tag> { ...@@ -20,4 +22,6 @@ public interface ITagService extends IService<Tag> {
* @param tagType * @param tagType
*/ */
void createTag(String tagName, Integer tagType) throws TagServiceException; void createTag(String tagName, Integer tagType) throws TagServiceException;
List<Tag> searchTags(String keywords);
} }
...@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* <p> * <p>
* 标签表 服务实现类 * 标签表 服务实现类
...@@ -55,4 +57,9 @@ public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagS ...@@ -55,4 +57,9 @@ public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagS
tag.setTagType(tagType); tag.setTagType(tagType);
save(tag); save(tag);
} }
@Override
public List<Tag> searchTags(String keywords) {
return tagMapper.searchTags(keywords);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment