老师你好,我想增加一个ticketName的模糊查询,没能生效。老师看看是啥原因呢?
来源:19-3 【项目实战】MyBatisX 插件的集成与应用

unbreakable_全栈
2025-03-28
resources/mapperTicketsMapper.xml
文件内容如下:
<resultMap id="BaseResultMap" type="com.imooc.job.domain.Tickets">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="ticketName" column="ticket_name" jdbcType="VARCHAR"/>
<result property="ticketCode" column="ticket_code" jdbcType="VARCHAR"/>
<result property="ticketUp" column="ticket_up" jdbcType="VARCHAR"/>
<result property="ticketDown" column="ticket_down" jdbcType="VARCHAR"/>
<result property="ticketCurrent" column="ticket_current" jdbcType="VARCHAR"/>
<result property="ticketLocation" column="ticket_location" jdbcType="VARCHAR"/>
<result property="ticketOne" column="ticket_one" jdbcType="VARCHAR"/>
<result property="ticketDividend" column="ticket_dividend" jdbcType="VARCHAR"/>
<result property="ticketMarket" column="ticket_market" jdbcType="VARCHAR"/>
<result property="ticketFinancing" column="ticket_financing" jdbcType="VARCHAR"/>
<result property="ticketChou90" column="ticket_chou_90" jdbcType="VARCHAR"/>
<result property="ticketChou70" column="ticket_chou_70" jdbcType="VARCHAR"/>
<result property="ticketAction" column="ticket_action" jdbcType="VARCHAR"/>
<result property="ticketField1" column="ticket_field1" jdbcType="VARCHAR"/>
<result property="ticketField2" column="ticket_field2" jdbcType="VARCHAR"/>
<result property="ticketField3" column="ticket_field3" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,ticket_name,ticket_code,
ticket_up,ticket_down,ticket_current,
ticket_controlling,ticket_location,ticket_one,
ticket_dividend,ticket_market,ticket_financing,
ticket_chou_90,ticket_chou_70,ticket_action,
ticket_field1,ticket_field2,ticket_field3
</sql>
<select id="allTickets" resultType="com.imooc.job.vo.JbosByTicketsVo">
SELECT
js.ticket_name
FROM
tickets js
LEFT JOIN
tickets jc ON js.ticket_name = jc.ticket_name;
</select>
<insert id="insertTickets" parameterType="com.imooc.job.domain.Tickets" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `tickets`
(ticket_name, ticket_code, ticket_up, ticket_down, ticket_current, ticket_controlling, ticket_location, ticket_one, ticket_dividend, ticket_market, ticket_financing, ticket_chou_90, ticket_chou_70, ticket_action, ticket_field1, ticket_field2, ticket_field3)
VALUES
(#{ticketName}, #{ticketCode}, #{ticketUp}, #{ticketDown}, #{ticketCurrent}, #{ticketControlling}, #{ticketLocation}, #{ticketOne}, #{ticketDividend}, #{ticketMarket}, #{ticketFinancing}, #{ticketChou90}, #{ticketChou70}, #{ticketAction}, #{ticketField1}, #{ticketField2}, #{ticketField3})
</insert>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
DELETE FROM `tickets`
WHERE id = #{id}
</delete>
<update id="updateByPrimaryKey" parameterType="com.imooc.job.domain.Tickets">
UPDATE tickets
SET
ticket_name = #{ticketName},
ticket_code = #{ticketCode},
ticket_up = #{ticketUp},
ticket_down = #{ticketDown},
ticket_current = #{ticketCurrent},
ticket_controlling = #{ticketControlling},
ticket_location = #{ticketLocation},
ticket_one = #{ticketOne},
ticket_dividend = #{ticketDividend},
ticket_market = #{ticketMarket},
ticket_financing = #{ticketFinancing},
ticket_chou_90 = #{ticketChou90},
ticket_chou_70 = #{ticketChou70},
ticket_action = #{ticketAction},
ticket_field1 = #{ticketField1},
ticket_field2 = #{ticketField2},
ticket_field3 = #{ticketField3}
WHERE
id = #{id}
</update>
domain/Tickets
文件如下:
package com.imooc.job.domain;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
//import org.hibernate.validator.constraints.Length;
//import javax.validation.constraints.NotBlank;
@Data // 使用@Data注解了,它将为您的类自动生成getter、setter、toString、equals和hashCode方法。
@NoArgsConstructor // 生成一个无参构造函数
@AllArgsConstructor // 生成一个包含所有参数的构造函数
public class Tickets {
private int id;
private String ticketName;
private String ticketCode;
private String ticketUp;
private String ticketDown;
private String ticketCurrent;
private String ticketControlling;
private String ticketLocation;
private String ticketOne;
private String ticketDividend;
private String ticketMarket;
private String ticketFinancing;
private String ticketChou90;
private String ticketChou70;
private String ticketAction;
private String ticketField1;
private String ticketField2;
private String ticketField3;
}
mapper
文件如下:
package com.imooc.job.mapper;
import com.imooc.job.domain.Tickets;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
public interface TicketsMapper extends BaseMapper {
/**
* 查询数据
* @return
*/
List allTickets();
/**
* 添加数据
* @param tickets
* @return
*/
int insertTickets(Tickets tickets);
/**
* 删除数据
* @param id
* @return
*/
int deleteByPrimaryKey(Integer id);
/**
* 修改数据
* @param tickets
* @return
*/
int updateByPrimaryKey(Tickets tickets);
}
service/TicketsService
package com.imooc.job.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.job.domain.Jobs;
import com.imooc.job.domain.Tickets;
import com.baomidou.mybatisplus.extension.service.IService;
import com.imooc.job.utils.ReponseResult;
import java.util.List;
/**
-
Tickets服务接口
/
public interface TicketsService extends IService {
/*- 获取所有数据
- @param pageNum 当前页码
- @param pageSize 每页数据条数
- @return
*/
IPage getAllTickets(int pageNum, int pageSize, String ticketName);
/**
- 新增
- @param tickets
- @return
*/
ReponseResult addTickets(Tickets tickets);
/**
- 删除
- @param id
- @return
*/
ReponseResult removeTickets(Integer id);
/**
- 修改
- @param tickets
- @return
*/
ReponseResult updateTickets(Tickets tickets);
}
service/impl/TicketsServiceImpl
文件内容:
package com.imooc.job.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.job.domain.Tickets;
import com.imooc.job.mapper.TicketsMapper;
import com.imooc.job.service.TicketsService;
import com.imooc.job.utils.ReponseResult;
import com.imooc.job.utils.enums.ResultCodeEnum;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TicketsServiceImpl extends ServiceImpl<TicketsMapper, Tickets> implements TicketsService {
@Override
public Class<Tickets> getEntityClass() {
return Tickets.class;
}
@Resource
private TicketsMapper ticketsMapper;
/**
* 查询所有
* @return
*/
@Override
// public ReponseResult getAllTickets() {
// return new ReponseResult(ticketsMapper.allTickets());
// }
public IPage getAllTickets(int pageNum, int pageSize, String ticketName) {
// 创建分页对象
Page<Tickets> page = new Page<>(pageNum, pageSize);
// 构造查询条件
QueryWrapper<Tickets> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id",
"ticket_name",
"ticket_code",
"ticket_up",
"ticket_down",
"ticket_current",
"ticket_controlling",
"ticket_location",
"ticket_one",
"ticket_dividend",
"ticket_market",
"ticket_financing",
"ticket_chou_90",
"ticket_chou_70",
"ticket_action",
"ticket_field1",
"ticket_field2",
"ticket_field3"
);
// 执行分页查询
Page<Tickets> ticketsPage = ticketsMapper.selectPage(page, queryWrapper);
return ticketsPage;
}
/**
* 新增
* @param tickets
* @return
*/
@Override
public ReponseResult addTickets(Tickets tickets) {
int result = ticketsMapper.insertTickets(tickets);
Map<String, Integer> idMap = new HashMap<>();
if (result > 0) {
// result = jobCategory.getId(); // 如果插入成功,返回自增主键id
idMap.put(“id”, tickets.getId());
return new ReponseResult(idMap);
}
return new ReponseResult(ResultCodeEnum.SERVER_ERROR);
}
/**
* 删除岗位类别
* @param id
* @return
*/
@Override
public ReponseResult removeTickets(Integer id) {
int result = ticketsMapper.deleteByPrimaryKey(id);
if (result > 0) {
return new ReponseResult();
}
return new ReponseResult(ResultCodeEnum.DB_ERROR);
}
/**
* 修改
* @param tickets
* @return
*/
@Override
public ReponseResult updateTickets(Tickets tickets) {
int result = ticketsMapper.updateByPrimaryKey(tickets);
if (result > 0) {
return new ReponseResult();
}
return new ReponseResult(ResultCodeEnum.DB_ERROR);
}
}
controllerTicketsController
文件内容:
package com.imooc.job.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.job.domain.Tickets;
import com.imooc.job.service.TicketsService;
import com.imooc.job.utils.ReponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Slf4j
@Api(tags=“股票相关接口”)
public class TicketsController {
@Autowired
private TicketsService ticketsService;
@GetMapping("/all/tickets")
@ApiOperation("获取所有")
public ReponseResult getAllTickets(@RequestParam("page") Integer page,
@RequestParam("pageSize") Integer pageSize,
@RequestParam(value = "ticketName", required = false) String ticketName) {
// 如果pageSize没有传递,可以设置一个默认值
if (pageSize == null) {
pageSize = 10; // 默认每页显示10条记录
}
IPage<Tickets> ticketsByPage = ticketsService.getAllTickets(page, pageSize, ticketName);
log.info("股票 总行数:{}", ticketsByPage.getTotal());
log.info("股票 总页数:{}", ticketsByPage.getPages());
log.info("股票 当前页:{}", ticketsByPage.getCurrent());
return new ReponseResult(ticketsByPage);
// return ticketsService.getAllTickets();
}
@PostMapping("/add/tickets")
@ApiOperation("添加")
public ReponseResult addTickets(@Validated Tickets tickets) {
return ticketsService.addTickets(tickets);
}
@PostMapping("/delete/tickets")
@ApiOperation("删除")
public ReponseResult deleteTickets(@RequestParam(value = "id") Integer id) {
return ticketsService.removeTickets(id);
}
@PostMapping("/update/tickets")
@ApiOperation("修改")
public ReponseResult updateTickets(Tickets tickets) {
return ticketsService.updateTickets(tickets);
}
}
1回答
-
彭彭老师
2025-03-31
完整的项目打包QQ发我一下吧,我看下
00
相似问题