package com.powernode.mybatis.Test;
import com.powernode.mybatis.mappers.CarMapper;
import com.powernode.mybatis.pojo.Car;
import com.powernode.mybatis.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
public class Test
{
@org.junit.Test
public void update()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
Car car = new Car(52L,"6666","比亚迪海豚",10L,"2020-11-11","新能源");
mapper.update(car);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
@org.junit.Test
public void deleteById()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
int count = mapper.deleteById(49L);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
@org.junit.Test
public void TestInsert()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
Car car = new Car(null,"6666","比亚迪海豚",10L,"2020-11-11","新能源");
int count = mapper.insert(car);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
}
package com.powernode.mybatis.Test;
import com.powernode.mybatis.mappers.CarMapper;
import com.powernode.mybatis.pojo.Car;
import com.powernode.mybatis.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
public class Test
{
@org.junit.Test
public void update()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
Car car = new Car(52L,"6666","比亚迪海豚",10L,"2020-11-11","新能源");
mapper.update(car);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
@org.junit.Test
public void deleteById()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
int count = mapper.deleteById(49L);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
@org.junit.Test
public void TestInsert()
{
SqlSession sqlSession = SqlSessionUtils.openSession();
CarMapper mapper = sqlSession.getMapper(CarMapper.class);
Car car = new Car(null,"6666","比亚迪海豚",10L,"2020-11-11","新能源");
int count = mapper.insert(car);
sqlSession.commit();
SqlSessionUtils.close(sqlSession);
}
}
package com.powernode.mybatis.mappers;
import com.powernode.mybatis.pojo.Car;
import com.powernode.mybatis.pojo.CarExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
public interface CarMapper {
long countByExample(CarExample example);
@Update("update t_car set car_num = #{carNum},brand = #{brand},guide_price = #{guidePrice}," +
"produce_time = #{produceTime},car_type = #{carType} where id = #{id}")
int update(Car car);
int deleteByExample(CarExample example);
@Delete("delete from t_car where id = #{id}")
int deleteById(Long id);
int deleteByPrimaryKey(Long id);
@Insert("insert into t_car values(null,#{carNum},#{brand},#{guidePrice},#{produceTime},#{carType})")
int insert(Car row);
int insertSelective(Car row);
List<Car> selectByExample(CarExample example);
Car selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("row") Car row, @Param("example") CarExample example);
int updateByExample(@Param("row") Car row, @Param("example") CarExample example);
int updateByPrimaryKeySelective(Car row);
int updateByPrimaryKey(Car row);
}
package com.powernode.mybatis.mappers;
import com.powernode.mybatis.pojo.Car;
import com.powernode.mybatis.pojo.CarExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
public interface CarMapper {
long countByExample(CarExample example);
@Update("update t_car set car_num = #{carNum},brand = #{brand},guide_price = #{guidePrice}," +
"produce_time = #{produceTime},car_type = #{carType} where id = #{id}")
int update(Car car);
int deleteByExample(CarExample example);
@Delete("delete from t_car where id = #{id}")
int deleteById(Long id);
int deleteByPrimaryKey(Long id);
@Insert("insert into t_car values(null,#{carNum},#{brand},#{guidePrice},#{produceTime},#{carType})")
int insert(Car row);
int insertSelective(Car row);
List<Car> selectByExample(CarExample example);
Car selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("row") Car row, @Param("example") CarExample example);
int updateByExample(@Param("row") Car row, @Param("example") CarExample example);
int updateByPrimaryKeySelective(Car row);
int updateByPrimaryKey(Car row);
}
package com.powernode.mybatis.pojo;
public class Car {
private Long id;
private String carNum;
private String brand;
private Long guidePrice;
private String produceTime;
private String carType;
public Car(Long id, String carNum, String brand, Long guidePrice, String produceTime, String carType) {
this.id = id;
this.carNum = carNum;
this.brand = brand;
this.guidePrice = guidePrice;
this.produceTime = produceTime;
this.carType = carType;
}
public Car() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCarNum() {
return carNum;
}
public void setCarNum(String carNum) {
this.carNum = carNum == null ? null : carNum.trim();
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand == null ? null : brand.trim();
}
public Long getGuidePrice() {
return guidePrice;
}
public void setGuidePrice(Long guidePrice) {
this.guidePrice = guidePrice;
}
public String getProduceTime() {
return produceTime;
}
public void setProduceTime(String produceTime) {
this.produceTime = produceTime == null ? null : produceTime.trim();
}
public String getCarType() {
return carType;
}
public void setCarType(String carType) {
this.carType = carType == null ? null : carType.trim();
}
}
package com.powernode.mybatis.pojo;
public class Car {
private Long id;
private String carNum;
private String brand;
private Long guidePrice;
private String produceTime;
private String carType;
public Car(Long id, String carNum, String brand, Long guidePrice, String produceTime, String carType) {
this.id = id;
this.carNum = carNum;
this.brand = brand;
this.guidePrice = guidePrice;
this.produceTime = produceTime;
this.carType = carType;
}
public Car() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCarNum() {
return carNum;
}
public void setCarNum(String carNum) {
this.carNum = carNum == null ? null : carNum.trim();
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand == null ? null : brand.trim();
}
public Long getGuidePrice() {
return guidePrice;
}
public void setGuidePrice(Long guidePrice) {
this.guidePrice = guidePrice;
}
public String getProduceTime() {
return produceTime;
}
public void setProduceTime(String produceTime) {
this.produceTime = produceTime == null ? null : produceTime.trim();
}
public String getCarType() {
return carType;
}
public void setCarType(String carType) {
this.carType = carType == null ? null : carType.trim();
}
}