1.sql语句复用
select
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nowcoder.community.dao.UserMapper">
<sql id="selectFields" >
id,
user_name,
password,
salt,
email,
type,
status,
activation_code,
header_url,
create_time
</sql>
<select id="selectById" resultType="User">
select <include refid="selectFields"></include>
from user
where id = #{id}
</select>
<select id="selectByName" resultType="User">
select <include refid="selectFields"></include>
from user
where user_name = #{userName}
</select>
<select id="selectByEmail" resultType="User">
select <include refid="selectFields"></include>
from user
where email = #{email}
</select>
</mapper>
**2.**id="insertFields">
<sql id="insertFields">
user_name, password, salt, email, type, status, activation_code, header_url, create_time
</sql>
<insert id="insertUser" parameterType="User" keyProperty="id">
insert into user (<include refid="insertFields"></include>)
values (#{userName},#{password},#{salt},#{email},
#{type},#{status},#{activationCode},#{headerUrl},#{createTime})
</insert>
注意:#{activationCode},#{headerUrl},#{createTime})
3.update
<update id="updateStatues">
update user set status = #{status}
where id = #{id}
</update>
<update id="updateHeaderUrl">
update user set header_url = #{HeaderUrl}
where id = #{id}
</update>
<update id="updatePassword">
update user set password = #{password} where id = #{id}
</update>
4.SQL语句
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nowcoder.community.dao.DiscussPostMapper">
<sql id="selectFields">
id,user_id,title,content,type,status,create_time,comment_count,score
</sql>
<select id="selectDiscussPosts" resultType="DiscussPost">
select
<include refid="selectFields"></include>
from discuss_post
where status != 2
<if test="userId != 0">
and user_id = #{userId}
</if>
order by type desc, create_time desc
limit #{offset}, #{limit}
</select>
<select id="selectDiscussPostRows" resultType="int">
select count(id) from discuss_post
<if test="userId != 0">
where user_id = #{userId}
</if>
</select>
</mapper>
5.index页面
<html lang="en" xmlns:th = "http://www.thymeleaf.org">
<link rel="stylesheet" th:href="@{/css/global.css}"/>
<script th:src= "@{/js/global.js}"></script>
<script th:src="@{/js/index.js}"></script>
6.An error happened during template parsing (template: "class path resource [templates//index.html]")
**'!=', '%', '&&', '(', '*', '+', '+=', '-', '.', '/', <, <=, '==', '>', '>=', '?', '?.', '?:', and, div, eq, ge, gt, le, lt, mod, ne, or, '||' or '}' expected, got '.'
**
模板解析错误
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "page.current==page.tatal?'disabled':''" (template: "/index" - line 157, col 11)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "page.current==page.tatal?'disabled':''" (template: "/index" - line 157, col 11)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'tatal' cannot be found on object of type 'com.nowcoder.community.entity.Page' - maybe not public or not valid?从错误信息中可以看出,你使用了一个不存在的属性名 tatal(可能是打字错误),而实际上在你的Page类中并没有定义名为 tatal 的属性。
8.邮件发送错误spring.mail.password=授权码
#mail配置
spring.mail.host=smtp.sina.com
spring.mail.port=465
spring.mail.username=nowcoderyouxiang@sina.com
spring.mail.password=授权码
spring.mail.protocol=smtps
spring.mail.properties.mail.smtp.ssl.enable=true