Java程序员用下班时间给学弟做了一个在线考试系统_使用schema搭建考试后台管理系统

<%@ page language=“java” contentType=“text/html; charset=UTF-8”%>
<%@ include file=“/base.jsp”%>

登录 -${websitemap.web.company}-${websitemap.web.title}
<div class="b-box">
	<div id="container">
		<div id="box">
			<h2>在线考试后台管理系统</h2>
			<form action="${ctx}/admin/main/login" method="POST" id="loginForm">
				<p class="main">
					<label>用户名: </label>
					<input name="sysUser.loginName" onkeyup="enterSubmit(event)" value="${sysUser.loginName}" placeholder="输入用户名" />
					<label>密码: </label>
					<input type="password" onkeyup="enterSubmit(event)" name="sysUser.loginPwd" value="${sysUser.loginPwd}" placeholder="输入密码">
				</p>
				<p class="main">
					<label>验证码: </label>
					<input name="randomCode" onkeyup="enterSubmit(event)" placeholder="验证码" style="width: 105px;"  maxlength="4"/>
					<span class="yzm-pic">
						<img src="${ctx}/ran/random" alt="验证码,点击图片更换" onclick="this.src='${ctx}/ran/random?random='+Math.random();" />
					</span>
				</p>
				<p class="space">
					<input type="submit" value="登录" class="login" />
					<span>${message}</span>
				</p>
			</form>
		</div>
		<div class="login-foot">
			<span>
				Powered By <a target="_blank" href="#" style="color: #666;">IT邦德</a>
			</span>
		</div>
	</div>
</div>

### 4.2 修改学员信息


#### 4.2 .1 Controller



/**
* 修改学员信息
*/
@RequestMapping(“/updateUserInfo”)
@ResponseBody
public Map<String, Object> updateUserInfo(HttpServletRequest request,
@ModelAttribute(“user”) User user) {
Map<String, Object> json = new HashMap<String, Object>();
try {
if (user.getUserId() > 0) {
if (user.getShowName() == null || user.getShowName() == “”) {
json = this.setJson(false, “姓名不能为空!”, null);
return json;
}
if (user.getEmail() != null
&& user.getEmail().trim().length() > 0
&& !WebUtils.checkEmail(user.getEmail(), 50)) {
json = this.setJson(false, “请输入正确的邮箱号”, null);
return json;
}
if (user.getMobile() != null
&& user.getMobile().trim().length() > 0
&& !WebUtils.checkMobile(user.getMobile())) {
json = this.setJson(false, “请输入正确的电话号”, null);
return json;
}
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
String startDate=user.getStartDate();
user.setShiftTime(sdf.parse(startDate));
userService.updateUser(user);
json = this.setJson(true, “学员修改成功”, null);
} else {
json = this.setJson(false, “修改失败”, null);
}
} catch (Exception e) {
this.setAjaxException(json);
logger.error(“udpateUser()–error”, e);
}
return json;
}


#### 4.2.2 Service



public interface UserService {
/**
* 创建用户
* @param user
* @return 返回用户ID
*/
public int createUser(User user);

/**
 * 通过用户ID查询用户
 * @param userId 用户不D
 * @return User
 */
public User queryUserById(int userId);


/**
 * 检测用户工号是否存在 
 * @param username 工号
 * @return  true存在 false不存在 
 */
public boolean checkuserName(String username);

/**
 * 检测手机是否存在 
 * @param mobile 手机号
 * @return true存在 false不存在 
 */
public boolean checkMobile(String mobile);

#### 4.2.3 ServiceImpl



@Service(“userService”)
public class UserServiceImpl implements UserService{

@Autowired
private UserDao userDao;

@Autowired
private SysDictService sysDictService;

@Autowired
private UserGroupService userGroupService;

public int createUser(User user) {
	return userDao.createUser(user);
}


public User queryUserById(int userId) {
	return userDao.queryUserById(userId);
}


public boolean checkMobile(String mobile) {
	int count = userDao.checkMobile(mobile);
	if(count>0){
		return true;
	}
	return false;
}

public boolean checkuserName(String username) {
	int count = userDao.checkuserName(username);
	if(count>0){
		return true;
	}
	return false;
}

#### 4.2.4 dao



public interface UserDao {
/**
* 创建用户
* @param user
* @return 返回用户ID
*/
public int createUser(User user);

/**
 * 通过用户ID查询用户
 * @param userId 用户不D
 * @return User
 */
public User queryUserById(int userId);

/**
 * 检测手机是否存在 
 * @param mobile 手机号
 * @return 返回记录数
 */
public int checkMobile(String mobile);


/**
 * 检测工号是否存在 
 * @param username 工号
 * @return 返回记录数
 */
public int checkuserName(String username);
/**
 * 检测邮箱号是否存在 
 * @param email 邮箱号
 * @return 返回记录数
 */
public int checkEmail(String email);

#### 4.2.5 UserMapper



<?xml version="1.0" encoding="UTF-8"?>
<!-- 分页查询用户列表,开始 -->
<select id="queryUserListPage" parameterType="java.util.Map" resultMap="UserResult">
SELECT <include refid="edu_user_column"/> FROM EDU_USER 
<where>
	<if test="e.isavalible>0">
	EDU_USER.IS_AVALIBLE=#{e.isavalible}
	</if>
    <if test="e.usergroup!=null and e.usergroup!=''">
	AND (EDU_USER.USERGROUP LIKE CONCAT('%',#{e.usergroup},'%'))
	</if>
	<if test="e.keyWord!=null and e.keyWord!=''">
	AND (EDU_USER.MOBILE LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.EMAIL LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.USER_NAME LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.SHOW_NAME LIKE CONCAT('%',#{e.keyWord},'%'))
	</if>
	<if test="e.beginCreateTime!=null and e.beginCreateTime!=''">
		AND EDU_USER.CREATE_TIME >= #{e.beginCreateTime}
	</if>
	<if test="e.endCreateTime!=null and e.endCreateTime!=''">
		AND <![CDATA[EDU_USER.CREATE_TIME <= #{e.endCreateTime}]]>
	</if>
</where>
<include refid="publicMapper.pageEnd"/>
</select>
<select id="queryUserListPageCount" parameterType="java.util.Map" resultType="int">
SELECT COUNT(1) FROM EDU_USER 
<where>
	<if test="e.isavalible>0">
	EDU_USER.IS_AVALIBLE=#{e.isavalible}
	</if>
    <if test="e.usergroup!=null and e.usergroup!=''">
	AND (EDU_USER.USERGROUP LIKE CONCAT('%',#{e.usergroup},'%'))
	</if>
	<if test="e.keyWord!=null and e.keyWord!=''">
	AND (EDU_USER.MOBILE LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.EMAIL LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.USER_NAME LIKE CONCAT('%',#{e.keyWord},'%') OR EDU_USER.SHOW_NAME LIKE CONCAT('%',#{e.keyWord},'%'))
	</if>
	<if test="e.beginCreateTime!=null and e.beginCreateTime!=''">
		AND EDU_USER.CREATE_TIME >= #{e.beginCreateTime}
	</if>
	<if test="e.endCreateTime!=null and e.endCreateTime!=''">
		AND <![CDATA[EDU_USER.CREATE_TIME <= #{e.endCreateTime}]]>
	</if>
</where>
</select>
<!-- 分页查询用户列表,结束-->	
<select id="queryUserByUserName" parameterType="java.lang.String" resultMap="UserResult">
SELECT <include refid="edu_user_column"/> FROM EDU_USER
<where>
	EDU_USER.USER_NAME = #{value}
</where>
</select>

<!-- 冻结或解冻用户 -->
<update id="updateUserStates" parameterType="User">
UPDATE EDU_USER SET EDU_USER.IS_AVALIBLE=#{isavalible} WHERE EDU_USER.USER_ID=#{userId}
</update>

<!-- 修改用户信息 -->
<update id="updateUser" parameterType="User">
UPDATE EDU_USER SET 
EDU_USER.SHOW_NAME=#{showName},
EDU_USER.USERGROUP=#{usergroup},
EDU_USER.SECTION=#{section},
EDU_USER.EMAIL=#{email},
EDU_USER.MOBILE=#{mobile},
EDU_USER.SEX=#{sex},
EDU_USER.AGE=#{age},
EDU_USER.SHIFT_DATE=#{shiftTime},
EDU_USER.FREQUENCY=#{frequency}
WHERE EDU_USER.USER_ID=#{userId}
</update>

<!-- 修改用户头像 -->
<update id="updateImg" parameterType="User">
UPDATE EDU_USER SET 
EDU_USER.PIC_IMG=#{picImg}
WHERE EDU_USER.USER_ID=#{userId}
</update>

<!-- 修改个中心个性化图片URL -->
<update id="updateUserBannerUrl" parameterType="User">
UPDATE EDU_USER SET BANNER_URL=#{bannerUrl} WHERE USER_ID=#{userId}
</update>

<!-- 查询所有学员记录数 -->
<select id="queryAllUserCount" resultType="int">
SELECT COUNT(1) FROM EDU_USER
</select>

<!-- 通过手机号或邮箱号查询用户信息 -->
<select id="queryUserByEmailOrMobile" parameterType="java.lang.String" resultMap="UserResult">
SELECT <include refid="edu_user_column"/> FROM EDU_USER WHERE EMAIL=#{value} OR MOBILE=#{value} LIMIT 1
</select>

<!-- 根据多个用户id获取用户信息 -->
<select id="queryCustomerInCusIds" parameterType="java.util.HashMap" resultMap="UserResult">
	select
	<include refid="edu_user_column"/>
	from EDU_USER 
	where EDU_USER.USER_ID in
	<foreach collection="list" index="index" item="item" open="(" separator="," close=")">  
    	#{item}  
	</foreach>  
</select>
<select id="getUserListPage" resultMap="UserResult" parameterType="java.util.HashMap">
	select
	<include refid="edu_user_column" />
	from edu_user
	<where>
		<if test="e.userId !=null and e.userId > 0 ">
			AND EDU_USER.USER_ID = #{e.userId}
		</if>
		<if test="e.email !=null and e.email !='' ">
			AND EDU_USER.EMAIL like CONCAT('%',#{e.email},'%')
		</if>
		<if test="e.mobile !=null and e.mobile !='' ">
			AND EDU_USER.MOBILE like CONCAT('%',#{e.mobile},'%')
		</if>
		<if test="e.userName !=null and e.userName !='' ">
			AND EDU_USER.USER_NAME like CONCAT('%',#{e.userName},'%')
		</if>
		<if test="e.showName !=null and e.showName !='' ">
			AND EDU_USER.SHOW_NAME like CONCAT('%',#{e.showName},'%')
		</if>
		<if test="e.sex !=null and e.sex > 0 ">
			AND EDU_USER.SEX=#{e.sex}
		</if>
	</where>
	order by EDU_USER.USER_ID desc
	<include refid="publicMapper.pageEnd" />
</select>
<select id="getUserListPageCount" resultType="int" parameterType="java.util.HashMap">
	select
	count(1)
	from edu_user
	<where>
		<if test="e.userId !=null and e.userId > 0 ">
			AND EDU_USER.USER_ID = #{e.userId}
		</if>
		<if test="e.email !=null and e.email !='' ">
			AND EDU_USER.EMAIL like CONCAT('%',#{e.email},'%')
		</if>
		<if test="e.mobile !=null and e.mobile !='' ">
			AND EDU_USER.MOBILE like CONCAT('%',#{e.mobile},'%')
		</if>
		<if test="e.userName !=null and e.userName !='' ">
			AND EDU_USER.USER_NAME like CONCAT('%',#{e.userName},'%')
		</if>
		<if test="e.showName !=null and e.showName !='' ">
			AND EDU_USER.SHOW_NAME like CONCAT('%',#{e.showName},'%')
		</if>
		<if test="e.sex !=null and e.sex > 0 ">
			AND EDU_USER.SEX=#{e.sex}
		</if>
	</where>
</select>

<!-- 删除学员 -->
<delete id="deleteUserById" parameterType="int">
	DELETE FROM EDU_USER WHERE EDU_USER.USER_ID = #{value}
</delete>

### 五 、框架其他配置


### 5.1 数据库配置


project.properties



#数据库主机地址
jdbc.host=localhost
#数据库名
jdbc.database=learn
#用户名
jdbc.username=root
#密码
jdbc.password=root

#项目路径
contextPath=http://localhost:80


### 5.2、配置spring-mvc.xml


配置里面的注释也很详细,主要是自动扫描控制器,视图模式,注解的启动这三个。



<?xml version="1.0" encoding="UTF-8"?>

<!-- ①:对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.inxedu.os"
	use-default-filters="false">
	<context:include-filter type="annotation"
		expression="org.springframework.stereotype.Controller" />
	<context:include-filter type="annotation"
		expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>

<mvc:annotation-driven
	content-negotiation-manager="contentNegotiationManager">
	<mvc:message-converters register-defaults="true">
		<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
		<bean class="org.springframework.http.converter.StringHttpMessageConverter">
			<constructor-arg value="UTF-8" />
		</bean>
	</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler />
<!-- ②:拦截器的配置 -->
<mvc:interceptors>
	<!-- 后台登录和权限的拦截器配置 -->
	<mvc:interceptor>
		<mvc:mapping path="/admin/*" />
		<mvc:mapping path="/admin/**/*" />
		<mvc:exclude-mapping path="/admin/main/login" />
		<bean class="com.inxedu.os.common.intercepter.IntercepterAdmin"></bean>
	</mvc:interceptor>
	<!-- 前台网站配置拦截器配置 -->
	<mvc:interceptor>
		<mvc:mapping path="/**/*" />
		<mvc:exclude-mapping path="/static/**/*" />
		<mvc:exclude-mapping path="/*/ajax/**" />
		<mvc:exclude-mapping path="/kindeditor/**/*" />
		<bean class="com.inxedu.os.common.intercepter.LimitIntercepterForWebsite">
		</bean>
	</mvc:interceptor>
	<!-- 前台用户登录拦截器配置 -->
	<mvc:interceptor>

最后

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

bean>
</mvc:interceptor>

mvc:interceptor
<mvc:mapping path=“//*" />
<mvc:exclude-mapping path="/static/
/" />
<mvc:exclude-mapping path="/
/ajax/" />
<mvc:exclude-mapping path="/kindeditor/
/*” />


</mvc:interceptor>

mvc:interceptor

最后

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 25
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值