帮我写一个springboot的对AdvertisementEntity的基于mybatis的增删改查,查是对字段type的,的serviceImpl类的实现方法和用controller层调用,其中AdvertisementEntity包含字段有Long id;String url;String type;String second;LocalDateTime createTime;LocalDateTime updateTime;int step;String enable;int advertisementType;String jumpUrl;。要求返回格式为json,数据库是MySQL
时间: 2023-03-31 22:00:18 浏览: 104
spring+springmvc+mybatis完善的增删改查,适合新手,数据库是mysql,自己建立一下数据库数据
好的,我可以回答这个问题。以下是基于Mybatis的AdvertisementEntity增删改查的serviceImpl类的实现方法和用controller层调用的示例代码:
AdvertisementServiceImpl.java
```
@Service
public class AdvertisementServiceImpl implements AdvertisementService {
@Autowired
private AdvertisementMapper advertisementMapper;
@Override
public AdvertisementEntity getAdvertisementByType(String type) {
return advertisementMapper.getAdvertisementByType(type);
}
@Override
public void addAdvertisement(AdvertisementEntity advertisement) {
advertisementMapper.addAdvertisement(advertisement);
}
@Override
public void updateAdvertisement(AdvertisementEntity advertisement) {
advertisementMapper.updateAdvertisement(advertisement);
}
@Override
public void deleteAdvertisement(Long id) {
advertisementMapper.deleteAdvertisement(id);
}
}
```
AdvertisementController.java
```
@RestController
@RequestMapping("/advertisement")
public class AdvertisementController {
@Autowired
private AdvertisementService advertisementService;
@GetMapping("/{type}")
public AdvertisementEntity getAdvertisementByType(@PathVariable String type) {
return advertisementService.getAdvertisementByType(type);
}
@PostMapping
public void addAdvertisement(@RequestBody AdvertisementEntity advertisement) {
advertisementService.addAdvertisement(advertisement);
}
@PutMapping
public void updateAdvertisement(@RequestBody AdvertisementEntity advertisement) {
advertisementService.updateAdvertisement(advertisement);
}
@DeleteMapping("/{id}")
public void deleteAdvertisement(@PathVariable Long id) {
advertisementService.deleteAdvertisement(id);
}
}
```
以上代码实现了对AdvertisementEntity的基于Mybatis的增删改查,查是对字段type的。返回格式为json。数据库是MySQL。
阅读全文