兄弟们,我又回来啦!

上次我把表建完了。今天来点干货,我们用ssm框架来先简单实现一下管理员的登录功能。

在实现之前,我对user表(管理员表)做了些简单的修改,先来看看:

忽略哪些蓝色的马赛克和乱输的数据,这个表一共5个字段,useraccountnum为账号,其他的都应该能看出来是什么。当然这里还是要说一句,这不是最终的表结构,以后根据需求还会修改的。

那么表有了,开始创建一个动态网页项目,这里我用的eclipse,项目是导的包,包如下:

本来想用maven配置包的,但想到自己对maven用的不熟练,算了,下次用maven做。

建好目录,项目结构如下:

项目名是pls,取得是parts,Library,System三个单词的首字母。服务器用的tomcat9,我觉得挺好用的。比myeclipse自带的服务器不知道快到哪里去了。

首先来看web.xml,代码如下:

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>pls</display-name>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> <!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/applicationContext.xml,/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Spring MVC servlet -->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/springmvc.xml</param-value>
</init-param>
<!--
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
-->
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list> </web-app>

感觉没什么好说的,用处注释都写了,看下一项,config文件夹的目录结构:

一样一样来,先是applicationContext.xml:

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd "> <!-- 加载配置文件 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 使用第三方的数据库连接池dbcp -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 开发阶段数据库最大连接数建议设置小一点够用即可,设置为3 -->
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
</bean> <!-- 事务管理 --> <!-- 事务管理器
mybatis使用jdbc事务管理
-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 配置传播行为 -->
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice> <!-- aop配置 -->
<aop:config>
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.pls.service.imp.*.*(..))"/>
</aop:config> </beans>

然后是applicationContext-dao.xml:

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd "> <!-- 配置SqlSessionFactory -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 配置SqlMapConfig.xml -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
</bean> <!-- 配置userDao -->
<!-- <bean id="userDao" class="cn.itcast.ssm.dao.old.UserDaoImpl">
注入会话工厂
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"/>
</bean> --> <!-- mapper动态代理 -->
<!-- 配置userMapper
MapperFactoryBean:用于生成 代理对象
-->
<!-- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
注入会话工厂
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"/>
mapper接口
<property name="mapperInterface" value="cn.itcast.ssm.dao.mapper.UserMapper"/>
</bean> --> <!-- 使用mapper批量扫描器扫描mapper接口
规则:mapper.xml和mapper.java在一个目录 且同名即可
扫描出来mapper,自动让spring容器注册,bean的id就是mapper类名(首字母小写)
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 会话工厂 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"/>
<!-- 扫描包路径
多个包中间用半角逗号分隔
-->
<property name="basePackage" value="com.pls.mapper"/>
</bean> </beans>

这是以前学的时候用的配置文件,改了改继续拿来用,所以有大量注释掉的代码(我舍不得删.)

applicationContext-service.xml:

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd "> <!-- 用户管理 --> <bean id="plsService" class="com.pls.service.imp.PlsServiceImp"/> </beans>

这里我本来想用注解代替的,但不知怎么的注解没起作用,无法完成注入,有大神的话希望看到后面能为我指出原因。

springmvc-xml:

 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd "> <!-- 组件扫描 只扫描action -->
<context:component-scan base-package="com.pls.controller" /> <!-- 使用<mvc:annotation-driven />替换上边定义的处理器映射器和适配器 -->
<mvc:annotation-driven /> <!-- 视图解析器 解析jsp视图,默认使用jstl,要求classpath下有jstl的jar包 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 视图的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 视图的后缀 -->
<property name="suffix" value=".jsp" /> </bean> <!--拦截器 -->
<mvc:interceptors> <mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="interceptor.LoginInterceptor"></bean>
</mvc:interceptor> </mvc:interceptors> </beans>

还有:sqlmapconfig.xml:

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <!-- 定义别名 -->
<typeAliases>
<package name="com.pls.po" />
</typeAliases>
<!-- 配置mapper映射文件 -->
<mappers>
<!-- 加载 原始dao使用映射文件 -->
<!-- <mapper resource="sqlmap/User.xml" /> --> <!--批量mapper扫描 遵循规则:将mapper.xml和mapper.java文件放在一个目录 且文件名相同 -->
<!-- <package name="cn.itcast.ssm.dao.mapper" /> -->
</mappers>
</configuration>

为什么<mappers>内没有代码?回去看dao的xml。

接下来是mapper的目录和po的目录:

这里共有八张表的接口和pojo,今天要涉及到的只有红圈的选中的部分。

这些mapper和pojo不全是自己写的,大部分还是利用mybatis的逆向工程生成的,生成的配置文件如下:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/partslibrarysystem" userId="root"
password="202011">
</jdbcConnection>
<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
userId="yycg"
password="yycg">
</jdbcConnection> --> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <!-- targetProject:生成PO类的位置 --> <javaModelGenerator targetPackage="com.pls.po"
targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" />
</javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.pls.mapper"
targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.pls.mapper"
targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 -->
<table schema="" tableName="allsortparts"></table>
<table schema="" tableName="user"></table>
<table schema="" tableName="bearing"></table>
<table schema="" tableName="coupling"></table>
<table schema="" tableName="electromotor"></table>
<table schema="" tableName="fastener"></table>
<table schema="" tableName="flange"></table>
<table schema="" tableName="sealing_element"></table> <!-- 有些表的字段需要指定java类型
<table schema="" tableName="">
<columnOverride column="" javaType="" />
</table> -->
</context>
</generatorConfiguration>

还需要这个java类:

 package gm;

 import java.io.File;
import java.util.ArrayList;
import java.util.List; import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback; public class GeneratorSqlmap { public void generator() throws Exception{ List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
//指定逆向工程配置文件。
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null); }
public static void main(String[] args) throws Exception {
try {
GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
generatorSqlmap.generator();
} catch (Exception e) {
e.printStackTrace();
} } }

运行这个文件,mapper和pojo就自动帮你生成了,是不是很方便。

看一看mapper.xml和dao接口吧:

 package com.pls.mapper;

 import com.pls.po.User;
import com.pls.po.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Param; public interface UserMapper {
int countByExample(UserExample example); int deleteByExample(UserExample example); int deleteByPrimaryKey(Integer iduser); int insert(User record); int insertSelective(User record); List<User> selectByExample(UserExample example); User selectByPrimaryKey(Integer iduser); int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example); int updateByExample(@Param("record") User record, @Param("example") UserExample example); int updateByPrimaryKeySelective(User record); int updateByPrimaryKey(User record); User selectByUseraccountnum(String useraccountnum); List<User> getAllUser(); }
 <?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.pls.mapper.UserMapper" >
<resultMap id="BaseResultMap" type="com.pls.po.User" >
<id column="iduser" property="iduser" jdbcType="INTEGER" />
<result column="username" property="username" jdbcType="VARCHAR" />
<result column="userpassword" property="userpassword" jdbcType="VARCHAR" />
<result column="useraccountnum" property="useraccountnum" jdbcType="VARCHAR" />
<result column="useremail" property="useremail" jdbcType="VARCHAR" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
iduser, username, userpassword, useraccountnum, useremail
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.pls.po.UserExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from user
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from user
where iduser = #{iduser,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from user
where iduser = #{iduser,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.pls.po.UserExample" >
delete from user
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.pls.po.User" >
insert into user (iduser, username, userpassword,
useraccountnum, useremail)
values (#{iduser,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{userpassword,jdbcType=VARCHAR},
#{useraccountnum,jdbcType=VARCHAR}, #{useremail,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.pls.po.User" >
insert into user
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="iduser != null" >
iduser,
</if>
<if test="username != null" >
username,
</if>
<if test="userpassword != null" >
userpassword,
</if>
<if test="useraccountnum != null" >
useraccountnum,
</if>
<if test="useremail != null" >
useremail,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="iduser != null" >
#{iduser,jdbcType=INTEGER},
</if>
<if test="username != null" >
#{username,jdbcType=VARCHAR},
</if>
<if test="userpassword != null" >
#{userpassword,jdbcType=VARCHAR},
</if>
<if test="useraccountnum != null" >
#{useraccountnum,jdbcType=VARCHAR},
</if>
<if test="useremail != null" >
#{useremail,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.pls.po.UserExample" resultType="java.lang.Integer" >
select count(*) from user
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update user
<set >
<if test="record.iduser != null" >
iduser = #{record.iduser,jdbcType=INTEGER},
</if>
<if test="record.username != null" >
username = #{record.username,jdbcType=VARCHAR},
</if>
<if test="record.userpassword != null" >
userpassword = #{record.userpassword,jdbcType=VARCHAR},
</if>
<if test="record.useraccountnum != null" >
useraccountnum = #{record.useraccountnum,jdbcType=VARCHAR},
</if>
<if test="record.useremail != null" >
useremail = #{record.useremail,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update user
set iduser = #{record.iduser,jdbcType=INTEGER},
username = #{record.username,jdbcType=VARCHAR},
userpassword = #{record.userpassword,jdbcType=VARCHAR},
useraccountnum = #{record.useraccountnum,jdbcType=VARCHAR},
useremail = #{record.useremail,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.pls.po.User" >
update user
<set >
<if test="username != null" >
username = #{username,jdbcType=VARCHAR},
</if>
<if test="userpassword != null" >
userpassword = #{userpassword,jdbcType=VARCHAR},
</if>
<if test="useraccountnum != null" >
useraccountnum = #{useraccountnum,jdbcType=VARCHAR},
</if>
<if test="useremail != null" >
useremail = #{useremail,jdbcType=VARCHAR},
</if>
</set>
where iduser = #{iduser,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pls.po.User" >
update user
set username = #{username,jdbcType=VARCHAR},
userpassword = #{userpassword,jdbcType=VARCHAR},
useraccountnum = #{useraccountnum,jdbcType=VARCHAR},
useremail = #{useremail,jdbcType=VARCHAR}
where iduser = #{iduser,jdbcType=INTEGER}
</update> <!-- 上面是机器生成的代码,以下是自己写的 -->
<select id="selectByUseraccountnum" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from user
where useraccountnum = #{useraccountnum,jdbcType=VARCHAR}
</select> <select id="getAllUser" resultMap="BaseResultMap" >
select * from user
</select> </mapper>

user.java没什么好说的,但还是贴上来:

 package com.pls.po;

 public class User {
private Integer iduser; private String username; private String userpassword; private String useraccountnum; private String useremail; public Integer getIduser() {
return iduser;
} public void setIduser(Integer iduser) {
this.iduser = iduser;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username == null ? null : username.trim();
} public String getUserpassword() {
return userpassword;
} public void setUserpassword(String userpassword) {
this.userpassword = userpassword == null ? null : userpassword.trim();
} public String getUseraccountnum() {
return useraccountnum;
} public void setUseraccountnum(String useraccountnum) {
this.useraccountnum = useraccountnum == null ? null : useraccountnum.trim();
} public String getUseremail() {
return useremail;
} public void setUseremail(String useremail) {
this.useremail = useremail == null ? null : useremail.trim();
} @Override
public String toString() {
return "User [iduser=" + iduser + ", username=" + username + ", userpassword=" + userpassword
+ ", useraccountnum=" + useraccountnum + ", useremail=" + useremail + "]";
} }

userExample看了下,有点晕:

 package com.pls.po;

 import java.util.ArrayList;
import java.util.List; public class UserExample {
protected String orderByClause; protected boolean distinct; protected List<Criteria> oredCriteria; public UserExample() {
oredCriteria = new ArrayList<Criteria>();
} public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
} public String getOrderByClause() {
return orderByClause;
} public void setDistinct(boolean distinct) {
this.distinct = distinct;
} public boolean isDistinct() {
return distinct;
} public List<Criteria> getOredCriteria() {
return oredCriteria;
} public void or(Criteria criteria) {
oredCriteria.add(criteria);
} public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
} public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
} protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
} public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
} protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria; protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
} public boolean isValid() {
return criteria.size() > 0;
} public List<Criterion> getAllCriteria() {
return criteria;
} public List<Criterion> getCriteria() {
return criteria;
} protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
} protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
} protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
} public Criteria andIduserIsNull() {
addCriterion("iduser is null");
return (Criteria) this;
} public Criteria andIduserIsNotNull() {
addCriterion("iduser is not null");
return (Criteria) this;
} public Criteria andIduserEqualTo(Integer value) {
addCriterion("iduser =", value, "iduser");
return (Criteria) this;
} public Criteria andIduserNotEqualTo(Integer value) {
addCriterion("iduser <>", value, "iduser");
return (Criteria) this;
} public Criteria andIduserGreaterThan(Integer value) {
addCriterion("iduser >", value, "iduser");
return (Criteria) this;
} public Criteria andIduserGreaterThanOrEqualTo(Integer value) {
addCriterion("iduser >=", value, "iduser");
return (Criteria) this;
} public Criteria andIduserLessThan(Integer value) {
addCriterion("iduser <", value, "iduser");
return (Criteria) this;
} public Criteria andIduserLessThanOrEqualTo(Integer value) {
addCriterion("iduser <=", value, "iduser");
return (Criteria) this;
} public Criteria andIduserIn(List<Integer> values) {
addCriterion("iduser in", values, "iduser");
return (Criteria) this;
} public Criteria andIduserNotIn(List<Integer> values) {
addCriterion("iduser not in", values, "iduser");
return (Criteria) this;
} public Criteria andIduserBetween(Integer value1, Integer value2) {
addCriterion("iduser between", value1, value2, "iduser");
return (Criteria) this;
} public Criteria andIduserNotBetween(Integer value1, Integer value2) {
addCriterion("iduser not between", value1, value2, "iduser");
return (Criteria) this;
} public Criteria andUsernameIsNull() {
addCriterion("username is null");
return (Criteria) this;
} public Criteria andUsernameIsNotNull() {
addCriterion("username is not null");
return (Criteria) this;
} public Criteria andUsernameEqualTo(String value) {
addCriterion("username =", value, "username");
return (Criteria) this;
} public Criteria andUsernameNotEqualTo(String value) {
addCriterion("username <>", value, "username");
return (Criteria) this;
} public Criteria andUsernameGreaterThan(String value) {
addCriterion("username >", value, "username");
return (Criteria) this;
} public Criteria andUsernameGreaterThanOrEqualTo(String value) {
addCriterion("username >=", value, "username");
return (Criteria) this;
} public Criteria andUsernameLessThan(String value) {
addCriterion("username <", value, "username");
return (Criteria) this;
} public Criteria andUsernameLessThanOrEqualTo(String value) {
addCriterion("username <=", value, "username");
return (Criteria) this;
} public Criteria andUsernameLike(String value) {
addCriterion("username like", value, "username");
return (Criteria) this;
} public Criteria andUsernameNotLike(String value) {
addCriterion("username not like", value, "username");
return (Criteria) this;
} public Criteria andUsernameIn(List<String> values) {
addCriterion("username in", values, "username");
return (Criteria) this;
} public Criteria andUsernameNotIn(List<String> values) {
addCriterion("username not in", values, "username");
return (Criteria) this;
} public Criteria andUsernameBetween(String value1, String value2) {
addCriterion("username between", value1, value2, "username");
return (Criteria) this;
} public Criteria andUsernameNotBetween(String value1, String value2) {
addCriterion("username not between", value1, value2, "username");
return (Criteria) this;
} public Criteria andUserpasswordIsNull() {
addCriterion("userpassword is null");
return (Criteria) this;
} public Criteria andUserpasswordIsNotNull() {
addCriterion("userpassword is not null");
return (Criteria) this;
} public Criteria andUserpasswordEqualTo(String value) {
addCriterion("userpassword =", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordNotEqualTo(String value) {
addCriterion("userpassword <>", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordGreaterThan(String value) {
addCriterion("userpassword >", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordGreaterThanOrEqualTo(String value) {
addCriterion("userpassword >=", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordLessThan(String value) {
addCriterion("userpassword <", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordLessThanOrEqualTo(String value) {
addCriterion("userpassword <=", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordLike(String value) {
addCriterion("userpassword like", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordNotLike(String value) {
addCriterion("userpassword not like", value, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordIn(List<String> values) {
addCriterion("userpassword in", values, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordNotIn(List<String> values) {
addCriterion("userpassword not in", values, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordBetween(String value1, String value2) {
addCriterion("userpassword between", value1, value2, "userpassword");
return (Criteria) this;
} public Criteria andUserpasswordNotBetween(String value1, String value2) {
addCriterion("userpassword not between", value1, value2, "userpassword");
return (Criteria) this;
} public Criteria andUseraccountnumIsNull() {
addCriterion("useraccountnum is null");
return (Criteria) this;
} public Criteria andUseraccountnumIsNotNull() {
addCriterion("useraccountnum is not null");
return (Criteria) this;
} public Criteria andUseraccountnumEqualTo(String value) {
addCriterion("useraccountnum =", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumNotEqualTo(String value) {
addCriterion("useraccountnum <>", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumGreaterThan(String value) {
addCriterion("useraccountnum >", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumGreaterThanOrEqualTo(String value) {
addCriterion("useraccountnum >=", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumLessThan(String value) {
addCriterion("useraccountnum <", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumLessThanOrEqualTo(String value) {
addCriterion("useraccountnum <=", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumLike(String value) {
addCriterion("useraccountnum like", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumNotLike(String value) {
addCriterion("useraccountnum not like", value, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumIn(List<String> values) {
addCriterion("useraccountnum in", values, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumNotIn(List<String> values) {
addCriterion("useraccountnum not in", values, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumBetween(String value1, String value2) {
addCriterion("useraccountnum between", value1, value2, "useraccountnum");
return (Criteria) this;
} public Criteria andUseraccountnumNotBetween(String value1, String value2) {
addCriterion("useraccountnum not between", value1, value2, "useraccountnum");
return (Criteria) this;
} public Criteria andUseremailIsNull() {
addCriterion("useremail is null");
return (Criteria) this;
} public Criteria andUseremailIsNotNull() {
addCriterion("useremail is not null");
return (Criteria) this;
} public Criteria andUseremailEqualTo(String value) {
addCriterion("useremail =", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailNotEqualTo(String value) {
addCriterion("useremail <>", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailGreaterThan(String value) {
addCriterion("useremail >", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailGreaterThanOrEqualTo(String value) {
addCriterion("useremail >=", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailLessThan(String value) {
addCriterion("useremail <", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailLessThanOrEqualTo(String value) {
addCriterion("useremail <=", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailLike(String value) {
addCriterion("useremail like", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailNotLike(String value) {
addCriterion("useremail not like", value, "useremail");
return (Criteria) this;
} public Criteria andUseremailIn(List<String> values) {
addCriterion("useremail in", values, "useremail");
return (Criteria) this;
} public Criteria andUseremailNotIn(List<String> values) {
addCriterion("useremail not in", values, "useremail");
return (Criteria) this;
} public Criteria andUseremailBetween(String value1, String value2) {
addCriterion("useremail between", value1, value2, "useremail");
return (Criteria) this;
} public Criteria andUseremailNotBetween(String value1, String value2) {
addCriterion("useremail not between", value1, value2, "useremail");
return (Criteria) this;
}
} public static class Criteria extends GeneratedCriteria { protected Criteria() {
super();
}
} public static class Criterion {
private String condition; private Object value; private Object secondValue; private boolean noValue; private boolean singleValue; private boolean betweenValue; private boolean listValue; private String typeHandler; public String getCondition() {
return condition;
} public Object getValue() {
return value;
} public Object getSecondValue() {
return secondValue;
} public boolean isNoValue() {
return noValue;
} public boolean isSingleValue() {
return singleValue;
} public boolean isBetweenValue() {
return betweenValue;
} public boolean isListValue() {
return listValue;
} public String getTypeHandler() {
return typeHandler;
} protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
} protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
} protected Criterion(String condition, Object value) {
this(condition, value, null);
} protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
} protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

service接口就不看了,直接看实现类代码:

 package com.pls.service.imp;

 import java.util.List;

 import javax.annotation.Resource;

 import org.springframework.stereotype.Service;

 import com.pls.mapper.UserMapper;
import com.pls.po.User;
import com.pls.po.UserExample;
import com.pls.po.UserExample.Criteria;
import com.pls.service.PlsService; @Service("plsService")
public class PlsServiceImp implements PlsService { @Resource
private UserMapper userDao; @Override
public User getUserById(int iduser) {
// TODO Auto-generated method stub
return this.userDao.selectByPrimaryKey(iduser);
} @Override
public List<User> getAllUser() {
// TODO Auto-generated method stub
//List<User> list; //UserExample e=new UserExample(); List<User> list=this.userDao.getAllUser(); return list;
} //根据用户名查找用户,主要用于登录时验证密码
@Override
public User getUserByUseraccountnum(String useraccountnum){ //UserExample example= new UserExample();
//Criteria criteria=example.createCriteria();
//criteria.andUseraccountnumEqualTo(useraccountnum);
User user=this.userDao.selectByUseraccountnum(useraccountnum); return user;
} //删除方法
@Override
public void deleteUser(int iduser){
this.userDao.deleteByPrimaryKey(iduser);
} //根据名字或账号查询方法
@Override
public List<User> findByNameOrAccountnum(String nameOrAccountnum){
UserExample e1=new UserExample();
Criteria c1=e1.createCriteria();
c1.andUsernameLike("%"+nameOrAccountnum+"%");
List<User> list=this.userDao.selectByExample(e1);
UserExample e2=new UserExample();
Criteria c2=e2.createCriteria();
c2.andUseraccountnumLike("%"+nameOrAccountnum+"%");
list.addAll(this.userDao.selectByExample(e2));
return list;
} //插入的方法
@Override
public int insertUser(User user){ int iduser=this.userDao.insert(user); return iduser;
} //更新用户
@Override
public int updateUser(User User){ int iduser=this.userDao.updateByPrimaryKey(User); return iduser; }
}

控制层目录:

先看userController:

 package com.pls.controller;

 import javax.servlet.http.HttpServletRequest;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import com.pls.po.User;
import com.pls.service.PlsService; @Controller
@RequestMapping("/log")
public class UserController { ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "spring/applicationContext.xml",
"spring/applicationContext-dao.xml", "spring/applicationContext-service.xml" });
PlsService plsService = (PlsService) ac.getBean("plsService"); //用于验证用户密码是否输入正确
@RequestMapping("/submit")
public String toIndex(HttpServletRequest request, Model model, String useraccountnum, String password) { User user = this.plsService.getUserByUseraccountnum(useraccountnum);
if (user != null) {
if (user.getUserpassword().equals(password)) { model.addAttribute("user", user);
model.addAttribute("iduser", user.getIduser());
return "index"; } else {
return "error";
}
} else {
return "error";
} } //跳转到登录页面
@RequestMapping("/login")
public String login(Model model) throws Exception { return "login";
} }

本来想用注解直接注入service的,结果一直报空指针错误,注入不成功,没办法只好用导配置文件的方式,不知道哪位大神能给我指点一下,说一下那个地方出错了。

这里我就不按action一个一个给你们看jsp页面及实现效果了,现在已经快12点了,我待会儿集中放后面。

manageController:

 package com.pls.controller;

 import java.util.List;

 import javax.servlet.http.HttpServletRequest;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import com.pls.po.User;
import com.pls.service.PlsService; @Controller
@RequestMapping("/manage")
public class MannageController { ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "spring/applicationContext.xml",
"spring/applicationContext-dao.xml", "spring/applicationContext-service.xml" });
PlsService plsService = (PlsService) ac.getBean("plsService"); @RequestMapping("/showUser")
public String showUser(Model model) throws Exception { List<User> list = this.plsService.getAllUser();
model.addAttribute("list", list); return "showUser";
} @RequestMapping(value = "/deleteUser/{iduser}", method = RequestMethod.GET)
public String deleteUser(HttpServletRequest request, Model model, @PathVariable int iduser) throws Exception { this.plsService.deleteUser(iduser);
List<User> list = this.plsService.getAllUser();
model.addAttribute("list", list); return "showUser";
} @RequestMapping("/findUser")
public String findUser(HttpServletRequest request, Model model, String nameOrAccountnum) throws Exception { // this.plsService.findByNameOrAccountnum(nameOrAccountnum);
List<User> list = this.plsService.findByNameOrAccountnum(nameOrAccountnum);
model.addAttribute("list", list); return "showUser";
} // 跳转到填加管理员页面
@RequestMapping("/addManage")
public String addManage(Model model) throws Exception { return "addManage";
} // 添加管理员
@RequestMapping("/submitUser")
public String submitUser(HttpServletRequest request, Model model, String accountnum, String userpassword,
String username, String Email) throws Exception { User user = new User();
user.setUseraccountnum(accountnum);
user.setUseremail(Email);
user.setUsername(username);
user.setUserpassword(userpassword); int iduser = this.plsService.insertUser(user); if (iduser > 0) { List<User> list = this.plsService.getAllUser();
model.addAttribute("list", list); return "showUser";
} return "addUserError";
} // 修改管理员
@RequestMapping(value = "/updateUser/{iduser}", method = RequestMethod.GET)
public String updateUser(HttpServletRequest request, Model model, @PathVariable int iduser) throws Exception { User user = this.plsService.getUserById(iduser);
model.addAttribute("user", user); return "updateManage";
} // 提交修改的管理员
@RequestMapping("/updateUserSubmit")
public String updateSubmitUser(HttpServletRequest request, Model model, String accountnum, String userpassword,
String username, String Email, int iduser) throws Exception { User user = new User();
user.setUseraccountnum(accountnum);
user.setUseremail(Email);
user.setUsername(username);
user.setUserpassword(userpassword);
user.setIduser(iduser); if (this.plsService.updateUser(user) > 0) { List<User> list = this.plsService.getAllUser();
model.addAttribute("list", list); return "showUser";
}
return null;
} }

webContent目录:

jsp页面代码,依次序排列:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquerypicture.js"></script> <style type="text/css">
body {font-size: 20px;
padding-bottom: 40px;
background-color:#e9e7ef;
}
.sidebar-nav {
padding: 9px 0;
} @media (max-width: 980px) {
/* Enable use of floated navbar text */
.navbar-text.pull-right {
float: none;
padding-left: 5px;
padding-right: 5px;
}
} </style>
</head>
<body>
<br>
<font color="#777777"><strong>请填写管理员资料:</strong></font>
<form action="${pageContext.request.contextPath }/manage/submitUser.action" method="post" class="definewidth m20" >
<table class="table table-bordered table-hover m10" style="margin-left:10px;margin-top:3px;"> <br>
<tr>
<td class="tableleft">账号</td>
<td><input type="text" name="accountnum" /></td>
<td class="tableleft">密码</td>
<td><input type="text" name="userpassword" /></td>
</tr>
<tr>
<td class="tableleft">姓名</td>
<td><input type="text" name="username" /></td>
<td class="tableleft">邮箱</td>
<td><input type="text" name="Email" /></td>
</tr> </table>
<br>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<button type="submit" onclick="${pageContext.request.contextPath }/manage/submitUser.action" class="btn btn-primary">提交</button>
</form>
<img src="" id="img0" > <script>
$("#GoodsPicture").change(function(){
var objUrl = getObjectURL(this.files[0]) ;
console.log("objUrl = "+objUrl) ;
if (objUrl) {
$("#img0").attr("src", objUrl) ;
}
}) ; </body>
</html>
<script>
$(function (){
$('#backid').click(function(){
window.location.href="goodsQuery.html";
});
}); </script>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>插入用户错误错误</title> </head>
<body> <h1>插入用户错误错误</h1> </body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>错误</title> </head>
<body> <h1>不存在的用户或用户名密码错误</h1> </body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
<head>
<meta charset="utf-8">
<title>零件库管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../html/Css/adminStyle.css" rel="stylesheet" type="text/css" /> <title>零件库管理系统</title>
<script type="text/javascript" src="../html/js/jquery1.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$(".div2").click(
function() {
$(this).next("div").slideToggle("slow").siblings(
".div3:visible").slideUp("slow");
});
});
function openurl(url) {
var rframe = parent.document.getElementById("rightFrame");
rframe.src = url;
}
</script>
<style>
body {
margin: 0;
font-family: 微软雅黑;
background-image: url(images/.jpg);
background-repeat: no-repea;
background-size: cover;
background-attachment: fixed;
background-color: #DDDDDD } .top1 {
position: absolute;
top: 0px;
width: 100%;
height: 20px;
text-align: center;
color: #FFFFFF;
font-size: 17px;
font-height: 20px;
font-family: 楷体;
background-color: #888888
} .title {
float:left;
margin:-32px 20px;
font-size: 40px;
color: #FFFFFF;
font-height: 55px;
font-family: 隶书;
} .top2 {
position: absolute;
top: 20px;
width: 100%;
height: 77px;
text-align: center;
color: #ccffff;
background-color: #888888
} .left {
position: absolute;
left: 0px;
top: 97px;
width: 200px;
height: 85%;
border-right: 1px solid #9370DB;
color: #000000;
font-size: 20px;
text-align: center;
background-color: #B3B3B3
} .right {
position: absolute;
left: 200px;
top:97px;
width: 85.2%;
height: 85%;
border-top: 0px solid #484860;
font-size: 14px;
text-align: center;
} .end {
position: absolute;
bottom: 0px;
width: 100%;
height: 30px;
text-align: center;
color: #556B2F;
font-size: 17px;
font-height: 20px;
font-family: 楷体;
background-color: #C0C0C0
} .div1 {
text-align: center;
width: 200px;
padding-top: 10px;
} .div2 {
height: 40px;
line-height: 40px;
cursor: pointer;
font-size: 18px;
position: relative;
border-bottom: #ccc 0px dotted;
} .spgl {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/1.png);
} .yhgl {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/4.png);
} .gggl {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/4.png);
} .zlgl {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/4.png);
} .pjgl {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/4.png);
} .tcht {
position: absolute;
height: 20px;
width: 20px;
left: 40px;
top: 10px;
background: url(images/2.png);
} .div3 {
display: none;
cursor: pointer;
font-size: 15px;
} .div3 ul {
margin: 0;
padding: 0;
} .div3 li {
height: 30px;
line-height: 30px;
list-style: none;
border-bottom: #ccc 1px dotted;
text-align: center;
} .a {
text-decoration: none;
color: #000000;
font-size: 15px;
} .a1 {
text-decoration: none;
color: #000000;
font-size: 18px;
}
</style>
</head>
<body> <div class="top1">
<marquee scrollAmount=2 width=300>数据无价,请谨慎操作!</marquee>
</div>
<div class="top2">
<div class="logo">
<img src="../html/images/admin_logo.png" title="在哪儿" />
</div>
<div class="title" >
<h3>零件库管理系统</h3>
</div>
<div class="fr top-link">
<a href="admin_list.html" target="mainCont" title="DeathGhost"><i
class="adminIcon"></i><span>管理员:${user.username }</span></a>
</div>
</div> <div class="left">
<div class="div1">
<div class="left_top">
<img src="../html/images/bbb_01.jpg"><img src="../html/images/bbb_02.jpg"
id="2"><img src="../html/images/bbb_03.jpg"><img
src="../html/images/bbb_04.jpg">
</div> <div class="div2">
<div class="spgl"></div>
视频管理
</div>
<div class="div3">
<li><a class="a" href="javascript:void(0);"
onClick="openurl('videoQuery.html');">查看所有视频</a></li>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('uservideoQuery.html');">用户视频列表</a></li> </div>
<div class="div2">
<div class="spgl"></div>
文档管理
</div>
<div class="div3">
<ul>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('documentQuery.html');">查看所有文档</a></li>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('userdocumentQuery.html');">用户文档列表</a></li> </ul>
</div>
<div class="div2">
<div class="spgl"></div>
类别管理
</div>
<div class="div3">
<ul>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('classQuery.html');">大类信息</a></li> </ul>
</div>
<div class="div2">
<div class="yhgl"></div>
用户管理
</div>
<div class="div3">
<ul>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('studentQuery.html');">学生管理</a></li>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('${pageContext.request.contextPath }/manage/showUser.action');">老师管理</a></li>
</ul>
</div> <div class="div2">
<div class="gggl"></div>
评价管理
</div>
<div class="div3"> <ul>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('deletecomment.html');">评价删除</a></li>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('useredit.html');">用户禁言</a></li>
</ul> </div>
<div class="div2">
<div class="pjgl"></div>
公告管理
</div>
<div class="div3">
<ul>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('afficheQuery.html');">查看公告</a></li>
<li><a class="a" href="javascript:void(0);"
onClick="openurl('afficheAdd.html');">添加公告</a></li>
</ul>
</div>
<a class="a1" href="login.html"><div class="div2">
<div class="tcht"></div>
退出后台
</div></a>
</div>
</div> <div class="right">
<iframe id="rightFrame" name="rightFrame" width="100%" height="100%"
scrolling="auto" marginheight="0" marginwidth="0" align="center"
style="border: 0px solid #CCC; margin: 0; padding: 0;"></iframe>
</div> </body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>零件库管理系统登录界面</title> <link rel="stylesheet" type="text/css" href="../html/Css/styles.css"> </head>
<body> <div class="wrapper"> <div class="container">
<h1>零件库管理系统</h1>
<form class="form" action="${pageContext.request.contextPath }/log/submit.action" method="post">
<input type="text" placeholder="Username" name="useraccountnum">
<input type="password" placeholder="Password" name="password"><br>
<button type="submit" id="login-button" onclick="${pageContext.request.contextPath }/log/submit.action"><strong>登陆</strong></button> </form>
</div> <ul class="bg-bubbles">
<li></li>
<li></li> </ul> </div> </body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
<link rel="stylesheet" type="text/css"
href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script> <style type="text/css">
body {
font-size: 20px;
padding-bottom: 40px;
background-color: #e9e7ef;
} .sidebar-nav {
padding: 9px 0;
} @media ( max-width : 980px) {
/* Enable use of floated navbar text */
.navbar-text.pull-right {
float: none;
padding-left: 5px;
padding-right: 5px;
}
}
</style>
</head>
<body>
<form class="form-inline definewidth m20" action="${pageContext.request.contextPath }/manage/findUser.action" method="post">
<font color="#777777"><strong>管理员姓名或账号:</strong></font> <input
type="text" name="nameOrAccountnum" id="menuname" class="abc input-default"
placeholder="" value="">&nbsp;&nbsp;
<button type="submit" class="btn btn-primary">查询</button>
<button type="button" id="addnew">
<a href="${pageContext.request.contextPath }/manage/addManage.action">添加管理员</a>
</button>
</form>
<table class="table table-bordered table-hover definewidth m10">
<thead>
<tr>
<th>管理员姓名</th> <th>管理员账号</th> <th>Email</th>
<th>注销账户</th>
<th>修改用户</th>
</tr>
</thead>
<c:forEach items="${list}" var="manage">
<tr>
<!-- <a href="teacherdetail.html">nblyp</a> -->
<td>${manage.username }</td> <td>${manage.useraccountnum }</td>
<td>${manage.useremail }</td>
<!--
<td><button type="submit" onclick="${pageContext.request.contextPath }/manage/deleteUser/${manage.iduser }.action" method="get">注销</button></td>
-->
<td><a href="${pageContext.request.contextPath }/manage/deleteUser/${manage.iduser }.action">注销</a></td>
<td><a href="${pageContext.request.contextPath }/manage/updateUser/${manage.iduser }.action">修改</a></td>
</tr>
</c:forEach> </table> </body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquerypicture.js"></script> <style type="text/css">
body {font-size: 20px;
padding-bottom: 40px;
background-color:#e9e7ef;
}
.sidebar-nav {
padding: 9px 0;
} @media (max-width: 980px) {
/* Enable use of floated navbar text */
.navbar-text.pull-right {
float: none;
padding-left: 5px;
padding-right: 5px;
}
} </style>
</head>
<body>
<br>
<font color="#777777"><strong>请填写管理员资料:</strong></font>
<form action="${pageContext.request.contextPath }/manage/updateUserSubmit.action" method="post" class="definewidth m20" >
<table class="table table-bordered table-hover m10" style="margin-left:10px;margin-top:3px;"> <br>
<tr> <td class="tableleft">账号</td>
<td><input type="text" name="accountnum" value=${user.useraccountnum} /></td>
<td class="tableleft">密码</td>
<td><input type="text" name="userpassword" value=${user.userpassword} /></td>
</tr>
<tr>
<td class="tableleft">真实姓名</td>
<td><input type="text" name="username" value=${user.username} /></td>
<td class="tableleft">邮箱</td>
<td><input type="text" name="Email" value=${user.useremail} /></td>
</tr>
<input type="hidden" name="iduser" value=${user.iduser} /> </table>
<br>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<button type="submit" onclick="${pageContext.request.contextPath }/manage/updateUserSubmit.action" class="btn btn-primary">提交</button>
</form>
<img src="" id="img0" > <script>
$("#GoodsPicture").change(function(){
var objUrl = getObjectURL(this.files[0]) ;
console.log("objUrl = "+objUrl) ;
if (objUrl) {
$("#img0").attr("src", objUrl) ;
}
}) ; </body>
</html>
<script>
$(function (){
$('#backid').click(function(){
window.location.href="goodsQuery.html";
});
}); </script>

代码是糙了一点,不过因为是第一次做项目嘛,包容包容。

来看看最后效果:

这肯定不是最终版本,我还有一些功能及一些地方需要修改。前端的代码不是我自己写的,是从网上下载的免费模板,在此感谢源码之家提供的免费模板,有兴趣的小伙伴可以取下一个来玩。本人第一次做项目,发到博客来和大家探讨学习,希望那些大神嘴下留情,不喜勿喷。

我还会继续更新我的毕设的,感谢大家支持。

零件库管理信息系统设计--part03:管理员登录部分设计的更多相关文章

  1. 基于Intranet的零件库管理信息系统设计--part01

    好吧,临近毕业的我,毕业设计还没开始做呢.时间不等人,再过两个月就要答辩了,我得开始做我的毕设了,虽然我现在还没能力完全把毕设做出来,但总得先迈出第一步吧.今天先做一小部分. 话不多说,先来看我得毕业 ...

  2. 基于Intranet的零件库管理信息系统设计--part02

    昨天建了第一个子表,今天继续. 按照这个一个一个来: 轴承参数查询如下(来源:轴承查询型号网) 照这个来大概就是这么几个属性: 轴承主键,轴承名称,新型号,旧型号,内径,外径,宽度,Cr,Cor(话说 ...

  3. 关于信息系统设计与开发——案例:VIP系统

    一.关于信息系统设计与开发 信息系统开发流程先对需求分析系统分析,设计数据库,设计程序,再对测试数据进行测试. 在程序设计中运用了接口:定义一个接口,可以有多种实现.变量声明为接口变量,调用接口方法, ...

  4. Go语言学习教程:管理员登录功能开发

    学习完了数据库操作的知识以后.本节内容,我们将实现管理员登陆功能,涉及到多个模块的代码实现和逻辑处理,以及数据库表的操作,都将在本节内容中进行实现. 管理员结构体定义 首先我们要定义管理员这个实体的结 ...

  5. Yii2创建管理员登录

    1. 创建管理员表 进入项目根目录,在根目录执行命令: 1 $ ./yii migrate 2. 创建管理的控制器 1 $ cd console/controllers/ 编写代码如下: 123456 ...

  6. 学用MVC4做网站六后台管理:6.1.1管理员登录、6.1.2退出

    1.管理员登录 在6.1中已添加控制器[AdministratorController] 在控制器中添加[Login()]action,用来显示登录页面 /// <summary> /// ...

  7. HoverTree开源项目已经实现管理员登录

    ASP.NET开源项目HoverTree已经实现了管理员登录功能,最新代码请到以下网址查看.http://hovertree.com/down/ 点击Clone右边的Download就可以下载最新开发 ...

  8. 超级管理员登录后如果连续XX分钟没有操作再次操作需要重新登录

    首先在设置session页面时 session_start(); session("name",$adminname); //加入session时间 time() session( ...

  9. discuz管理员登录进入后台管理马上跳转到登录界面

    昨天尝试了一下这个discuz论坛,感觉还可以.今天刚刚用管理员账户进入后台管理,准备改一改界面熟悉一下,过不了10秒钟.老是马上就退出来了.我想起来了,昨天是在阿里云服务器上面直接登录这个管理员账号 ...

随机推荐

  1. WinForm 对话框、流

    一.对话框 ColorDialog:颜色选择控件 private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDia ...

  2. 内功心法 -- java.util.ArrayList<E> (6)

    写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------下文主要对java.util ...

  3. 认识 getAttribute() setAttribute()

    getAttribute()方法不属于document对象,所以不能通过document对象调用,它只能通过元素节点对象调用 var paras = document.getElementsByTag ...

  4. 安装Oracle服务端后配置注册表与PL/SQL

    1.流程: 1.安装Oracle客户端(绿色版和安装版均可,建议安装在和Oracle服务端文件夹并行的路径下,例:E:\app\yginuo\product\11.2.0) 2.配置环境变量和注册表( ...

  5. this的相关介绍与用法

    当一个对象创建后,Java虚拟机(JVM)就会给这个对象分配一个引用自身的指针,这个指针的名字就是this.因此,this只能在类中的非静态方法中使用,静态方法和静态的代码块中绝对不能出现this,并 ...

  6. ios 动画学习的套路 (二)

    有它们俩你就够了! 说明:下面有些概念我说的不怎么详细,网上实在是太多了,说了我觉得也意义不大了!但链接都给大家了,可以自己去看,重点梳理学习写动画的一个过程和一些好的博客! (一) 说说这两个三方库 ...

  7. 通过 Chrome 在 Windows 中调试运行在 iphone-safari 上的 页面

    本文重点讨论如何在 Windows 系统中通过chrome 浏览器调试运行在 iPhone Safari 浏览器中的网页.如果你有一台 iMac/MacBook,可忽略该文档.iMac 环境下,直接通 ...

  8. Python学习的个人笔记(基础语法)

    Python学习的个人笔记 题外话: 我是一个大二的计算机系的学生,这份python学习个人笔记是趁寒假这一周在慕课网,w3cschool,还有借鉴了一些博客,资料整理出来的,用于自己方便的时候查阅, ...

  9. nginx配合IIS实现简单负载均衡

    1.IIS 部署两个站点端口分别为8081和8082 8081站点和8082站点如下[随便写了个没有样式的很丑的页面],我特意加了111和222区分     2.设置nginx配置文件,实现简单的负载 ...

  10. Linux下connect超时处理【总结】

    1.前言 最近在写一个测试工具,要求快速的高效率的扫描出各个服务器开放了哪些端口.当时想了一下,ping只能检测ip,判断服务器的网络是连通的,而不能判断是否开放了端口.我们知道端口属于网络的应用层, ...