utf8mb3和utf8mb4的区别在于:utf8mb3最多使用3个字节来表示1个字符,utf8mb4最多使用4个字节来表示1个字符;因此utf8mb4可以表示更多字符,如生僻汉字、冷门符号、emoji表情符号等。在MySQL / MariaDB中,最好都使用utf8mb4,尽量不要使用utf8。
<!-- mysql依赖 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
这样写报错的原因可能是:父文件中指定了该依赖的版本,但是仓库中没有这个版本的依赖,所以再加上仓库中有的版本号就行了。 改为:
<!-- mysql依赖 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
</dependency>
里这部分报错的原因可能是: 因为版本号错了,加一个和上面的2.7.12一致就行了。
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
没有"/"是相对路径;有"/"是绝对路径。 @RequestMapping("/index/goods")里面的第一个"/"表示项目根目录。
直接进入jsp页面没有数据,应当先通过服务将需要用到的数据存入HttpServletRequest
中,然后jsp中使用HttpServletRequest
中的数据,这样加载出来的页面才会有用。
eg:
//选择商品分类
request.setAttribute("flag",2);
//获取商品分类列表
List<Type> types = typeService.getTypeList();
//把商品分类列表存入request中,供页面使用
request.setAttribute("typeList",types);
//获取商品分类的信息
Type type = typeService.getTypeById(typeid);
request.setAttribute("type",type);
//获取属于该类的商品列表
List<Goods> goodsList = goodsService.getGoodsListByTypeId(typeid,page,size);
request.setAttribute("goodList",goodsList);
return "/index/goods.jsp";
<c:forEach var="type" items="${typeList}">
<li><a class="list" href="goods?typeid=${type.id}&page=1&size=16">${type.name}</a></li>
</c:forEach>
jsp文件使用HttpServletRequest
中的数据的方式${typeList}
,也就是${***}
。
项目无法启动,一直报错说是找不到bean
;bean
注入失败;使用@Autowired
自动装配失败,最后将springboot版本号有2.6.1更改为2.7.12后可以成功运行,猜测是版本兼容问题。
<resultMap id="goodsMap" type="goods">
<id column="id" property="id"></id>
<association column="type_id" property="type" fetchType="lazy"
select="com.lanou.yoyoshop.mapper.TypeMapper.selectTypeById"></association>
</resultMap>
注意:以上代码的select=""
中,不能有换行或者空格,否则会报错。