基于Spring MVC + Spring + MyBatis的【野生动物保护系统】
資源下載:https://download.csdn.net/download/weixin_44893902/45603787
練習(xí)點(diǎn)設(shè)計(jì): 模糊查詢、刪除、新增、修改
一、語(yǔ)言和環(huán)境
二、實(shí)現(xiàn)功能
隨著社會(huì)的發(fā)展,人與動(dòng)物需要和諧共處,現(xiàn)需要制作野生動(dòng)物保護(hù)系統(tǒng),主要功能如下:
1.首頁(yè)默認(rèn)顯示所有動(dòng)物列表,如圖1所示。
2.鼠標(biāo)懸停某行數(shù)據(jù)時(shí),以線性過(guò)渡動(dòng)畫(huà)顯示光棒效果,如圖2所示。
3.用戶輸入動(dòng)物名稱,則完成模糊查詢,顯示查詢結(jié)果,如圖3所示。
4.用戶點(diǎn)擊升級(jí)或降級(jí)時(shí),則彈出提示框,用戶點(diǎn)擊確定后,修改選中數(shù)據(jù)并顯示最新數(shù)據(jù),如圖4和圖5所示。
5.用戶點(diǎn)擊“新增”鏈接,則打開(kāi)新增頁(yè)面,填寫完相關(guān)信息后點(diǎn)擊添加按鈕,增加野生動(dòng)物信息數(shù)據(jù)到數(shù)據(jù)庫(kù),且頁(yè)面跳轉(zhuǎn)到列表頁(yè)面展示最新數(shù)據(jù),如圖6和圖7所示。
三、 數(shù)據(jù)庫(kù)設(shè)計(jì)
1.創(chuàng)建數(shù)據(jù)庫(kù)(animal_db)。
2.創(chuàng)建數(shù)據(jù)表(tb_type),結(jié)構(gòu)如下。
| type_id | 類型編號(hào) | int | 主鍵,自增,增量為1 | |
| type_name | 類型名稱 | varchar | 50 | 不能為空 |
3.創(chuàng)建數(shù)據(jù)表(tb_animal),結(jié)構(gòu)如下。
| id | 編號(hào) | int | 主鍵,自增,增量為1 | |
| name | 動(dòng)物品種 | varchar | 50 | 不能為空 |
| count | 動(dòng)物數(shù)量 | int | 不能為空 | |
| level | 保護(hù)等級(jí) | int | 不能為空 | |
| type_id | 類型編號(hào) | int | 外鍵 |
四、推薦實(shí)現(xiàn)步驟
1.SSM版本的實(shí)現(xiàn)步驟如下:
(1)創(chuàng)建數(shù)據(jù)庫(kù)和數(shù)據(jù)表,添加測(cè)試數(shù)據(jù)(至少添加3條測(cè)試數(shù)據(jù))。
(2)創(chuàng)建Web工程并創(chuàng)建各個(gè)包,導(dǎo)入工程所需的jar文件。
(3)添加相關(guān)SSM框架支持。
(4)配置項(xiàng)目所需要的各種配置文件(mybatis配置文件、spring配置文件、springMVC配置文件)。
(5)創(chuàng)建實(shí)體類。
(6)創(chuàng)建MyBatis操作數(shù)據(jù)庫(kù)所需的Mapper接口及其Xml映射數(shù)據(jù)庫(kù)操作語(yǔ)句文件。
(7)創(chuàng)建業(yè)務(wù)邏輯相應(yīng)的接口及其實(shí)現(xiàn)類,實(shí)現(xiàn)相應(yīng)的業(yè)務(wù),并在類中加入對(duì)DAO/Mapper的引用和注入。
(8)創(chuàng)建Controller控制器類,在Controller中添加對(duì)業(yè)務(wù)邏輯類的引用和注入,并配置springMVC配置文件。
(9)創(chuàng)建相關(guān)的操作頁(yè)面,并使用CSS對(duì)頁(yè)面進(jìn)行美化。
(10)實(shí)現(xiàn)頁(yè)面的各項(xiàng)操作功能,并在相關(guān)地方進(jìn)行驗(yàn)證,操作要人性化。
(11)調(diào)試運(yùn)行成功后導(dǎo)出相關(guān)的數(shù)據(jù)庫(kù)文件并提交。
五、實(shí)現(xiàn)代碼
1、MySQL數(shù)據(jù)庫(kù)
animal_db.sql
2、項(xiàng)目Java代碼
目錄結(jié)構(gòu)
animal_db
JAR包:
src
com.controller
AnimaalController.java
package com.controller;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.entity.TbAnimal; import com.services.AnimmailServices;@Controller public class AnimaalController {@Resourceprivate AnimmailServices animmailServices;//查詢@RequestMapping("/getList")public String getAniamal(Model model,String name) {List<TbAnimal> list=animmailServices.getAnimals(name);if (name==null||name.trim().equals("")) {name=null;}model.addAttribute("getList", list);int size=list.size();model.addAttribute("sizes", size);return "Animal";}//錄入@RequestMapping("/insert")public String getInsert(Model model,TbAnimal animal) {int count=animmailServices.inser(animal);return "redirect:/getList.do";}//進(jìn)入新增頁(yè)面@RequestMapping("/intoAdd")public String into() {return "addAnimal";}//降級(jí)@RequestMapping("/upDown")public String upDown(Model model,TbAnimal animal) {int upDown=animmailServices.down(animal);return "redirect:/getList.do";}//升級(jí)@RequestMapping("/updateDown")public String updateDown(Model model,TbAnimal animal) {int updateDown=animmailServices.upDown(animal);return "redirect:/getList.do";}}com.dao
TbAnimalMapper.java
package com.dao;import com.entity.TbAnimal; import java.util.List;public interface TbAnimalMapper {int deleteByPrimaryKey(Integer id);int insert(TbAnimal record);TbAnimal selectByPrimaryKey(Integer id);List<TbAnimal> selectAll();int updatedown(TbAnimal record);int updateUpdown(TbAnimal record);//模糊查詢List<TbAnimal> selectLikeAll (String name);}TbTypeMapper.java
package com.dao;import com.entity.TbType; import java.util.List;public interface TbTypeMapper {int deleteByPrimaryKey(Integer typeId);int insert(TbType record);TbType selectByPrimaryKey(Integer typeId);List<TbType> selectAll();int updateByPrimaryKey(TbType record); }TbAnimalMapper.xml
<?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.dao.TbAnimalMapper" ><resultMap id="BaseResultMap" type="com.entity.TbAnimal" ><id column="id" property="id" jdbcType="INTEGER" /><result column="name" property="name" jdbcType="VARCHAR" /><result column="count" property="count" jdbcType="INTEGER" /><result column="level" property="level" jdbcType="INTEGER" /><result column="type_id" property="typeId" jdbcType="INTEGER" /></resultMap><delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >delete from tb_animalwhere id = #{id,jdbcType=INTEGER}</delete><insert id="insert" parameterType="com.entity.TbAnimal" >insert into tb_animal (id, name, count, level, type_id)values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{count,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, #{typeId,jdbcType=INTEGER})</insert><!--降級(jí) --><update id="updatedown" parameterType="com.entity.TbAnimal" >update tb_animalset level = level-1where id = #{id,jdbcType=INTEGER}</update><!--升級(jí) --><update id="updateUpdown" parameterType="com.entity.TbAnimal" >update tb_animalset level = level+1where id = #{id,jdbcType=INTEGER}</update><select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >select id, name, count, level, type_idfrom tb_animalwhere id = #{id,jdbcType=INTEGER}</select><!--查詢 --><select id="selectAll" resultMap="BaseResultMap" >select id, name, count, level, type_idfrom tb_animal</select><!--模糊查詢 --><select id="selectLikeAll" resultMap="BaseResultMap" >select id, name, count, level, type_idfrom tb_animalwhere name like "%"#{name}"%"</select> </mapper>TbTypeMapper.xml
<?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.dao.TbTypeMapper" ><resultMap id="BaseResultMap" type="com.entity.TbType" ><id column="type_id" property="typeId" jdbcType="INTEGER" /><result column="type_name" property="typeName" jdbcType="VARCHAR" /></resultMap><delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >delete from tb_typewhere type_id = #{typeId,jdbcType=INTEGER}</delete><insert id="insert" parameterType="com.entity.TbType" >insert into tb_type (type_id, type_name)values (#{typeId,jdbcType=INTEGER}, #{typeName,jdbcType=VARCHAR})</insert><update id="updateByPrimaryKey" parameterType="com.entity.TbType" >update tb_typeset type_name = #{typeName,jdbcType=VARCHAR}where type_id = #{typeId,jdbcType=INTEGER}</update><select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >select type_id, type_namefrom tb_typewhere type_id = #{typeId,jdbcType=INTEGER}</select><select id="selectAll" resultMap="BaseResultMap" >select type_id, type_namefrom tb_type</select> </mapper>com.entity
TbAnimal.java
package com.entity;public class TbAnimal {private Integer id;private String name;private Integer count;private Integer level;private Integer typeId;private String typeName;public String getTypeName() {return typeName;}public void setTypeName(String typeName) {this.typeName = typeName == null ? null : typeName.trim();}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name == null ? null : name.trim();}public Integer getCount() {return count;}public void setCount(Integer count) {this.count = count;}public Integer getLevel() {return level;}public void setLevel(Integer level) {this.level = level;}public Integer getTypeId() {return typeId;}public void setTypeId(Integer typeId) {this.typeId = typeId;} }TbType.java
package com.entity;public class TbType {private Integer typeId;private String typeName;public Integer getTypeId() {return typeId;}public void setTypeId(Integer typeId) {this.typeId = typeId;}public String getTypeName() {return typeName;}public void setTypeName(String typeName) {this.typeName = typeName == null ? null : typeName.trim();} }com.generator
Generator.java
package com.generator;import java.io.IOException; import java.io.InputStream; import java.sql.SQLException; 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.exception.InvalidConfigurationException; import org.mybatis.generator.exception.XMLParserException; import org.mybatis.generator.internal.DefaultShellCallback;public class Generator {/** targetRuntime="MyBatis3Simple", 不生成Example*/public void generateMyBatis() {//MBG執(zhí)行過(guò)程中的警告信息List<String> warnings = new ArrayList<String>();//當(dāng)生成的代碼重復(fù)時(shí),覆蓋原代碼boolean overwrite = true ;//String generatorFile = "/generator/generatorConfig.xml";String generatorFile = "/generatorConfig.xml";//讀取MBG配置文件InputStream is = Generator.class.getResourceAsStream(generatorFile);ConfigurationParser cp = new ConfigurationParser(warnings);Configuration config;try {config = cp.parseConfiguration(is);DefaultShellCallback callback = new DefaultShellCallback(overwrite);//創(chuàng)建MBGMyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);//執(zhí)行生成代碼myBatisGenerator.generate(null);} catch (IOException e) {e.printStackTrace();} catch (XMLParserException e) {e.printStackTrace();} catch (InvalidConfigurationException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();}for (String warning : warnings) {System.out.println(warning);}}public static void main(String[] args) {Generator generator = new Generator();generator.generateMyBatis();} }com.serviceImpi
AnimamalServicesImpi.java
package com.serviceImpi;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Service;import com.dao.TbAnimalMapper; import com.entity.TbAnimal; import com.services.AnimmailServices; @Service public class AnimamalServicesImpi implements AnimmailServices {@Resourceprivate TbAnimalMapper tbanimail;//查詢@Overridepublic List<TbAnimal> getAnimals(String name) {if (name==null||name.equals("")) {List<TbAnimal> getList=tbanimail.selectAll();return getList;} else { List<TbAnimal> getLikeList=tbanimail.selectLikeAll(name);return getLikeList ;}}//錄入@Overridepublic int inser(TbAnimal animal) {int count=tbanimail.insert(animal);return count;}@Overridepublic int down(TbAnimal animal) {int upDown=tbanimail.updatedown(animal);return upDown;}//升級(jí)@Overridepublic int upDown(TbAnimal animal) {int upDown=tbanimail.updateUpdown(animal);return upDown;}}com.services
AnimmailServices.java
package com.services;import java.util.List;import com.entity.TbAnimal;public interface AnimmailServices {//查詢List<TbAnimal> getAnimals(String name);//錄入int inser(TbAnimal animal);//降級(jí)int down(TbAnimal animal);//升級(jí)int upDown(TbAnimal animal); }mybatis
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.entity" /></typeAliases> </configuration>spring
applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" 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-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "><!-- 指定spring容器讀取db.properties文件 --><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder><!-- 將連接池注冊(cè)到bean容器中 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"></property><property name="Url" value="${jdbc.url}"></property><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!-- 配置SqlSessionFactory --><bean class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 設(shè)置MyBatis核心配置文件 --><property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" /><!-- 設(shè)置數(shù)據(jù)源 --><property name="dataSource" ref="dataSource" /></bean><!-- 配置Mapper掃描 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 設(shè)置Mapper掃描包 --><property name="basePackage" value="com.dao" /></bean><!-- 配置事務(wù)管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 開(kāi)啟注解方式管理AOP事務(wù) --><tx:annotation-driven transaction-manager="transactionManager" /> </beans>applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "><!-- 配置Service掃描 --><context:component-scan base-package="com" /> </beans>spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd "><!-- 配置Controller掃描 --><context:component-scan base-package="com.controller" /><!-- 配置注解驅(qū)動(dòng) --><mvc:annotation-driven /><!-- 配置視圖解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 前綴 --><property name="prefix" value="/WEB-INF/jsp/" /><!-- 后綴 --><property name="suffix" value=".jsp" /></bean> </beans>generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <!-- 配置生成器 --> <generatorConfiguration><context id="MySQLContext" targetRuntime="MyBatis3Simple" defaultModelType="flat"><!-- 配置前置分隔符和后置分隔符 --><property name="beginningDelimiter" value="`"/><property name="endingDelimiter" value="`"/><!-- 配置注釋信息 --><commentGenerator><!-- 不生成注釋 --><property name="suppressAllComments" value="true"/><property name="suppressDate" value="true"/><property name="addRemarkComments" value="true"/></commentGenerator><!-- 數(shù)據(jù)庫(kù)連接配置 --><jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/animal_db"userId="root" password="root"></jdbcConnection><!-- targetPackage:生成實(shí)體類存放的包名, targetProject:指定目標(biāo)項(xiàng)目路徑,可以使用相對(duì)路徑或絕對(duì)路徑 --><javaModelGenerator targetPackage="com.entity" targetProject="src"><property name="trimStrings" value="true"/></javaModelGenerator><!-- 配置SQL映射器Mapper.xml文件的屬性 --><sqlMapGenerator targetPackage="com.dao" targetProject="src"/><!-- type="XMLMAPPER":所有的方法都在XML中,接口調(diào)用依賴XML文件 --><javaClientGenerator targetPackage="com.dao" type="XMLMAPPER" targetProject="src"/><!-- 生成所有表的映射 --><table tableName="%"></table> </context> </generatorConfiguration>jdbc.properties
jdbc.url=jdbc:mysql://localhost:3306/animal_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false jdbc.username=root jdbc.password=123456 jdbc.driver=com.mysql.jdbc.Driverlog4j.properties
# 全局配置 log4j.rootLogger=ERROR, stdout # MyBatis日志配置 log4j.logger.com.lxh.mapper=TRACE # 控制臺(tái)輸出配置 log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%nWebContent
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>animal_db</display-name><welcome-file-list><welcome-file>index.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>classpath:spring/applicationContext-*.xml</param-value></context-param><!-- 監(jiān)聽(tīng)器,加載spring配置 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 前端控制器 --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><!-- 設(shè)置post請(qǐng)求的字符編碼過(guò)濾器 --><filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping> </web-app>JSP
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body><script>window.location.href = "getList.do";</script> </body> </html>addAnimal.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>錄入新同學(xué)</title> <style type="text/css"> table {margin: auto; }.button {margin: auto; } </style> </head> <body><form action="insert.do"><table border="0" cellspacing="" cellpadding=""><tr><td> <h1 style="text-align:;">新增頁(yè)面</h1></td></tr><tr><td>品種: <input type="text" name="name"value="${list.name}"></td></tr><tr><td>數(shù)量: <input type="text" name="count"value="${list.count}"></td></tr><tr><td>等級(jí): <input type="text" name="level"value="${list.level}"></td></tr><tr><td>類別: <input type="radio"name="typeId" value="1" <c:if test="${list.typeId==1}"></c:if>>魚(yú)類<input type="radio" name="typeId" value="2"<c:if test="${list.typeId==2}"></c:if>>鳥(niǎo)類</td></tr><tr><td><input style="width: 100px;" type="submit" value="確定" /> <input style="width: 100px;" type="reset" value="取消"onclick="retuns()" /></td></tr></table></form><script type="text/javascript">function retuns() {window.location.href = "getList.do";}</script> </body> </html>Animal.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> <style type="text/css">tr:hover {background: orange;}#app {width: 800px;margin: 0 auto;}table {border: 1px solid black;margin: 0 auto;width: 100%;}th, td {border: 1px solid black}table, td, th {border-collapse: collapse;border-spacing: 0;}td {text-align: center;}#end {margin-left: 650px;} </style> <body><div id="app"><fieldset><form action="getList.do" method="get">品種: <input type="text" name="name" /> <input type="submit"value="搜索" /></form></fieldset><table><tr><th>編號(hào)</th><th>品種</th><th>數(shù)量</th><th>等級(jí)</th><th>類型</th><th>操作</th></tr><c:forEach items="${getList}" var="list"><tr><td>${list.id}</td><td>${list.name}</td><td>${list.count}</td><td>${list.level}</td><td><c:if test="${list.typeId==1}">鳥(niǎo)類 </c:if> <c:if test="${list.typeId==2}">魚(yú)類 </c:if></td><td><a onclick="upDown(${list.id})">降級(jí)</a> <aonclick="updateDown(${list.id})">升級(jí)</a></td></tr></c:forEach></table><div id="end"><span><a href="intoAdd.do">錄入</a></span> <span>共${sizes}條數(shù)據(jù)</span></div></div><script type="text/javascript"> function upDown(id){if(confirm("確認(rèn)要降級(jí)嗎?")){return window.location.href="upDown.do?id="+id;}else {return false;}} function updateDown(id){if(confirm("確認(rèn)要升級(jí)嗎?")){return window.location.href="updateDown.do?id="+id;}else {return false;}} </script></body> </html>總結(jié)
以上是生活随笔為你收集整理的基于Spring MVC + Spring + MyBatis的【野生动物保护系统】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php将微信绑定到账号上,微信通帐户绑定
- 下一篇: [架构之路-146]-《软考-系统分析师