Wildlife protection system based on Spring MVC + Spring + MyBatis

Resource download: https://download.csdn.net/download/weixin_44893902/45603787

Exercise point design: fuzzy query, delete, add, modify

1, Language and environment

  1. Implementation language: JAVA language.
  2. Environment requirements: MyEclipse/Eclipse + Tomcat + MySql.
  3. Use technology: Jsp+Servlet+JavaBean or spring MVC + Spring + mybatis.

2, Realize function

With the development of society, people and animals need to coexist harmoniously. Now it is necessary to make a wildlife protection system. Its main functions are as follows:
1. The home page displays a list of all animals by default, as shown in Figure 1.

2. When the mouse hovers over a row of data, the light bar effect is displayed in linear transition animation, as shown in Figure 2.

3. When the user enters the animal name, the fuzzy query is completed and the query results are displayed, as shown in Figure 3.

4. When the user clicks upgrade or downgrade, a prompt box will pop up. After the user clicks OK, modify the selected data and display the latest data, as shown in Figure 4 and figure 5.


5. The user clicks the "add" link to open the new page. After filling in the relevant information, click the Add button to add wildlife information data to the database, and the page jumps to the list page to display the latest data, as shown in Figure 6 and Figure 7.

3, Database design

1. Create a database (animal_db).
2. Create a data table (tb_type) with the following structure.

Field nameexplainField typelengthremarks
type_idType numberintPrimary key, self increment, increment is 1
type_nameType namevarchar50Cannot be empty

3. Create a tb_animal with the following structure.

Field nameexplainField typelengthremarks
idnumberintPrimary key, self increment, increment is 1
nameAnimal speciesvarchar50Cannot be empty
countNumber of animalsintCannot be empty
levelProtection levelintCannot be empty
type_idType numberintForeign key

4, Recommended implementation steps

1. The implementation steps of SSM version are as follows:

(1) Create database and data table and add test data (add at least 3 test data).
(2) Create a Web project, create various packages, and import the jar files required by the project.
(3) Add relevant SSM framework support.
(4) Various configuration files required by the configuration project (mybatis configuration file, spring configuration file, spring MVC configuration file).
(5) Create an entity class.
(6) Mapper interface required to create MyBatis operation database and its Xml mapping database operation statement file.
(7) Create corresponding interfaces and implementation classes of business logic, implement corresponding businesses, and add references and injections to DAO/Mapper in the classes.
(8) Create the Controller class, add reference and injection to the business logic class in the Controller, and configure the spring MVC configuration file.
(9) Create relevant operation pages and beautify the pages with CSS.
(10) Realize various operation functions of the page and verify them in relevant places. The operation should be humanized.
(11) After debugging and running successfully, export relevant database files and submit them.

5, Implementation code

1. MySQL database

animal_db.sql

2. Project Java code

directory structure

animal_db

JAR package:

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 {
	@Resource
	private AnimmailServices animmailServices;
	//query
	@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";
	}
	//Input
	@RequestMapping("/insert")
	public String getInsert(Model model,TbAnimal animal) {
		int count=animmailServices.inser(animal);
		return "redirect:/getList.do";
	}
	//Enter the new page
	@RequestMapping("/intoAdd")
	public String into() {
		return "addAnimal";
	}
	//Demotion
	@RequestMapping("/upDown")
	public String upDown(Model model,TbAnimal animal) {
		int upDown=animmailServices.down(animal);
		return "redirect:/getList.do";
	}
	//upgrade
		@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);
    //Fuzzy query
    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_animal
    where 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>
  <!--Demotion  -->
  <update id="updatedown" parameterType="com.entity.TbAnimal" >
    update tb_animal
    set 
     level = level-1
    where id = #{id,jdbcType=INTEGER}
  </update>
   <!--upgrade  -->
  <update id="updateUpdown" parameterType="com.entity.TbAnimal" >
    update tb_animal
    set 
     level = level+1
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select id, name, count, level, type_id
    from tb_animal
    where id = #{id,jdbcType=INTEGER}
  </select>
  <!--query  -->
  <select id="selectAll" resultMap="BaseResultMap" >
    select id, name, count, level, type_id
    from tb_animal
  </select>
  <!--Fuzzy query  -->
  <select id="selectLikeAll" resultMap="BaseResultMap" >
    select id, name, count, level, type_id
    from tb_animal
    where 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_type
    where 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_type
    set 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_name
    from tb_type
    where type_id = #{typeId,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap" >
    select type_id, type_name
    from 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", Do not generate Example
	 */
	public void generateMyBatis() {
		//Warning messages during MBG execution
		List<String> warnings = new ArrayList<String>();
		//When the generated code is repeated, the original code is overwritten
		boolean overwrite = true ;
		//String generatorFile = "/generator/generatorConfig.xml";
		String generatorFile = "/generatorConfig.xml";
		//Read MBG configuration file
		InputStream is = Generator.class.getResourceAsStream(generatorFile);
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config;
		try {
			config = cp.parseConfiguration(is);
			DefaultShellCallback callback = new DefaultShellCallback(overwrite);
			//Create MBG
			MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
			//Execute generated code
			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 {
	@Resource
	private TbAnimalMapper tbanimail;
	//query
	@Override
	public 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 ;
		}
	}
	//Input
	@Override
	public int inser(TbAnimal animal) {
		int count=tbanimail.insert(animal);
		return count;
	}
	
	@Override
	public int down(TbAnimal animal) {
		int upDown=tbanimail.updatedown(animal);
		return upDown;
	}
	//upgrade
	@Override
	public 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 {
	//query
	 List<TbAnimal> getAnimals(String   name);
    //Input
	 int inser(TbAnimal animal);
	//Demotion
	 int down(TbAnimal animal);
	//upgrade
	 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>
	<!-- alias -->
	<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/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
	
	<!-- appoint spring Container read db.properties file -->
	<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
	<!-- Register connection pool with bean In container -->
	<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>
	<!-- to configure SqlSessionFactory -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- set up MyBatis Core profile -->
		<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
		<!-- set up data sources -->
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- to configure Mapper scanning -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- set up Mapper Scan package -->
		<property name="basePackage"  value="com.dao" />
	</bean>
	<!-- Configure transaction manager -->
		<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
			<property name="dataSource" ref="dataSource"></property>
		</bean>
		<!-- Enable annotation mode management AOP affair -->
		<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 ">
		<!-- to configure Service scanning -->
		<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 ">
		
		<!-- to configure Controller scanning -->
		<context:component-scan base-package="com.controller" />
		<!-- Configure annotation driven -->
		<mvc:annotation-driven />
		<!-- Configure view parser -->
		<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<!-- prefix -->
			<property name="prefix" value="/WEB-INF/jsp/" />
			<!-- suffix -->
			<property name="suffix" value=".jsp" />
		</bean>
</beans>

generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- Configuration Generator  -->
<generatorConfiguration>
	<context id="MySQLContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
		<!-- Configure leading and trailing delimiters -->
		<property name="beginningDelimiter" value="`"/>
		<property name="endingDelimiter" value="`"/>
		<!-- Configure comment information -->
		<commentGenerator>
			<!-- Do not generate comments -->
			<property name="suppressAllComments" value="true"/>
			<property name="suppressDate" value="true"/>
			<property name="addRemarkComments" value="true"/>
		</commentGenerator>
		<!-- Database connection configuration -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver" 
				connectionURL="jdbc:mysql://localhost:3306/animal_db"
				userId="root" password="root">
		</jdbcConnection>
		
		<!-- targetPackage: Generate the package name stored in the entity class, targetProject: Specify the target project path, either relative or absolute -->
		<javaModelGenerator targetPackage="com.entity" targetProject="src">
			<property name="trimStrings" value="true"/>
		</javaModelGenerator>
		
		<!-- to configure SQL Mapper Mapper.xml File properties -->
		<sqlMapGenerator targetPackage="com.dao" targetProject="src"/>
		
		<!-- type="XMLMAPPER": All the methods are in use XML Interface call dependency XML file -->
		<javaClientGenerator targetPackage="com.dao" type="XMLMAPPER" 
								targetProject="src"/>
								
		<!-- Generate mappings for all tables -->
		<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.Driver

log4j.properties

# Global configuration
log4j.rootLogger=ERROR, stdout
# MyBatis log configuration
log4j.logger.com.lxh.mapper=TRACE
# Console output configuration
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

WebContent

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 container  -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:spring/applicationContext-*.xml</param-value>
  </context-param>
  <!-- Listener, loading spring to configure -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- Front end controller -->
	<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>
	<!-- set up post Requested character encoding filter -->
  <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>Enter new students</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>&nbsp;&nbsp;&nbsp;
					<h1 style="text-align:;">New page</h1>
				</td>
			</tr>
			<tr>
				<td>varieties:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="name"
					value="${list.name}">
				</td>
			</tr>

			<tr>
				<td>quantity:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="count"
					value="${list.count}">
				</td>
			</tr>
			<tr>
				<td>Grade:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="level"
					value="${list.level}">
				</td>
			</tr>
			<tr>
				<td>category:&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio"
					name="typeId" value="1" <c:if test="${list.typeId==1}"></c:if>>fish
					<input type="radio" name="typeId" value="2"
					<c:if test="${list.typeId==2}"></c:if>>birds
				</td>
			</tr>
			<tr>
				<td><input style="width: 100px;" type="submit" value="determine" />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input style="width: 100px;" type="reset" value="cancel"
					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">
				varieties: <input type="text" name="name" /> <input type="submit"
					value="search" />
			</form>
		</fieldset>
		<table>
			<tr>
				<th>number</th>
				<th>varieties</th>
				<th>quantity</th>
				<th>Grade</th>
				<th>type</th>
				<th>operation</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}">
					     birds  
					</c:if> <c:if test="${list.typeId==2}">
					     fish  
					</c:if></td>
					<td><a onclick="upDown(${list.id})">Demotion</a> <a
						onclick="updateDown(${list.id})">upgrade</a></td>
				</tr>
			</c:forEach>
		</table>
		<div id="end">
			<span><a href="intoAdd.do">Input</a></span> <span>common ${sizes}Data bar</span>
		</div>
	</div>
	<script type="text/javascript">
function upDown(id){
    if(confirm("Are you sure you want to downgrade?")){
        return window.location.href="upDown.do?id="+id;
    }else {
        return false;
    }
 } 
function updateDown(id){
    if(confirm("Are you sure you want to upgrade?")){
        return window.location.href="updateDown.do?id="+id;
    }else {
        return false;
    }
 } 
 
</script>

</body>
</html>

Tags: Java MySQL Mybatis Spring mvc

Posted on Sun, 05 Dec 2021 17:52:36 -0500 by bigdaddysheikh