4.0.0org.springframework.bootspring-boot-starter-parent2.6.11com.demoboot-010.0.1-SNAPSHOTboot-01Demo project for Spring Boot1.8org.springframework.bootspring-boot-starter-jdbcorg.springframework.bootspring-boot-starter-thymeleaforg.springframework.bootspring-boot-starter-weborg.mybatis.spring.bootmybatis-spring-boot-starter2.2.2com.mysqlmysql-connector-jruntimeorg.projectlomboklomboktrueorg.springframework.bootspring-boot-starter-testtestorg.apache.maven.pluginsmaven-compiler-plugin3.8.11.81.8UTF-8org.springframework.bootspring-boot-maven-plugin
package com.demo.boot01.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Type {
private Integer typeid;
private String typename;
}
工具类utils
public class R extends HashMap {
private static final long serialVersionUID = 1L;
public R() {
put("code", 0);
put("msg", "success");
}
public static R error() {
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员");
}
public static R error(String msg) {
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
}
public static R error(int code, String msg) {
R r = new R();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("msg", msg);
return r;
}
public static R ok(Map map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
public R put(String key, Object value) {
super.put(key, value);
return this;
}
}
@Mapper
public interface GoodsMapper {
int insert(Goods record);
int insertSelective(Goods record);
List getAll();
int delById(@Param("goodsName")String goodsName);
int update(Goods goods);
Goods findByGoodsName(String name);
}
编写service业务层
@Service
public class GoodsServiceImpl implements GoodsService{
@Resource
private GoodsMapper goodsMapper;
@Override
public int insert(Goods record) {
return goodsMapper.insert(record);
}
@Override
public int insertSelective(Goods record) {
return goodsMapper.insertSelective(record);
}
@Override
public List getAll() {
return goodsMapper.getAll();
}
@Override
public int delById(String goodsName) {
return goodsMapper.delById(goodsName);
}
@Override
public int update(Goods goods) {
return goodsMapper.update(goods);
}
@Override
public Goods findByGoodsName(String name) {
return goodsMapper.findByGoodsName(name);
}
}
编写controller
@Controller
public class GoodsController {
@Autowired
private GoodsService goodsService;
@GetMapping("/getAll")
@ResponseBody
public R getAll() {
List all = goodsService.getAll();
return R.ok().code(200).data("goodList", all);
}
@GetMapping("/findByName")
@ResponseBody
public R findByName(@RequestParam("goodsName") String goodsName) {
Goods goods = goodsService.findByGoodsName(goodsName);
return R.ok().code(200).data("goods", goods);
}
@GetMapping("/del")
@ResponseBody
public R del(@RequestParam("goodsName") String goodsName) {
System.out.println("名称=============>" + goodsName);
int delcount = goodsService.delById(goodsName);
return R.ok().code(200).data("isFlag", delcount);
}
@GetMapping("/add")
@ResponseBody
public R add( Goods goods) {
int addCount = goodsService.insertSelective(goods);
return R.ok().code(200).data("isFlag", addCount);
}
}
快速高效用:SET SQL_SAFE_UPDATES = 0;下面的就不要看了!
今日用MySQL Workbench进行数据库的管理更新时,执行一个更新的语句碰到以下错误提示:
Error Code: 1175
You are using safe update mode and you tried to update a table without a WHERE that
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
Note:You may assume that nums1 has enough space (size that is