Mybatis,模糊查询语句,以及传参数的正确写法
2024-09-03 16:17:12
不多说直接上代码!
接口:
public interface CommodityMapper {
int deleteByPrimaryKey(Integer productId); int insert(Commodity record); Commodity selectByPrimaryKey(Integer productId); List<Commodity> selectAll(); List<Commodity> getType(int id); int updateByPrimaryKey(Commodity record); int getCount(); List<Commodity> SearchCommodity(@Param("productName") String productName);//注意传参的名字必须要和Mapper文件一致 }
Constroller层:
//搜索
@RequestMapping(path = "/search", method = RequestMethod.GET)
public ResponseEntity Search(String productName) {
if (commodityService.SearchCommodity(productName).size() != 0) {
return ResponseEntity.ok(commodityService.SearchCommodity(productName));
} else {
return ResponseEntity.ok("error");
} }
Mapper文件
<select id="SearchCommodity" resultType="string" resultMap="BaseResultMap">
select
c.product_id,
c.product_name,
c.product_content,
s.product_specs,
s.product_price,
d.product_simg
from commodity c
cross join Standard s
on c.product_id=s.product_id
cross join dommodityAttribute d
on c.product_id=d.product_id
where c.product_name like concat('%',#{productName},'%') group by c.product_id
</select>
最新文章
- asp.net MVC 通用登录验证模块
- [linux系统]查看内核版本和系统版本方法
- GEF: 图形拖拽处理
- MVVM架构~knockoutjs系列之扩展ajax验证~验证输入数据是否与后台数据相等
- ubuntu安装VNC、Xfce桌面
- SSH相关
- ACTIVITI 研究代码 之 模版模式
- OSG中的示例程序简介(转)
- HDU 1848 Fibonacci again and again
- Ubuntu Crontab
- shell 中最常使用的 FD (file descriptor)
- Csocket基本原理
- 记录一次JavaWeb开发的乱码解决
- linux 保存git的账号密码
- VS2012使用验证控件出现[ASP.NET]WebForms UnobtrusiveValidationMode 需要 &#39;jquery&#39; 的 ScriptResourceMapping。請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)。的解决办法。
- python-面向对象增强版
- Android开发之getX,getRawX,getWidth,getTranslationX等的区别
- intellij 快捷键整理
- flink 根据时间消费kafka
- fatal error LNK1104: 无法打开文件“libc.lib”的问题