Mybatis,模糊查詢語句,以及傳參數的正確寫法


不多說直接上代碼!

 

 

 

 

接口:

 
         

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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM