例如,上图所示,
【用户工资表】现有字段为用户id,用户工资,生效时间,备注信息
这些字段也就是你设计数据库时,数据库工资表字段
,现在,要让显示这个页面,增加一个用户姓名信息
做法:
1.首先,domain实体类添加这个字段,并alt+insert(这是我电脑的快捷键,你的不一定是这个),生成对应set get方法,
/**
* 用户名字
*/
@Excel(name = "用户名字")
private String userName;
在在tostring方法下增加:
.append("userName", getUserName())
2.接着,去mapper.xml数据库查询语句,里面,查增修改里面都加上username参数(你要添加的参数)
<?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="com.jhsoft.product.extra.mapper.TExtraMapper">
<resultMap type="TExtra" id="TExtraResult">
<result property="extraId" column="extra_id" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="extraSalary" column="extra_salary" />
<result property="type" column="type" />
<result property="remark" column="remark" />
<result property="effectTime" column="effect_time" />
<result property="createTime" column="create_time" />
</resultMap><sql id="selectTExtraVo">
select extra_id, user_id, user_name,extra_salary, type, remark, effect_time, create_time from t_extra
</sql><select id="selectTExtraList" parameterType="TExtra" resultMap="TExtraResult">
<include refid="selectTExtraVo"/>
<where>
<if test="userId != null and userId != ''"> and user_id = #{userId}</if>
<if test="userName != null and userName != ''"></if>
<if test="extraSalary != null "> and extra_salary = #{extraSalary}</if>
<if test="type != null "> and type = #{type}</if>
<if test="effectTime != null "> and effect_time = #{effectTime}</if>
</where>
</select>
<select id="selectTExtraByExtraId" parameterType="Long" resultMap="TExtraResult">
<include refid="selectTExtraVo"/>
where extra_id = #{extraId}
</select>
<insert id="insertTExtra" parameterType="TExtra" useGeneratedKeys="true" keyProperty="extraId">
insert into t_extra
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>
<if test="userName != null">user_name,</if>
<if test="extraSalary != null">extra_salary,</if>
<if test="type != null">type,</if>
<if test="remark != null">remark,</if>
<if test="effectTime != null">effect_time,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="userName != null">#{userName},</if>
<if test="extraSalary != null">#{extraSalary},</if>
<if test="type != null">#{type},</if>
<if test="remark != null">#{remark},</if>
<if test="effectTime != null">#{effectTime},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert><update id="updateTExtra" parameterType="TExtra">
update t_extra
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if>
<if test="userName != null">user_name = #{userName},</if>
<if test="extraSalary != null">extra_salary = #{extraSalary},</if>
<if test="type != null">type = #{type},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="effectTime != null">effect_time = #{effectTime},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where extra_id = #{extraId}
</update><delete id="deleteTExtraByExtraId" parameterType="Long">
delete from t_extra where extra_id = #{extraId}
</delete><delete id="deleteTExtraByExtraIds" parameterType="String">
delete from t_extra where extra_id in
<foreach item="extraId" collection="array" open="(" separator="," close=")">
#{extraId}
</foreach>
</delete></mapper>
3.数据库里面加上这个字段(这是另一个表,也是做的同样操作,增加姓名字段)
到这为止,后台代码操作完成,然后改页面代码
4.页面上先改哪个页面顺序其实都可以
add.html
添加下面这段代码:
<div class="form-group">
<label class="col-sm-3 control-label">用户名字:</label>
<div class="col-sm-8">
<input name="userName" class="form-control" type="text" readonly="true"
οnclick="selectWxUser()" required><!--员工id-->
<!-- <input name="userName" class="form-control" type="text">-->
</div>
</div>
来个例子把:
edit.html
添加代码:
<div class="form-group">
<label class="col-sm-3 control-label">用户名字:</label>
<div class="col-sm-8">
<input name="userName" class="form-control" type="text" readonly="true"
οnclick="selectWxUser()" required><!--员工id-->
<!-- <input name="userName" th:field="*{userName}" class="form-control" type="text">-->
</div>
</div>
html.html
添加代码:
<li>
<label>用户名字:</label>
<input type="text" name="userName"/>
</li>
{
field: 'userName',
title: '用户名字'
}