Springboot数码电子购物商城实战错误集锦

配置相关

1、开启mybatis的驼峰命名规则没有生效
首先是在config代码中进行配置,但是没有生效(应该是可能代码写入的时候有错误),因为大佬说,代码只是xml的一种形式,xml的其实还是代码加载进去的。
然后在application.yml中配置,报错,说configuration和configLocation不能同时出现,什么鬼的。
后来在mybatis-config.xml中配置如下代码

<settings>
        <setting name="mapUnderscoreToCamelCase" value="true" />
 </settings>

2、Spring 是有缓存机制的,
也就是说,在服务不重启的情况下,你去变动修改这些资源文件,去页面查看,不会发生改变,这个时候需要在application.properties中进行如下配置

spring.thymeleaf.cache=false

thymeleaf的使用

1、用户登录成功后,在页面显示用户名
登录成功后,把用户名存入到了session中,在页面进行获取的时候th:text="${session.user_session}"
在使用th:if标签进行判断时,只能进行一次判断,不能使用或和与运算

2、使用th:href标签进行url的更改
th:href="@{toMyOrder?pn=}+${pageInfo.pageNum+1}"可以加参数

3、使用th:if进行判断

<li class="" th:if="${session.user_session}!=null">
    <a id="exit_user" role="button" style="padding-right:0"><span class="btn btn-large btn-success">退出</span></a>
</li>
<li class="" th:if="${session.user_session}==null">
    <a href="#" role="button" data-toggle="login_modal" style="padding-right:0"><span id="login_index_btn" class="btn btn-large btn-success" >登录</span></a>
</li>                    

4、传参的方式(3种)
1、路径后面自己添加参数th:href="@{toMyOrder?productId=2}",这个时候使用的是@RequestParam注解

@RequestMapping("/productDetails")
    public String toProductDetailsPage(@RequestParam("productId") Integer productId, Model model){}

2、路径传参,th:href="@{/toMyOrder/2}",这个时候绑定到参数的时候使用的是@PathVariable注解

@GetMapping("/emp/{id}")
    public String editEmp(@PathVariable("id") Integer id , Model model){
        System.out.println(id);

3、在controller中使用request

 String productName=request.getParameter("productName");
 String categoryId = request.getParameter("categoryId");

Ajax的使用(成功后的回调函数里)

1、实现页面的跳转(可以加参数)

//可以访问controller
window.location.href="toProductOrder?orderId="+orderId;
//可以跳转页面(在springboot中,这种也相当于是通过controller进行跳转的)
window.location.href="index.html";

2、也可以使页面重新加载

location.reload(true);

数据库相关

1、日期的转换
由于实体类的Data是java.util的,当传入数据库时要进行转换

Timestamp timestamp = new Timestamp(new Date().getTime());
order.setOrderTime(timestamp);

2、数据库日期的显示精确到时分秒
这个时候要把数据库中时间那一列的类型设置为datetime,而不是date

对于错误的检查

1、如果参数没有传递过去,那就在前台用js,看是否能获取的到
2、使用pageHelp分页插件的时候要记得引入依赖

猜你喜欢

转载自blog.csdn.net/ilikejj0/article/details/81475709