零件库管理信息系统设计--part03:管理员登录部分设计

兄弟们,我又回来啦!

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

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

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

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

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

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

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

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

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <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">
 3   <display-name>pls</display-name>
 4   <welcome-file-list>
 5     <welcome-file>login.html</welcome-file>
 6     <welcome-file>index.htm</welcome-file>
 7     <welcome-file>index.jsp</welcome-file>
 8     <welcome-file>default.html</welcome-file>
 9     <welcome-file>default.htm</welcome-file>
10     <welcome-file>default.jsp</welcome-file>
11   </welcome-file-list>
12   
13   <!-- 加载spring容器 -->
14     <context-param>
15         <param-name>contextConfigLocation</param-name>
16         <param-value>/WEB-INF/classes/spring/applicationContext.xml,/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
17     </context-param>
18     <listener>
19         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
20     </listener>    
21     
22     
23     <!-- 编码过滤器 -->
24     <filter>
25         <filter-name>encodingFilter</filter-name>
26         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
27         <async-supported>true</async-supported>
28         <init-param>
29             <param-name>encoding</param-name>
30             <param-value>UTF-8</param-value>
31         </init-param>
32     </filter>
33     <filter-mapping>
34         <filter-name>encodingFilter</filter-name>
35         <url-pattern>/*</url-pattern>
36     </filter-mapping>
37     
38     <!-- Spring监听器 -->
39     <listener>
40         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
41     </listener>
42     
43     <!-- Spring MVC servlet -->
44     <servlet>
45         <servlet-name>SpringMVC</servlet-name>
46         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
47         <init-param>
48             <param-name>contextConfigLocation</param-name>
49             <param-value>/WEB-INF/classes/spring/springmvc.xml</param-value>
50         </init-param>
51         <!--  
52         <load-on-startup>1</load-on-startup>
53         <async-supported>true</async-supported>
54         -->
55     </servlet>
56     <servlet-mapping>
57         <servlet-name>SpringMVC</servlet-name>        
58         <url-pattern>*.action</url-pattern>
59     </servlet-mapping>
60     <welcome-file-list>
61         <welcome-file>/index.jsp</welcome-file>
62     </welcome-file-list>
63   
64 </web-app>

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

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

 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
 7         http://www.springframework.org/schema/mvc 
 8         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
 9         http://www.springframework.org/schema/context 
10         http://www.springframework.org/schema/context/spring-context-3.1.xsd 
11         http://www.springframework.org/schema/aop 
12         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
13         http://www.springframework.org/schema/tx 
14         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
15 
16     
17     <!-- 加载配置文件 -->
18     <context:property-placeholder location="classpath:db.properties" />
19     <!-- 使用第三方的数据库连接池dbcp -->
20     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
21         destroy-method="close">
22         <property name="driverClassName" value="${jdbc.driver}" />
23         <property name="url" value="${jdbc.url}" />
24         <property name="username" value="${jdbc.username}" />
25         <property name="password" value="${jdbc.password}" />
26         <!-- 开发阶段数据库最大连接数建议设置小一点够用即可,设置为3 -->
27         <property name="maxActive" value="${jdbc.maxActive}" />
28         <property name="maxIdle" value="${jdbc.maxIdle}" />
29     </bean>
30     
31     <!-- 事务管理 -->
32     
33     <!-- 事务管理器
34     mybatis使用jdbc事务管理
35      -->
36     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
37         <!-- 数据源 -->
38         <property name="dataSource" ref="dataSource"/>
39     </bean>
40     
41     <!-- 通知 -->
42     <tx:advice id="txAdvice" transaction-manager="transactionManager">
43         <!-- 配置传播行为 -->
44         <tx:attributes>
45             <tx:method name="save*" propagation="REQUIRED" />
46             <tx:method name="insert*" propagation="REQUIRED"/>
47             <tx:method name="update*" propagation="REQUIRED"/>
48             <tx:method name="delete*" propagation="REQUIRED"/>
49             <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
50             <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
51             <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
52         </tx:attributes>
53     </tx:advice>
54     
55     <!-- aop配置 -->
56     <aop:config>
57         <aop:advisor advice-ref="txAdvice"
58          pointcut="execution(* com.pls.service.imp.*.*(..))"/>
59     </aop:config>
60 
61 
62 </beans>

 

 然后是applicationContext-dao.xml:

 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
 7         http://www.springframework.org/schema/mvc 
 8         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
 9         http://www.springframework.org/schema/context 
10         http://www.springframework.org/schema/context/spring-context-3.1.xsd 
11         http://www.springframework.org/schema/aop 
12         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
13         http://www.springframework.org/schema/tx 
14         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
15 
16 <!-- 配置SqlSessionFactory -->
17 <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
18     <!-- 数据源 -->
19     <property name="dataSource" ref="dataSource"/>
20     <!-- 配置SqlMapConfig.xml -->
21     <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
22 </bean>
23 
24 <!-- 配置userDao -->
25 <!-- <bean id="userDao" class="cn.itcast.ssm.dao.old.UserDaoImpl">
26     注入会话工厂
27     <property name="sqlSessionFactory" ref="sqlSessionFactoryBean"/>
28 </bean> -->
29 
30 
31 <!-- mapper动态代理 -->
32 <!-- 配置userMapper
33 MapperFactoryBean:用于生成 代理对象
34  -->
35 <!-- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
36    注入会话工厂
37     <property name="sqlSessionFactory" ref="sqlSessionFactoryBean"/>
38     mapper接口
39     <property name="mapperInterface" value="cn.itcast.ssm.dao.mapper.UserMapper"/>
40 </bean> -->
41 
42 <!-- 使用mapper批量扫描器扫描mapper接口
43 规则:mapper.xml和mapper.java在一个目录 且同名即可 
44 扫描出来mapper,自动让spring容器注册,bean的id就是mapper类名(首字母小写)
45  -->
46 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
47     <!-- 会话工厂 -->
48     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"/>
49   <!-- 扫描包路径 
50   多个包中间用半角逗号分隔
51    -->
52     <property name="basePackage" value="com.pls.mapper"/>
53 </bean>
54 
55 
56 </beans>

 

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

 

 applicationContext-service.xml:

 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
 7         http://www.springframework.org/schema/mvc 
 8         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
 9         http://www.springframework.org/schema/context 
10         http://www.springframework.org/schema/context/spring-context-3.1.xsd 
11         http://www.springframework.org/schema/aop 
12         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
13         http://www.springframework.org/schema/tx 
14         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
15 
16 
17 <!--  用户管理 -->
18   
19 <bean id="plsService" class="com.pls.service.imp.PlsServiceImp"/>
20 
21 </beans>

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

springmvc-xml:

 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
 7         http://www.springframework.org/schema/mvc 
 8         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
 9         http://www.springframework.org/schema/context 
10         http://www.springframework.org/schema/context/spring-context-3.1.xsd 
11         http://www.springframework.org/schema/aop 
12         http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
13         http://www.springframework.org/schema/tx 
14         http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
15 
16     <!-- 组件扫描 只扫描action -->
17     <context:component-scan base-package="com.pls.controller" />
18 
19 
20     <!-- 使用<mvc:annotation-driven />替换上边定义的处理器映射器和适配器 -->
21     <mvc:annotation-driven />
22 
23     <!-- 视图解析器 解析jsp视图,默认使用jstl,要求classpath下有jstl的jar包 -->
24     <bean
25         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
26         <!-- 视图的前缀 -->
27         <property name="prefix" value="/WEB-INF/jsp/" />
28         <!-- 视图的后缀 -->
29         <property name="suffix" value=".jsp" />
30         
31 
32     </bean>
33     
34     
35     <!--拦截器 -->
36     <mvc:interceptors>
37         
38         <mvc:interceptor>
39             <mvc:mapping path="/**" />
40             <bean class="interceptor.LoginInterceptor"></bean>
41         </mvc:interceptor>
42         
43     </mvc:interceptors>
44     
45 
46 </beans>

 

 还有:sqlmapconfig.xml:

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

 

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

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

 

 

 

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

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

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3   PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4   "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 
 6 <generatorConfiguration>
 7     <context id="testTables" targetRuntime="MyBatis3">
 8         <commentGenerator>
 9             <!-- 是否去除自动生成的注释 true:是 : false:否 -->
10             <property name="suppressAllComments" value="true" />
11         </commentGenerator>
12         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
13         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
14             connectionURL="jdbc:mysql://localhost:3306/partslibrarysystem" userId="root"
15             password="202011">
16         </jdbcConnection>
17         <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
18             connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg" 
19             userId="yycg"
20             password="yycg">
21         </jdbcConnection> -->
22 
23         <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 
24             NUMERIC 类型解析为java.math.BigDecimal -->
25         <javaTypeResolver>
26             <property name="forceBigDecimals" value="false" />
27         </javaTypeResolver>
28 
29         <!-- targetProject:生成PO类的位置 -->
30          
31         <javaModelGenerator targetPackage="com.pls.po"
32             targetProject=".\src">
33        
34             <!-- enableSubPackages:是否让schema作为包的后缀 -->
35              
36             <property name="enableSubPackages" value="false" />
37             
38             <!-- 从数据库返回的值被清理前后的空格 -->
39              
40             <property name="trimStrings" value="true" />
41         </javaModelGenerator>
42         
43         <!-- targetProject:mapper映射文件生成的位置 -->
44         <sqlMapGenerator targetPackage="com.pls.mapper" 
45             targetProject=".\src">
46             <!-- enableSubPackages:是否让schema作为包的后缀 -->
47             <property name="enableSubPackages" value="false" />
48         </sqlMapGenerator>
49         <!-- targetPackage:mapper接口生成的位置 -->
50         <javaClientGenerator type="XMLMAPPER"
51             targetPackage="com.pls.mapper" 
52             targetProject=".\src">
53             <!-- enableSubPackages:是否让schema作为包的后缀 -->
54             <property name="enableSubPackages" value="false" />
55         </javaClientGenerator>
56         <!-- 指定数据库表 -->
57         <table schema="" tableName="allsortparts"></table>
58         <table schema="" tableName="user"></table>
59         <table schema="" tableName="bearing"></table>
60         <table schema="" tableName="coupling"></table>
61         <table schema="" tableName="electromotor"></table>
62         <table schema="" tableName="fastener"></table>
63         <table schema="" tableName="flange"></table>
64         <table schema="" tableName="sealing_element"></table>
65         
66         <!-- 有些表的字段需要指定java类型
67          <table schema="" tableName="">
68             <columnOverride column="" javaType="" />
69         </table> -->
70     </context>
71 </generatorConfiguration>

还需要这个java类:

 1 package gm;
 2 
 3 
 4 import java.io.File;
 5 import java.util.ArrayList;
 6 import java.util.List;
 7 
 8 import org.mybatis.generator.api.MyBatisGenerator;
 9 import org.mybatis.generator.config.Configuration;
10 import org.mybatis.generator.config.xml.ConfigurationParser;
11 import org.mybatis.generator.internal.DefaultShellCallback;
12 
13 public class GeneratorSqlmap {
14 
15     public void generator() throws Exception{
16 
17         List<String> warnings = new ArrayList<String>();
18         boolean overwrite = true;
19         //指定逆向工程配置文件。
20         File configFile = new File("generatorConfig.xml"); 
21         ConfigurationParser cp = new ConfigurationParser(warnings);
22         Configuration config = cp.parseConfiguration(configFile);
23         DefaultShellCallback callback = new DefaultShellCallback(overwrite);
24         MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
25                 callback, warnings);
26         myBatisGenerator.generate(null);
27 
28     } 
29     public static void main(String[] args) throws Exception {
30         try {
31             GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
32             generatorSqlmap.generator();
33         } catch (Exception e) {
34             e.printStackTrace();
35         }
36         
37     }
38 
39 }

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

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

 

 1 package com.pls.mapper;
 2 
 3 import com.pls.po.User;
 4 import com.pls.po.UserExample;
 5 import java.util.List;
 6 import org.apache.ibatis.annotations.Param;
 7 
 8 public interface UserMapper {
 9     int countByExample(UserExample example);
10 
11     int deleteByExample(UserExample example);
12 
13     int deleteByPrimaryKey(Integer iduser);
14 
15     int insert(User record);
16 
17     int insertSelective(User record);
18 
19     List<User> selectByExample(UserExample example);
20 
21     User selectByPrimaryKey(Integer iduser);
22 
23     int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);
24 
25     int updateByExample(@Param("record") User record, @Param("example") UserExample example);
26 
27     int updateByPrimaryKeySelective(User record);
28 
29     int updateByPrimaryKey(User record);
30     
31     User selectByUseraccountnum(String useraccountnum);
32     
33     List<User> getAllUser();
34     
35 }

 

  1 <?xml version="1.0" encoding="UTF-8" ?>
  2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 <mapper namespace="com.pls.mapper.UserMapper" >
  4   <resultMap id="BaseResultMap" type="com.pls.po.User" >
  5     <id column="iduser" property="iduser" jdbcType="INTEGER" />
  6     <result column="username" property="username" jdbcType="VARCHAR" />
  7     <result column="userpassword" property="userpassword" jdbcType="VARCHAR" />
  8     <result column="useraccountnum" property="useraccountnum" jdbcType="VARCHAR" />
  9     <result column="useremail" property="useremail" jdbcType="VARCHAR" />
 10   </resultMap>
 11   <sql id="Example_Where_Clause" >
 12     <where >
 13       <foreach collection="oredCriteria" item="criteria" separator="or" >
 14         <if test="criteria.valid" >
 15           <trim prefix="(" suffix=")" prefixOverrides="and" >
 16             <foreach collection="criteria.criteria" item="criterion" >
 17               <choose >
 18                 <when test="criterion.noValue" >
 19                   and ${criterion.condition}
 20                 </when>
 21                 <when test="criterion.singleValue" >
 22                   and ${criterion.condition} #{criterion.value}
 23                 </when>
 24                 <when test="criterion.betweenValue" >
 25                   and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
 26                 </when>
 27                 <when test="criterion.listValue" >
 28                   and ${criterion.condition}
 29                   <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
 30                     #{listItem}
 31                   </foreach>
 32                 </when>
 33               </choose>
 34             </foreach>
 35           </trim>
 36         </if>
 37       </foreach>
 38     </where>
 39   </sql>
 40   <sql id="Update_By_Example_Where_Clause" >
 41     <where >
 42       <foreach collection="example.oredCriteria" item="criteria" separator="or" >
 43         <if test="criteria.valid" >
 44           <trim prefix="(" suffix=")" prefixOverrides="and" >
 45             <foreach collection="criteria.criteria" item="criterion" >
 46               <choose >
 47                 <when test="criterion.noValue" >
 48                   and ${criterion.condition}
 49                 </when>
 50                 <when test="criterion.singleValue" >
 51                   and ${criterion.condition} #{criterion.value}
 52                 </when>
 53                 <when test="criterion.betweenValue" >
 54                   and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
 55                 </when>
 56                 <when test="criterion.listValue" >
 57                   and ${criterion.condition}
 58                   <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
 59                     #{listItem}
 60                   </foreach>
 61                 </when>
 62               </choose>
 63             </foreach>
 64           </trim>
 65         </if>
 66       </foreach>
 67     </where>
 68   </sql>
 69   <sql id="Base_Column_List" >
 70     iduser, username, userpassword, useraccountnum, useremail
 71   </sql>
 72   <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.pls.po.UserExample" >
 73     select
 74     <if test="distinct" >
 75       distinct
 76     </if>
 77     <include refid="Base_Column_List" />
 78     from user
 79     <if test="_parameter != null" >
 80       <include refid="Example_Where_Clause" />
 81     </if>
 82     <if test="orderByClause != null" >
 83       order by ${orderByClause}
 84     </if>
 85   </select>
 86   <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
 87     select 
 88     <include refid="Base_Column_List" />
 89     from user
 90     where iduser = #{iduser,jdbcType=INTEGER}
 91   </select>
 92   <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
 93     delete from user
 94     where iduser = #{iduser,jdbcType=INTEGER}
 95   </delete>
 96   <delete id="deleteByExample" parameterType="com.pls.po.UserExample" >
 97     delete from user
 98     <if test="_parameter != null" >
 99       <include refid="Example_Where_Clause" />
100     </if>
101   </delete>
102   <insert id="insert" parameterType="com.pls.po.User" >
103     insert into user (iduser, username, userpassword, 
104       useraccountnum, useremail)
105     values (#{iduser,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{userpassword,jdbcType=VARCHAR}, 
106       #{useraccountnum,jdbcType=VARCHAR}, #{useremail,jdbcType=VARCHAR})
107   </insert>
108   <insert id="insertSelective" parameterType="com.pls.po.User" >
109     insert into user
110     <trim prefix="(" suffix=")" suffixOverrides="," >
111       <if test="iduser != null" >
112         iduser,
113       </if>
114       <if test="username != null" >
115         username,
116       </if>
117       <if test="userpassword != null" >
118         userpassword,
119       </if>
120       <if test="useraccountnum != null" >
121         useraccountnum,
122       </if>
123       <if test="useremail != null" >
124         useremail,
125       </if>
126     </trim>
127     <trim prefix="values (" suffix=")" suffixOverrides="," >
128       <if test="iduser != null" >
129         #{iduser,jdbcType=INTEGER},
130       </if>
131       <if test="username != null" >
132         #{username,jdbcType=VARCHAR},
133       </if>
134       <if test="userpassword != null" >
135         #{userpassword,jdbcType=VARCHAR},
136       </if>
137       <if test="useraccountnum != null" >
138         #{useraccountnum,jdbcType=VARCHAR},
139       </if>
140       <if test="useremail != null" >
141         #{useremail,jdbcType=VARCHAR},
142       </if>
143     </trim>
144   </insert>
145   <select id="countByExample" parameterType="com.pls.po.UserExample" resultType="java.lang.Integer" >
146     select count(*) from user
147     <if test="_parameter != null" >
148       <include refid="Example_Where_Clause" />
149     </if>
150   </select>
151   <update id="updateByExampleSelective" parameterType="map" >
152     update user
153     <set >
154       <if test="record.iduser != null" >
155         iduser = #{record.iduser,jdbcType=INTEGER},
156       </if>
157       <if test="record.username != null" >
158         username = #{record.username,jdbcType=VARCHAR},
159       </if>
160       <if test="record.userpassword != null" >
161         userpassword = #{record.userpassword,jdbcType=VARCHAR},
162       </if>
163       <if test="record.useraccountnum != null" >
164         useraccountnum = #{record.useraccountnum,jdbcType=VARCHAR},
165       </if>
166       <if test="record.useremail != null" >
167         useremail = #{record.useremail,jdbcType=VARCHAR},
168       </if>
169     </set>
170     <if test="_parameter != null" >
171       <include refid="Update_By_Example_Where_Clause" />
172     </if>
173   </update>
174   <update id="updateByExample" parameterType="map" >
175     update user
176     set iduser = #{record.iduser,jdbcType=INTEGER},
177       username = #{record.username,jdbcType=VARCHAR},
178       userpassword = #{record.userpassword,jdbcType=VARCHAR},
179       useraccountnum = #{record.useraccountnum,jdbcType=VARCHAR},
180       useremail = #{record.useremail,jdbcType=VARCHAR}
181     <if test="_parameter != null" >
182       <include refid="Update_By_Example_Where_Clause" />
183     </if>
184   </update>
185   <update id="updateByPrimaryKeySelective" parameterType="com.pls.po.User" >
186     update user
187     <set >
188       <if test="username != null" >
189         username = #{username,jdbcType=VARCHAR},
190       </if>
191       <if test="userpassword != null" >
192         userpassword = #{userpassword,jdbcType=VARCHAR},
193       </if>
194       <if test="useraccountnum != null" >
195         useraccountnum = #{useraccountnum,jdbcType=VARCHAR},
196       </if>
197       <if test="useremail != null" >
198         useremail = #{useremail,jdbcType=VARCHAR},
199       </if>
200     </set>
201     where iduser = #{iduser,jdbcType=INTEGER}
202   </update>
203   <update id="updateByPrimaryKey" parameterType="com.pls.po.User" >
204     update user
205     set username = #{username,jdbcType=VARCHAR},
206       userpassword = #{userpassword,jdbcType=VARCHAR},
207       useraccountnum = #{useraccountnum,jdbcType=VARCHAR},
208       useremail = #{useremail,jdbcType=VARCHAR}
209     where iduser = #{iduser,jdbcType=INTEGER}
210   </update>
211   
212   <!-- 上面是机器生成的代码,以下是自己写的 -->
213   <select id="selectByUseraccountnum" resultMap="BaseResultMap" parameterType="java.lang.String" >
214     select 
215     <include refid="Base_Column_List" />
216     from user
217     where useraccountnum = #{useraccountnum,jdbcType=VARCHAR}
218   </select>
219   
220   <select id="getAllUser" resultMap="BaseResultMap" >
221     select * from user
222   </select>
223   
224   
225 </mapper>

 

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

 1 package com.pls.po;
 2 
 3 public class User {
 4     private Integer iduser;
 5 
 6     private String username;
 7 
 8     private String userpassword;
 9 
10     private String useraccountnum;
11 
12     private String useremail;
13 
14     public Integer getIduser() {
15         return iduser;
16     }
17 
18     public void setIduser(Integer iduser) {
19         this.iduser = iduser;
20     }
21 
22     public String getUsername() {
23         return username;
24     }
25 
26     public void setUsername(String username) {
27         this.username = username == null ? null : username.trim();
28     }
29 
30     public String getUserpassword() {
31         return userpassword;
32     }
33 
34     public void setUserpassword(String userpassword) {
35         this.userpassword = userpassword == null ? null : userpassword.trim();
36     }
37 
38     public String getUseraccountnum() {
39         return useraccountnum;
40     }
41 
42     public void setUseraccountnum(String useraccountnum) {
43         this.useraccountnum = useraccountnum == null ? null : useraccountnum.trim();
44     }
45 
46     public String getUseremail() {
47         return useremail;
48     }
49 
50     public void setUseremail(String useremail) {
51         this.useremail = useremail == null ? null : useremail.trim();
52     }
53 
54     @Override
55     public String toString() {
56         return "User [iduser=" + iduser + ", username=" + username + ", userpassword=" + userpassword
57                 + ", useraccountnum=" + useraccountnum + ", useremail=" + useremail + "]";
58     }
59     
60     
61     
62 }

 

userExample看了下,有点晕:

  1 package com.pls.po;
  2 
  3 import java.util.ArrayList;
  4 import java.util.List;
  5 
  6 public class UserExample {
  7     protected String orderByClause;
  8 
  9     protected boolean distinct;
 10 
 11     protected List<Criteria> oredCriteria;
 12 
 13     public UserExample() {
 14         oredCriteria = new ArrayList<Criteria>();
 15     }
 16 
 17     public void setOrderByClause(String orderByClause) {
 18         this.orderByClause = orderByClause;
 19     }
 20 
 21     public String getOrderByClause() {
 22         return orderByClause;
 23     }
 24 
 25     public void setDistinct(boolean distinct) {
 26         this.distinct = distinct;
 27     }
 28 
 29     public boolean isDistinct() {
 30         return distinct;
 31     }
 32 
 33     public List<Criteria> getOredCriteria() {
 34         return oredCriteria;
 35     }
 36 
 37     public void or(Criteria criteria) {
 38         oredCriteria.add(criteria);
 39     }
 40 
 41     public Criteria or() {
 42         Criteria criteria = createCriteriaInternal();
 43         oredCriteria.add(criteria);
 44         return criteria;
 45     }
 46 
 47     public Criteria createCriteria() {
 48         Criteria criteria = createCriteriaInternal();
 49         if (oredCriteria.size() == 0) {
 50             oredCriteria.add(criteria);
 51         }
 52         return criteria;
 53     }
 54 
 55     protected Criteria createCriteriaInternal() {
 56         Criteria criteria = new Criteria();
 57         return criteria;
 58     }
 59 
 60     public void clear() {
 61         oredCriteria.clear();
 62         orderByClause = null;
 63         distinct = false;
 64     }
 65 
 66     protected abstract static class GeneratedCriteria {
 67         protected List<Criterion> criteria;
 68 
 69         protected GeneratedCriteria() {
 70             super();
 71             criteria = new ArrayList<Criterion>();
 72         }
 73 
 74         public boolean isValid() {
 75             return criteria.size() > 0;
 76         }
 77 
 78         public List<Criterion> getAllCriteria() {
 79             return criteria;
 80         }
 81 
 82         public List<Criterion> getCriteria() {
 83             return criteria;
 84         }
 85 
 86         protected void addCriterion(String condition) {
 87             if (condition == null) {
 88                 throw new RuntimeException("Value for condition cannot be null");
 89             }
 90             criteria.add(new Criterion(condition));
 91         }
 92 
 93         protected void addCriterion(String condition, Object value, String property) {
 94             if (value == null) {
 95                 throw new RuntimeException("Value for " + property + " cannot be null");
 96             }
 97             criteria.add(new Criterion(condition, value));
 98         }
 99 
100         protected void addCriterion(String condition, Object value1, Object value2, String property) {
101             if (value1 == null || value2 == null) {
102                 throw new RuntimeException("Between values for " + property + " cannot be null");
103             }
104             criteria.add(new Criterion(condition, value1, value2));
105         }
106 
107         public Criteria andIduserIsNull() {
108             addCriterion("iduser is null");
109             return (Criteria) this;
110         }
111 
112         public Criteria andIduserIsNotNull() {
113             addCriterion("iduser is not null");
114             return (Criteria) this;
115         }
116 
117         public Criteria andIduserEqualTo(Integer value) {
118             addCriterion("iduser =", value, "iduser");
119             return (Criteria) this;
120         }
121 
122         public Criteria andIduserNotEqualTo(Integer value) {
123             addCriterion("iduser <>", value, "iduser");
124             return (Criteria) this;
125         }
126 
127         public Criteria andIduserGreaterThan(Integer value) {
128             addCriterion("iduser >", value, "iduser");
129             return (Criteria) this;
130         }
131 
132         public Criteria andIduserGreaterThanOrEqualTo(Integer value) {
133             addCriterion("iduser >=", value, "iduser");
134             return (Criteria) this;
135         }
136 
137         public Criteria andIduserLessThan(Integer value) {
138             addCriterion("iduser <", value, "iduser");
139             return (Criteria) this;
140         }
141 
142         public Criteria andIduserLessThanOrEqualTo(Integer value) {
143             addCriterion("iduser <=", value, "iduser");
144             return (Criteria) this;
145         }
146 
147         public Criteria andIduserIn(List<Integer> values) {
148             addCriterion("iduser in", values, "iduser");
149             return (Criteria) this;
150         }
151 
152         public Criteria andIduserNotIn(List<Integer> values) {
153             addCriterion("iduser not in", values, "iduser");
154             return (Criteria) this;
155         }
156 
157         public Criteria andIduserBetween(Integer value1, Integer value2) {
158             addCriterion("iduser between", value1, value2, "iduser");
159             return (Criteria) this;
160         }
161 
162         public Criteria andIduserNotBetween(Integer value1, Integer value2) {
163             addCriterion("iduser not between", value1, value2, "iduser");
164             return (Criteria) this;
165         }
166 
167         public Criteria andUsernameIsNull() {
168             addCriterion("username is null");
169             return (Criteria) this;
170         }
171 
172         public Criteria andUsernameIsNotNull() {
173             addCriterion("username is not null");
174             return (Criteria) this;
175         }
176 
177         public Criteria andUsernameEqualTo(String value) {
178             addCriterion("username =", value, "username");
179             return (Criteria) this;
180         }
181 
182         public Criteria andUsernameNotEqualTo(String value) {
183             addCriterion("username <>", value, "username");
184             return (Criteria) this;
185         }
186 
187         public Criteria andUsernameGreaterThan(String value) {
188             addCriterion("username >", value, "username");
189             return (Criteria) this;
190         }
191 
192         public Criteria andUsernameGreaterThanOrEqualTo(String value) {
193             addCriterion("username >=", value, "username");
194             return (Criteria) this;
195         }
196 
197         public Criteria andUsernameLessThan(String value) {
198             addCriterion("username <", value, "username");
199             return (Criteria) this;
200         }
201 
202         public Criteria andUsernameLessThanOrEqualTo(String value) {
203             addCriterion("username <=", value, "username");
204             return (Criteria) this;
205         }
206 
207         public Criteria andUsernameLike(String value) {
208             addCriterion("username like", value, "username");
209             return (Criteria) this;
210         }
211 
212         public Criteria andUsernameNotLike(String value) {
213             addCriterion("username not like", value, "username");
214             return (Criteria) this;
215         }
216 
217         public Criteria andUsernameIn(List<String> values) {
218             addCriterion("username in", values, "username");
219             return (Criteria) this;
220         }
221 
222         public Criteria andUsernameNotIn(List<String> values) {
223             addCriterion("username not in", values, "username");
224             return (Criteria) this;
225         }
226 
227         public Criteria andUsernameBetween(String value1, String value2) {
228             addCriterion("username between", value1, value2, "username");
229             return (Criteria) this;
230         }
231 
232         public Criteria andUsernameNotBetween(String value1, String value2) {
233             addCriterion("username not between", value1, value2, "username");
234             return (Criteria) this;
235         }
236 
237         public Criteria andUserpasswordIsNull() {
238             addCriterion("userpassword is null");
239             return (Criteria) this;
240         }
241 
242         public Criteria andUserpasswordIsNotNull() {
243             addCriterion("userpassword is not null");
244             return (Criteria) this;
245         }
246 
247         public Criteria andUserpasswordEqualTo(String value) {
248             addCriterion("userpassword =", value, "userpassword");
249             return (Criteria) this;
250         }
251 
252         public Criteria andUserpasswordNotEqualTo(String value) {
253             addCriterion("userpassword <>", value, "userpassword");
254             return (Criteria) this;
255         }
256 
257         public Criteria andUserpasswordGreaterThan(String value) {
258             addCriterion("userpassword >", value, "userpassword");
259             return (Criteria) this;
260         }
261 
262         public Criteria andUserpasswordGreaterThanOrEqualTo(String value) {
263             addCriterion("userpassword >=", value, "userpassword");
264             return (Criteria) this;
265         }
266 
267         public Criteria andUserpasswordLessThan(String value) {
268             addCriterion("userpassword <", value, "userpassword");
269             return (Criteria) this;
270         }
271 
272         public Criteria andUserpasswordLessThanOrEqualTo(String value) {
273             addCriterion("userpassword <=", value, "userpassword");
274             return (Criteria) this;
275         }
276 
277         public Criteria andUserpasswordLike(String value) {
278             addCriterion("userpassword like", value, "userpassword");
279             return (Criteria) this;
280         }
281 
282         public Criteria andUserpasswordNotLike(String value) {
283             addCriterion("userpassword not like", value, "userpassword");
284             return (Criteria) this;
285         }
286 
287         public Criteria andUserpasswordIn(List<String> values) {
288             addCriterion("userpassword in", values, "userpassword");
289             return (Criteria) this;
290         }
291 
292         public Criteria andUserpasswordNotIn(List<String> values) {
293             addCriterion("userpassword not in", values, "userpassword");
294             return (Criteria) this;
295         }
296 
297         public Criteria andUserpasswordBetween(String value1, String value2) {
298             addCriterion("userpassword between", value1, value2, "userpassword");
299             return (Criteria) this;
300         }
301 
302         public Criteria andUserpasswordNotBetween(String value1, String value2) {
303             addCriterion("userpassword not between", value1, value2, "userpassword");
304             return (Criteria) this;
305         }
306 
307         public Criteria andUseraccountnumIsNull() {
308             addCriterion("useraccountnum is null");
309             return (Criteria) this;
310         }
311 
312         public Criteria andUseraccountnumIsNotNull() {
313             addCriterion("useraccountnum is not null");
314             return (Criteria) this;
315         }
316 
317         public Criteria andUseraccountnumEqualTo(String value) {
318             addCriterion("useraccountnum =", value, "useraccountnum");
319             return (Criteria) this;
320         }
321 
322         public Criteria andUseraccountnumNotEqualTo(String value) {
323             addCriterion("useraccountnum <>", value, "useraccountnum");
324             return (Criteria) this;
325         }
326 
327         public Criteria andUseraccountnumGreaterThan(String value) {
328             addCriterion("useraccountnum >", value, "useraccountnum");
329             return (Criteria) this;
330         }
331 
332         public Criteria andUseraccountnumGreaterThanOrEqualTo(String value) {
333             addCriterion("useraccountnum >=", value, "useraccountnum");
334             return (Criteria) this;
335         }
336 
337         public Criteria andUseraccountnumLessThan(String value) {
338             addCriterion("useraccountnum <", value, "useraccountnum");
339             return (Criteria) this;
340         }
341 
342         public Criteria andUseraccountnumLessThanOrEqualTo(String value) {
343             addCriterion("useraccountnum <=", value, "useraccountnum");
344             return (Criteria) this;
345         }
346 
347         public Criteria andUseraccountnumLike(String value) {
348             addCriterion("useraccountnum like", value, "useraccountnum");
349             return (Criteria) this;
350         }
351 
352         public Criteria andUseraccountnumNotLike(String value) {
353             addCriterion("useraccountnum not like", value, "useraccountnum");
354             return (Criteria) this;
355         }
356 
357         public Criteria andUseraccountnumIn(List<String> values) {
358             addCriterion("useraccountnum in", values, "useraccountnum");
359             return (Criteria) this;
360         }
361 
362         public Criteria andUseraccountnumNotIn(List<String> values) {
363             addCriterion("useraccountnum not in", values, "useraccountnum");
364             return (Criteria) this;
365         }
366 
367         public Criteria andUseraccountnumBetween(String value1, String value2) {
368             addCriterion("useraccountnum between", value1, value2, "useraccountnum");
369             return (Criteria) this;
370         }
371 
372         public Criteria andUseraccountnumNotBetween(String value1, String value2) {
373             addCriterion("useraccountnum not between", value1, value2, "useraccountnum");
374             return (Criteria) this;
375         }
376 
377         public Criteria andUseremailIsNull() {
378             addCriterion("useremail is null");
379             return (Criteria) this;
380         }
381 
382         public Criteria andUseremailIsNotNull() {
383             addCriterion("useremail is not null");
384             return (Criteria) this;
385         }
386 
387         public Criteria andUseremailEqualTo(String value) {
388             addCriterion("useremail =", value, "useremail");
389             return (Criteria) this;
390         }
391 
392         public Criteria andUseremailNotEqualTo(String value) {
393             addCriterion("useremail <>", value, "useremail");
394             return (Criteria) this;
395         }
396 
397         public Criteria andUseremailGreaterThan(String value) {
398             addCriterion("useremail >", value, "useremail");
399             return (Criteria) this;
400         }
401 
402         public Criteria andUseremailGreaterThanOrEqualTo(String value) {
403             addCriterion("useremail >=", value, "useremail");
404             return (Criteria) this;
405         }
406 
407         public Criteria andUseremailLessThan(String value) {
408             addCriterion("useremail <", value, "useremail");
409             return (Criteria) this;
410         }
411 
412         public Criteria andUseremailLessThanOrEqualTo(String value) {
413             addCriterion("useremail <=", value, "useremail");
414             return (Criteria) this;
415         }
416 
417         public Criteria andUseremailLike(String value) {
418             addCriterion("useremail like", value, "useremail");
419             return (Criteria) this;
420         }
421 
422         public Criteria andUseremailNotLike(String value) {
423             addCriterion("useremail not like", value, "useremail");
424             return (Criteria) this;
425         }
426 
427         public Criteria andUseremailIn(List<String> values) {
428             addCriterion("useremail in", values, "useremail");
429             return (Criteria) this;
430         }
431 
432         public Criteria andUseremailNotIn(List<String> values) {
433             addCriterion("useremail not in", values, "useremail");
434             return (Criteria) this;
435         }
436 
437         public Criteria andUseremailBetween(String value1, String value2) {
438             addCriterion("useremail between", value1, value2, "useremail");
439             return (Criteria) this;
440         }
441 
442         public Criteria andUseremailNotBetween(String value1, String value2) {
443             addCriterion("useremail not between", value1, value2, "useremail");
444             return (Criteria) this;
445         }
446     }
447 
448     public static class Criteria extends GeneratedCriteria {
449 
450         protected Criteria() {
451             super();
452         }
453     }
454 
455     public static class Criterion {
456         private String condition;
457 
458         private Object value;
459 
460         private Object secondValue;
461 
462         private boolean noValue;
463 
464         private boolean singleValue;
465 
466         private boolean betweenValue;
467 
468         private boolean listValue;
469 
470         private String typeHandler;
471 
472         public String getCondition() {
473             return condition;
474         }
475 
476         public Object getValue() {
477             return value;
478         }
479 
480         public Object getSecondValue() {
481             return secondValue;
482         }
483 
484         public boolean isNoValue() {
485             return noValue;
486         }
487 
488         public boolean isSingleValue() {
489             return singleValue;
490         }
491 
492         public boolean isBetweenValue() {
493             return betweenValue;
494         }
495 
496         public boolean isListValue() {
497             return listValue;
498         }
499 
500         public String getTypeHandler() {
501             return typeHandler;
502         }
503 
504         protected Criterion(String condition) {
505             super();
506             this.condition = condition;
507             this.typeHandler = null;
508             this.noValue = true;
509         }
510 
511         protected Criterion(String condition, Object value, String typeHandler) {
512             super();
513             this.condition = condition;
514             this.value = value;
515             this.typeHandler = typeHandler;
516             if (value instanceof List<?>) {
517                 this.listValue = true;
518             } else {
519                 this.singleValue = true;
520             }
521         }
522 
523         protected Criterion(String condition, Object value) {
524             this(condition, value, null);
525         }
526 
527         protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
528             super();
529             this.condition = condition;
530             this.value = value;
531             this.secondValue = secondValue;
532             this.typeHandler = typeHandler;
533             this.betweenValue = true;
534         }
535 
536         protected Criterion(String condition, Object value, Object secondValue) {
537             this(condition, value, secondValue, null);
538         }
539     }
540 }

 

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

 1 package com.pls.service.imp;
 2 
 3 import java.util.List;
 4 
 5 import javax.annotation.Resource;
 6 
 7 import org.springframework.stereotype.Service;
 8 
 9 import com.pls.mapper.UserMapper;
10 import com.pls.po.User;
11 import com.pls.po.UserExample;
12 import com.pls.po.UserExample.Criteria;
13 import com.pls.service.PlsService;
14 
15 @Service("plsService")
16 public class PlsServiceImp implements PlsService {
17 
18     @Resource
19     private UserMapper userDao;
20     
21     
22     @Override
23     public User getUserById(int iduser) {
24         // TODO Auto-generated method stub
25         return this.userDao.selectByPrimaryKey(iduser);
26     }
27     
28     @Override
29     public List<User> getAllUser() {
30         // TODO Auto-generated method stub
31         //List<User> list;
32         
33     
34         //UserExample e=new UserExample();
35         
36         List<User> list=this.userDao.getAllUser();
37         
38         return list;
39     }
40 
41     //根据用户名查找用户,主要用于登录时验证密码
42     @Override
43     public User getUserByUseraccountnum(String useraccountnum){
44         
45         //UserExample example= new UserExample();
46         //Criteria criteria=example.createCriteria();
47         //criteria.andUseraccountnumEqualTo(useraccountnum);
48         User user=this.userDao.selectByUseraccountnum(useraccountnum);
49         
50         
51         
52         return user;
53     }
54     
55     //删除方法
56     @Override
57     public void deleteUser(int iduser){
58         this.userDao.deleteByPrimaryKey(iduser);
59     }
60     
61     //根据名字或账号查询方法
62     @Override
63     public List<User> findByNameOrAccountnum(String nameOrAccountnum){
64         UserExample e1=new UserExample();
65         Criteria c1=e1.createCriteria();
66         c1.andUsernameLike("%"+nameOrAccountnum+"%");
67         List<User> list=this.userDao.selectByExample(e1);
68         UserExample e2=new UserExample();
69         Criteria c2=e2.createCriteria();
70         c2.andUseraccountnumLike("%"+nameOrAccountnum+"%");
71         list.addAll(this.userDao.selectByExample(e2));
72         return list;
73     }
74     
75     //插入的方法
76     @Override
77     public int insertUser(User user){
78         
79         int iduser=this.userDao.insert(user);
80         
81         return iduser;
82     }
83     
84     //更新用户
85     @Override
86     public int updateUser(User User){
87         
88         int iduser=this.userDao.updateByPrimaryKey(User);
89         
90         return iduser;
91         
92     }
93 }

 

控制层目录:

 

先看userController:

 1 package com.pls.controller;
 2 
 3 import javax.servlet.http.HttpServletRequest;
 4 
 5 import org.springframework.context.ApplicationContext;
 6 import org.springframework.context.support.ClassPathXmlApplicationContext;
 7 import org.springframework.stereotype.Controller;
 8 import org.springframework.ui.Model;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 
11 import com.pls.po.User;
12 import com.pls.service.PlsService;
13 
14 @Controller
15 @RequestMapping("/log")
16 public class UserController {
17 
18     ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "spring/applicationContext.xml",
19             "spring/applicationContext-dao.xml", "spring/applicationContext-service.xml" });
20     PlsService plsService = (PlsService) ac.getBean("plsService");
21 
22     //用于验证用户密码是否输入正确
23     @RequestMapping("/submit")
24     public String toIndex(HttpServletRequest request, Model model, String useraccountnum, String password) {
25         
26 
27         User user = this.plsService.getUserByUseraccountnum(useraccountnum);
28         if (user != null) {
29             if (user.getUserpassword().equals(password)) {
30 
31                 model.addAttribute("user", user);
32                 model.addAttribute("iduser", user.getIduser());
33                 return "index";
34 
35             } else {
36                 return "error";
37             }
38         } else {
39             return "error";
40         }
41 
42     }
43 
44     //跳转到登录页面
45     @RequestMapping("/login")
46     public String login(Model model) throws Exception {
47 
48         return "login";
49     }
50     
51     
52 }

 

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

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

manageController:

  1 package com.pls.controller;
  2 
  3 import java.util.List;
  4 
  5 import javax.servlet.http.HttpServletRequest;
  6 
  7 import org.springframework.context.ApplicationContext;
  8 import org.springframework.context.support.ClassPathXmlApplicationContext;
  9 import org.springframework.stereotype.Controller;
 10 import org.springframework.ui.Model;
 11 import org.springframework.web.bind.annotation.PathVariable;
 12 import org.springframework.web.bind.annotation.RequestMapping;
 13 import org.springframework.web.bind.annotation.RequestMethod;
 14 
 15 import com.pls.po.User;
 16 import com.pls.service.PlsService;
 17 
 18 @Controller
 19 @RequestMapping("/manage")
 20 public class MannageController {
 21 
 22     ApplicationContext ac = new ClassPathXmlApplicationContext(new String[] { "spring/applicationContext.xml",
 23             "spring/applicationContext-dao.xml", "spring/applicationContext-service.xml" });
 24     PlsService plsService = (PlsService) ac.getBean("plsService");
 25 
 26     @RequestMapping("/showUser")
 27     public String showUser(Model model) throws Exception {
 28 
 29         List<User> list = this.plsService.getAllUser();
 30         model.addAttribute("list", list);
 31 
 32         return "showUser";
 33     }
 34 
 35     @RequestMapping(value = "/deleteUser/{iduser}", method = RequestMethod.GET)
 36     public String deleteUser(HttpServletRequest request, Model model, @PathVariable int iduser) throws Exception {
 37 
 38         this.plsService.deleteUser(iduser);
 39         List<User> list = this.plsService.getAllUser();
 40         model.addAttribute("list", list);
 41 
 42         return "showUser";
 43     }
 44 
 45     @RequestMapping("/findUser")
 46     public String findUser(HttpServletRequest request, Model model, String nameOrAccountnum) throws Exception {
 47 
 48         // this.plsService.findByNameOrAccountnum(nameOrAccountnum);
 49         List<User> list = this.plsService.findByNameOrAccountnum(nameOrAccountnum);
 50         model.addAttribute("list", list);
 51 
 52         return "showUser";
 53     }
 54 
 55     // 跳转到填加管理员页面
 56     @RequestMapping("/addManage")
 57     public String addManage(Model model) throws Exception {
 58 
 59         return "addManage";
 60     }
 61 
 62     // 添加管理员
 63     @RequestMapping("/submitUser")
 64     public String submitUser(HttpServletRequest request, Model model, String accountnum, String userpassword,
 65             String username, String Email) throws Exception {
 66 
 67         User user = new User();
 68         user.setUseraccountnum(accountnum);
 69         user.setUseremail(Email);
 70         user.setUsername(username);
 71         user.setUserpassword(userpassword);
 72 
 73         int iduser = this.plsService.insertUser(user);
 74 
 75         if (iduser > 0) {
 76 
 77             List<User> list = this.plsService.getAllUser();
 78             model.addAttribute("list", list);
 79 
 80             return "showUser";
 81         }
 82 
 83         return "addUserError";
 84     }
 85 
 86     // 修改管理员
 87     @RequestMapping(value = "/updateUser/{iduser}", method = RequestMethod.GET)
 88     public String updateUser(HttpServletRequest request, Model model, @PathVariable int iduser) throws Exception {
 89 
 90         User user = this.plsService.getUserById(iduser);
 91         model.addAttribute("user", user);
 92 
 93         return "updateManage";
 94     }
 95 
 96     // 提交修改的管理员
 97     @RequestMapping("/updateUserSubmit")
 98     public String updateSubmitUser(HttpServletRequest request, Model model, String accountnum, String userpassword,
 99             String username, String Email, int iduser) throws Exception {
100 
101         User user = new User();
102         user.setUseraccountnum(accountnum);
103         user.setUseremail(Email);
104         user.setUsername(username);
105         user.setUserpassword(userpassword);
106         user.setIduser(iduser);
107 
108         if (this.plsService.updateUser(user) > 0) {
109 
110             List<User> list = this.plsService.getAllUser();
111             model.addAttribute("list", list);
112 
113             return "showUser";
114         }
115         return null;
116     }
117 
118 }

 

webContent目录:

 

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

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6     <title></title>
 7     <meta charset="UTF-8">
 8     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
 9     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
10     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
11     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
12     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
13     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
14     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
15     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script>
16     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquerypicture.js"></script>
17     
18     <style type="text/css">
19         body {font-size: 20px;
20             padding-bottom: 40px;
21             background-color:#e9e7ef;
22         }
23         .sidebar-nav {
24             padding: 9px 0;
25         }
26 
27         @media (max-width: 980px) {
28             /* Enable use of floated navbar text */
29             .navbar-text.pull-right {
30                 float: none;
31                 padding-left: 5px;
32                 padding-right: 5px;
33             }
34         }
35 
36 
37     </style>
38 </head>
39 <body>
40 <br>
41  <font color="#777777"><strong>请填写管理员资料:</strong></font>
42 <form action="${pageContext.request.contextPath }/manage/submitUser.action" method="post" class="definewidth m20" >
43 <table class="table table-bordered table-hover m10" style="margin-left:10px;margin-top:3px;">
44     
45    
46    <br>
47     <tr>
48         <td class="tableleft">账号</td>
49         <td><input type="text" name="accountnum"  /></td>
50         <td class="tableleft">密码</td>
51         <td><input type="text" name="userpassword"  /></td>
52     </tr>
53     <tr>
54         <td class="tableleft">姓名</td>
55         <td><input type="text" name="username"   /></td>
56         <td class="tableleft">邮箱</td>
57         <td><input type="text" name="Email"  /></td>
58     </tr>
59     
60     
61 </table>
62 <br>
63 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<button type="submit" onclick="${pageContext.request.contextPath }/manage/submitUser.action" class="btn btn-primary">提交</button>
64 </form>
65  <img src="" id="img0" > 
66  
67 <script>    
68 $("#GoodsPicture").change(function(){
69     var objUrl = getObjectURL(this.files[0]) ;
70     console.log("objUrl = "+objUrl) ;
71     if (objUrl) {
72         $("#img0").attr("src", objUrl) ;
73     }
74 }) ;
75 
76 </body>
77 </html>
78 <script>
79    $(function (){       
80         $('#backid').click(function(){
81                 window.location.href="goodsQuery.html";
82          });
83     });
84         
85 </script>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html lang="zh">
 5 <head>
 6 <meta charset="UTF-8">
 7 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
 8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 9 <title>插入用户错误错误</title>
10   
11 
12 
13 
14 
15 </head>
16 <body>
17 
18 
19 <h1>插入用户错误错误</h1>
20 
21 
22 </body>
23 </html>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html lang="zh">
 5 <head>
 6 <meta charset="UTF-8">
 7 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
 8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 9 <title>错误</title>
10   
11 
12 
13 
14 
15 </head>
16 <body>
17 
18 
19 <h1>不存在的用户或用户名密码错误</h1>
20 
21 
22 </body>
23 </html>

 

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4 
  5 <html>
  6 <head>
  7 <meta charset="utf-8">
  8 <title>零件库管理系统</title>
  9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 10 <link href="../html/Css/adminStyle.css" rel="stylesheet" type="text/css" />
 11 
 12 <title>零件库管理系统</title>
 13 <script type="text/javascript" src="../html/js/jquery1.js"></script>
 14 <script type="text/javascript">
 15     $(document).ready(
 16             function() {
 17                 $(".div2").click(
 18                         function() {
 19                             $(this).next("div").slideToggle("slow").siblings(
 20                                     ".div3:visible").slideUp("slow");
 21                         });
 22             });
 23     function openurl(url) {
 24         var rframe = parent.document.getElementById("rightFrame");
 25         rframe.src = url;
 26     }
 27 </script>
 28 <style>
 29 body {
 30     margin: 0;
 31     font-family: 微软雅黑;
 32     background-image: url(images/.jpg);
 33     background-repeat: no-repea;
 34     background-size: cover;
 35     background-attachment: fixed;
 36     background-color: #DDDDDD
 37     
 38 }
 39 
 40 .top1 {
 41     position: absolute;
 42     top: 0px;
 43     width: 100%;
 44     height: 20px;
 45     text-align: center;
 46     color: #FFFFFF;
 47     font-size: 17px;
 48     font-height: 20px;
 49     font-family: 楷体;
 50     background-color: #888888
 51 }
 52 
 53 .title {
 54 float:left;
 55     margin:-32px 20px;
 56     font-size: 40px;
 57     color: #FFFFFF;
 58     font-height: 55px;
 59     font-family: 隶书;
 60 }
 61 
 62 .top2 {
 63     position: absolute;
 64     top: 20px;
 65     width: 100%;
 66     height: 77px;
 67     text-align: center;
 68     color: #ccffff;
 69     background-color: #888888
 70 }
 71 
 72 .left {
 73     position: absolute;
 74     left: 0px;
 75     top: 97px;
 76     width: 200px;
 77     height: 85%;
 78     border-right: 1px solid #9370DB;
 79     color: #000000;
 80     font-size: 20px;
 81     text-align: center;
 82     background-color: #B3B3B3
 83 }
 84 
 85 .right {
 86     position: absolute;
 87     left: 200px;
 88     top:97px;
 89     width: 85.2%;
 90     height: 85%;
 91     border-top: 0px solid #484860;
 92     font-size: 14px;
 93     text-align: center;
 94 }
 95 
 96 .end {
 97     position: absolute;
 98     bottom: 0px;
 99     width: 100%;
100     height: 30px;
101     text-align: center;
102     color: #556B2F;
103     font-size: 17px;
104     font-height: 20px;
105     font-family: 楷体;
106     background-color: #C0C0C0
107 }
108 
109 .div1 {
110     text-align: center;
111     width: 200px;
112     padding-top: 10px;
113 }
114 
115 .div2 {
116     height: 40px;
117     line-height: 40px;
118     cursor: pointer;
119     font-size: 18px;
120     position: relative;
121     border-bottom: #ccc 0px dotted;
122 }
123 
124 .spgl {
125     position: absolute;
126     height: 20px;
127     width: 20px;
128     left: 40px;
129     top: 10px;
130     background: url(images/1.png);
131 }
132 
133 .yhgl {
134     position: absolute;
135     height: 20px;
136     width: 20px;
137     left: 40px;
138     top: 10px;
139     background: url(images/4.png);
140 }
141 
142 .gggl {
143     position: absolute;
144     height: 20px;
145     width: 20px;
146     left: 40px;
147     top: 10px;
148     background: url(images/4.png);
149 }
150 
151 .zlgl {
152     position: absolute;
153     height: 20px;
154     width: 20px;
155     left: 40px;
156     top: 10px;
157     background: url(images/4.png);
158 }
159 
160 .pjgl {
161     position: absolute;
162     height: 20px;
163     width: 20px;
164     left: 40px;
165     top: 10px;
166     background: url(images/4.png);
167 }
168 
169 .tcht {
170     position: absolute;
171     height: 20px;
172     width: 20px;
173     left: 40px;
174     top: 10px;
175     background: url(images/2.png);
176 }
177 
178 .div3 {
179     display: none;
180     cursor: pointer;
181     font-size: 15px;
182 }
183 
184 .div3 ul {
185     margin: 0;
186     padding: 0;
187 }
188 
189 .div3 li {
190     height: 30px;
191     line-height: 30px;
192     list-style: none;
193     border-bottom: #ccc 1px dotted;
194     text-align: center;
195 }
196 
197 .a {
198     text-decoration: none;
199     color: #000000;
200     font-size: 15px;
201 }
202 
203 .a1 {
204     text-decoration: none;
205     color: #000000;
206     font-size: 18px;
207 }
208 </style>
209 </head>
210 <body>
211 
212     <div class="top1">
213         <marquee scrollAmount=2 width=300>数据无价,请谨慎操作!</marquee>
214     </div>
215     <div class="top2">
216         <div class="logo">
217             <img src="../html/images/admin_logo.png" title="在哪儿" />
218         </div>
219         <div class="title" >
220             <h3>零件库管理系统</h3>
221         </div>
222         <div class="fr top-link">
223             <a href="admin_list.html" target="mainCont" title="DeathGhost"><i
224                 class="adminIcon"></i><span>管理员:${user.username }</span></a> 
225         </div>
226     </div>
227 
228     <div class="left">
229         <div class="div1">
230             <div class="left_top">
231                 <img src="../html/images/bbb_01.jpg"><img src="../html/images/bbb_02.jpg"
232                     id="2"><img src="../html/images/bbb_03.jpg"><img
233                     src="../html/images/bbb_04.jpg">
234             </div>
235             
236            <div class="div2">
237                 <div class="spgl"></div>
238                 视频管理
239             </div>
240             <div class="div3">
241                 <li><a class="a" href="javascript:void(0);"
242                     onClick="openurl('videoQuery.html');">查看所有视频</a></li>
243                 <li><a class="a" href="javascript:void(0);"
244                     onClick="openurl('uservideoQuery.html');">用户视频列表</a></li>
245                
246             </div>
247             <div class="div2">
248                 <div class="spgl"></div>
249                 文档管理
250             </div>
251             <div class="div3">
252                 <ul>
253                     <li><a class="a" href="javascript:void(0);"
254                         onClick="openurl('documentQuery.html');">查看所有文档</a></li>
255                         <li><a class="a" href="javascript:void(0);"
256                         onClick="openurl('userdocumentQuery.html');">用户文档列表</a></li>
257                     
258                 </ul>
259             </div>
260             <div class="div2">
261                 <div class="spgl"></div>
262                 类别管理
263             </div>
264             <div class="div3">
265                 <ul>
266                     <li><a class="a" href="javascript:void(0);"
267                         onClick="openurl('classQuery.html');">大类信息</a></li>
268                         
269                 </ul>
270             </div>
271             <div class="div2">
272                 <div class="yhgl"></div>
273                 用户管理
274             </div>
275             <div class="div3">
276                 <ul>
277                     <li><a class="a" href="javascript:void(0);"
278                         onClick="openurl('studentQuery.html');">学生管理</a></li>
279                     <li><a class="a" href="javascript:void(0);"
280                         onClick="openurl('${pageContext.request.contextPath }/manage/showUser.action');">老师管理</a></li>
281                 </ul>
282             </div>
283             
284             <div class="div2">
285                 <div class="gggl"></div>
286                 评价管理
287             </div>
288             <div class="div3">
289 
290                 <ul>
291                     <li><a class="a" href="javascript:void(0);"
292                         onClick="openurl('deletecomment.html');">评价删除</a></li>
293                     <li><a class="a" href="javascript:void(0);"
294                         onClick="openurl('useredit.html');">用户禁言</a></li>
295                 </ul>
296 
297             </div>
298             <div class="div2">
299                 <div class="pjgl"></div>
300                 公告管理
301             </div>
302             <div class="div3">
303                 <ul>
304                     <li><a class="a" href="javascript:void(0);"
305                         onClick="openurl('afficheQuery.html');">查看公告</a></li>
306                     <li><a class="a" href="javascript:void(0);"
307                         onClick="openurl('afficheAdd.html');">添加公告</a></li>
308                 </ul>
309             </div>
310             <a class="a1" href="login.html"><div class="div2">
311                     <div class="tcht"></div>
312                     退出后台
313                 </div></a>
314         </div>
315     </div>
316 
317     <div class="right">
318         <iframe id="rightFrame" name="rightFrame" width="100%" height="100%"
319             scrolling="auto" marginheight="0" marginwidth="0" align="center"
320             style="border: 0px solid #CCC; margin: 0; padding: 0;"></iframe>
321     </div>
322 
323 
324 
325 
326 
327 
328 
329 </body>
330 </html>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html lang="zh">
 5 <head>
 6 <meta charset="UTF-8">
 7 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
 8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 9 <title>零件库管理系统登录界面</title>
10   
11 <link rel="stylesheet" type="text/css" href="../html/Css/styles.css">
12 
13 
14 
15 </head>
16 <body>
17 
18 
19 <div class="wrapper">
20 
21     <div class="container">
22         <h1>零件库管理系统</h1>
23         <form class="form" action="${pageContext.request.contextPath }/log/submit.action" method="post">
24             <input type="text" placeholder="Username" name="useraccountnum">
25             <input type="password" placeholder="Password" name="password"><br>
26             <button type="submit" id="login-button" onclick="${pageContext.request.contextPath }/log/submit.action"><strong>登陆</strong></button>
27             
28         </form>
29     </div>
30     
31     <ul class="bg-bubbles">
32         <li></li>
33         <li></li>
34         
35     </ul>
36     
37 </div>
38 
39 
40 
41 </body>
42 </html>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
 4 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 6 <html>
 7 <head>
 8 <title></title>
 9 <meta charset="UTF-8">
10 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
11 <link rel="stylesheet" type="text/css"
12     href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
13 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
14 <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
15 <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
16 <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
17 <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
18 <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script>
19 
20 <style type="text/css">
21 body {
22     font-size: 20px;
23     padding-bottom: 40px;
24     background-color: #e9e7ef;
25 }
26 
27 .sidebar-nav {
28     padding: 9px 0;
29 }
30 
31 @media ( max-width : 980px) {
32     /* Enable use of floated navbar text */
33     .navbar-text.pull-right {
34         float: none;
35         padding-left: 5px;
36         padding-right: 5px;
37     }
38 }
39 </style>
40 </head>
41 <body>
42     <form class="form-inline definewidth m20" action="${pageContext.request.contextPath }/manage/findUser.action" method="post">
43         <font color="#777777"><strong>管理员姓名或账号:</strong></font> <input
44             type="text" name="nameOrAccountnum" id="menuname" class="abc input-default"
45             placeholder="" value="">&nbsp;&nbsp;
46         <button type="submit" class="btn btn-primary">查询</button>
47         <button type="button" id="addnew">
48             <a href="${pageContext.request.contextPath }/manage/addManage.action">添加管理员</a>
49         </button>
50     </form>
51     <table class="table table-bordered table-hover definewidth m10">
52         <thead>
53             <tr>
54                 <th>管理员姓名</th>
55 
56                 <th>管理员账号</th>
57 
58                 <th>Email</th>
59                 <th>注销账户</th>
60                 <th>修改用户</th>
61             </tr>
62         </thead>
63         <c:forEach items="${list}" var="manage">
64         <tr>
65             <!-- <a href="teacherdetail.html">nblyp</a>    -->
66             <td>${manage.username }</td>
67 
68             <td>${manage.useraccountnum }</td>
69             <td>${manage.useremail }</td>
70             <!-- 
71             <td><button type="submit" onclick="${pageContext.request.contextPath }/manage/deleteUser/${manage.iduser }.action" method="get">注销</button></td>
72              -->
73             <td><a href="${pageContext.request.contextPath }/manage/deleteUser/${manage.iduser }.action">注销</a></td>
74             <td><a href="${pageContext.request.contextPath }/manage/updateUser/${manage.iduser }.action">修改</a></td>
75         </tr>
76         </c:forEach>
77          
78 
79     </table>
80 
81 </body>
82 </html>

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6     <title></title>
 7     <meta charset="UTF-8">
 8     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap.css" />
 9     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/bootstrap-responsive.css" />
10     <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/html/Css/style.css" />
11     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.js"></script>
12     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquery2.sorted.js"></script>
13     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/bootstrap.js"></script>
14     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/ckform.js"></script>
15     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/common.js"></script>
16     <script type="text/javascript" src="<%=request.getContextPath() %>/html/js/jquerypicture.js"></script>
17     
18     <style type="text/css">
19         body {font-size: 20px;
20             padding-bottom: 40px;
21             background-color:#e9e7ef;
22         }
23         .sidebar-nav {
24             padding: 9px 0;
25         }
26 
27         @media (max-width: 980px) {
28             /* Enable use of floated navbar text */
29             .navbar-text.pull-right {
30                 float: none;
31                 padding-left: 5px;
32                 padding-right: 5px;
33             }
34         }
35 
36 
37     </style>
38 </head>
39 <body>
40 <br>
41  <font color="#777777"><strong>请填写管理员资料:</strong></font>
42 <form  action="${pageContext.request.contextPath }/manage/updateUserSubmit.action" method="post" class="definewidth m20" >
43 <table class="table table-bordered table-hover m10" style="margin-left:10px;margin-top:3px;">
44     
45    
46    <br>
47     <tr>
48     
49         <td class="tableleft">账号</td>
50         <td><input type="text" name="accountnum" value=${user.useraccountnum}  /></td>
51         <td class="tableleft">密码</td>
52         <td><input type="text" name="userpassword" value=${user.userpassword}  /></td>
53     </tr>
54     <tr>
55         <td class="tableleft">真实姓名</td>
56         <td><input type="text" name="username" value=${user.username}  /></td>
57         <td class="tableleft">邮箱</td>
58         <td><input type="text" name="Email" value=${user.useremail} /></td>
59     </tr>
60     <input type="hidden"  name="iduser" value=${user.iduser}  />
61     
62 </table>
63 <br>
64 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<button type="submit" onclick="${pageContext.request.contextPath }/manage/updateUserSubmit.action" class="btn btn-primary">提交</button>
65 </form>
66  <img src="" id="img0" > 
67  
68 <script>    
69 $("#GoodsPicture").change(function(){
70     var objUrl = getObjectURL(this.files[0]) ;
71     console.log("objUrl = "+objUrl) ;
72     if (objUrl) {
73         $("#img0").attr("src", objUrl) ;
74     }
75 }) ;
76 
77 </body>
78 </html>
79 <script>
80    $(function (){       
81         $('#backid').click(function(){
82                 window.location.href="goodsQuery.html";
83          });
84     });
85         
86 </script>

 

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

来看看最后效果:

 

 

 

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

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

 

posted @ 2017-03-24 00:07  HelloWorld_Du  阅读(900)  评论(0编辑  收藏  举报