There is no getter for property named 'sub_title' in class Goods

package com.imooc.mybatis.entity;
public class Goods {
private Integer goodsId; //商品编号
private String title; //标题
private String subTitle; //子标题
private Float originalCost; //原始价格
private Float currentPrice; //当前价格
private Float discount; //
private Integer isFreeDelivery; //是否包邮,1-包邮 0-不包邮
private Integer categoryId; //分类编号
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubTitle() {
return subTitle;
}
public void setSubTitle(String subTitle) {
this.subTitle = subTitle;
}
public Float getOriginalCost() {
return originalCost;
}
public void setOriginalCost(Float originalCost) {
this.originalCost = originalCost;
}
public Float getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(Float currentPrice) {
this.currentPrice = currentPrice;
}
public Float getDiscount() {
return discount;
}
public void setDiscount(Float discount) {
this.discount = discount;
}
public Integer getIsFreeDelivery() {
return isFreeDelivery;
}
public void setIsFreeDelivery(Integer isFreeDelivery) {
this.isFreeDelivery = isFreeDelivery;
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
}<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="goods">
<!--namespace有点类似于Java中的package-->
<select id="selectAll" resultType="com.imooc.mybatis.entity.Goods">
<!-- id相当于select语句的别名 -->
select * from t_goods order by goods_id desc limit 10
</select>
<select id="selectById" parameterType="Integer" resultType="com.imooc.mybatis.entity.Goods">
select * from babytun.t_goods where goods_id=#{value}
</select>
<insert id="insert" parameterType="com.imooc.mybatis.entity.Goods">
INSERT INTO t_goods(title,sub_title,original_cost,current_price,discount,is_free_delivery,category_id)
VALUES (#{title},#{sub_title},#{original_cost},#{current_price},#{discount},#{is_free_delivery},#{category_id})
</insert>
</mapper>package com.imooc.mybatis;
import com.imooc.mybatis.entity.Goods;
import com.imooc.mybatis.utils.MyBatisUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.util.List;
public class MyBatisTestor {
@Test
public void insertTest()throws Exception{
SqlSession session = null;
try {
session = MyBatisUtils.openSession();
Goods goods = new Goods();
goods.setTitle("test");
goods.setSubTitle("1234");
goods.setOriginalCost(2000f);
goods.setCurrentPrice(1000f);
goods.setDiscount(0.5f);
goods.setIsFreeDelivery(1);
goods.setCategoryId(43);
int num = session.insert("goods.insert",goods);
System.out.println(num);
session.commit();
System.out.println(goods.getGoodsId());
}catch (Exception e){
if(session!=null){
session.rollback();
}
throw e;
}finally {
MyBatisUtils.closeSession(session);
}
}
}package com.imooc.mybatis.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.Reader;
//MyBatisUtils工具类,创建全局唯一的sqlSessionFactory对象
public class MyBatisUtils {
//利用static属于类不属于对象,且全局唯一
private static SqlSessionFactory sqlSessionFactory;
//利用静态块在初始化类时
static {
Reader reader;
try {
reader = Resources.getResourceAsReader("mybatis-config.xml");
//如果xml文件名写错了,会出现IOException:Counld not find resouce mybatis1-config.xml
//也会出现NoClassDefFoundError:Could not initialize class com.imooc.mybatis.utils.MyBatisUtils
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
} catch (IOException e) {
e.printStackTrace();
//初始化错误时,通过抛出异常ExceptionInInitializerError通知调用者
throw new ExceptionInInitializerError(e);
}
}
public static SqlSession openSession(){
return sqlSessionFactory.openSession();
}
public static void closeSession(SqlSession session){
if(session != null) {
session.close();
}
}
}<?xml version="1.0" encoding="UTF-8" ?> <!--文件名可以任意,文件类型一定要是xml文件--> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <!--mybatis.org官网-入门里copy dtd --> <configuration> <settings> <!--可以把数据库中的字段如goods_id ==>goodsId --> <setting name="mapUnderscoreToCamelCase" value="true"/> </settings> <environments default="dev"> <!--default属性设置默认使用的数据库--> <environment id="dev"> <!--采用JDBC对数据库对事务commit/rollback--> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <!--使用连接池对数据进行管理--> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=utf-8"/> <property name="username" value="root"/> <property name="password" value="abc123456"/> </dataSource> </environment> <environment id="prd"> <!--采用JDBC对数据库对事务commit/rollback--> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://192.168.1.155:3306/babytun?useUnicode=true&characterEncoding=utf-8"/> <property name="username" value="root"/> <property name="password" value="abc123456"/> </dataSource> </environment> </environments> <mappers> <mapper resource="mappers/goods.xml"/> <!--<mapper resource="mappers/student.xml"/>--> </mappers> </configuration>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.imooc</groupId> <artifactId>mybatis</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <repository> <id>aliyun</id> <name>aliyun</name> <url>https://maven.aliyun.com/repository/public</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.9</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.26</version> </dependency> </dependencies> </project>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="goods">
<!--namespace有点类似于Java中的package-->
<select id="selectAll" resultType="com.imooc.mybatis.entity.Goods">
<!-- id相当于select语句的别名 -->
select * from t_goods order by goods_id desc limit 10
</select>
<select id="selectById" parameterType="Integer" resultType="com.imooc.mybatis.entity.Goods">
select * from babytun.t_goods where goods_id=#{value}
</select>
<insert id="insert" parameterType="com.imooc.mybatis.entity.Goods">
INSERT INTO t_goods(title,sub_title,original_cost,current_price,discount,is_free_delivery,category_id)
VALUES (#{title},#{sub_title},#{original_cost},#{current_price},#{discount},#{is_free_delivery},#{category_id})
</insert>
</mapper>5
收起
正在回答 回答被采纳积分+1
1回答
好帮手慕小脸
2022-03-11 16:33:50
java工程师2020版
- 参与学习 人
- 提交作业 9410 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星