框架开发与应用期末考试

题型

  • 选择题
  • 程序阅读题
  • 程序改错题
  • 程序填空题
  • 编程题

考点

  • pom(热部署)
  • 常用注解
  • loc(自动注入)
  • aop
  • properties(配置文件)
  • mapper
  • 前端(不考虑jsp)

掌握常用坐标dependency的含义,如web,热部署等

<dependencies>
	<dependency>
        <groupId>项目组标识</groupId>
        <artifactId>项目标识</artifactId>
        <version>项目版本号</version>
        <scope>作用域</scope>
    </dependency>
</dependencies>

spring boot

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.M3</version>
</parent>

spring-boot-starter-web

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

热部署

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <version>2.3.12.RELEASE</version>
    <optional>true</optional>
</dependency>

所有讲授过的注解及其含义和用法;

启动器注解

@SpringBootApplication

这个注解是Spring Boot最核心的注解,用在 Spring Boot的主类上,标识这是一个 Spring Boot 应用,用来开启 Spring Boot 的各项能力。实际上这个注解是@Configuration,@EnableAutoConfiguration,@ComponentScan三个注解的组合。由于这些注解一般都是一起使用,所以Spring Boot提供了一个统一的注解@SpringBootApplication@ComponentScan

组件扫描。让spring Boot扫描到Configuration类并把它加入到程序上下文。
@ComponentScan注解默认就会装配标识了@Controller@Service@Repository@Component注解的类到spring容器中。

组件注册注解

@Component :标准一个普通的spring Bean类。 
@Repository:标注一个DAO组件类。 
@Service:标注一个业务逻辑组件类。 
@Controller:标注一个控制器组件类。 

java显式装配注解

@Configuration

用于定义配置类,指出该类是 Bean 配置的信息源,相当于传统的xml配置文件,一般加在主类上。如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件。

@Bean

相当于XML中的,放在方法的上面,而不是类,意思是产生一个bean,并交给spring管理。

例子

@Configuration  //代表这是一个配置类
@Import(MyConfig2.class)  //导入合并其他配置类,类似于配置文件中的 inculde 标签
public class MyConfig {
	/**
     *    通过方法注册一个bean,方法名为 bean.id;返回的实例化对象对应的的全类名为 bean.class
     */
   @Bean //通过方法注册一个bean
   public Dog dog(){
       return new Dog();
  }
}

mvc注解

@RestController

用于标注控制层组件(如struts中的action),表示这是个控制器bean,并且是将函数的返回值直 接填入HTTP响应体中,是REST风格的控制器;它是@Controller@ResponseBody的合集。
    
@RequestMapping

RequestMapping是一个用来处理请求地址映射的注解;提供路由信息,负责URL到Controller中的具体函数的映射,可用于类或方法上。vaule=""等价于path="",可省略。method=RequestMethod.GET设置请求类型
    
@ResponseBody

表示该方法的返回结果直接写入HTTP response body中

@RequestBody

是指方法参数被绑定到HTTP请求Body上,前端就不能用表单的方式提交了,需要用json的方式提交。
@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,而是application/json或application/xml等。一般情况下来说常用其来处理application/json类型。并且@requestbody传送的参数需要是json对象即可;

附:form默认的提交方式content-type是x-www-form-urlencoded,会将传递的参数转换成key-value方式

@RequestParam
    
处理content-type是默认的application/x-www-form-urlcoded编码的内容
用在方法的参数前面
value = "" 前端参数名称
required = false 是否必须
defaultValue = "" 默认值
    
@PathVariable

通过 @PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariable("xxx") 

自动注入注解

@AutoWired

byType方式。把配置好的Bean拿来用,完成属性、方法的组装,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。

当加上(required=false)时,就算找不到bean也不报错。

@Qualifier

当有多个同一类型的Bean时,可以用@Qualifier("name")来指定。与@Autowired配合使用

@Resource(name="name",type="type")

没有括号内内容的话,默认byName。与@Autowired干类似的事。

仅了解的注解

@ConfigurationProperties

Spring Boot可使用注解的方式将自定义的properties文件映射到实体bean中,比如config.properties文件。

@Value("${app.name}")
注入简单值
 
@Import

通过导入的方式实现把实例加入springIOC容器中

@EnableAutoConfiguration

让 Spring Boot 根据应用所声明的依赖来对 Spring 框架进行自动配置,一般加在主类上。

@Profiles
    
Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只能在特定的环境下生效。
任何@Component@Configuration都能被@Profile标记,从而限制加载它的时机。
    
@ModelAttribute

作用于Controller的方法上,在URL被映射到该类时该方法首先被执行
@ModelAttribute注解,springmvc提前执行取数据操作,再进行修改操作,解决修改中为赋值对象为空的问题

理解和应用IOC的原理和注入方式,AOP的原理和应用;

IoC(反转控制):

一种**设计思想**,就是将原本在程序中手动创建对象的控制权,交由Spring框架来管理

DI(依赖注入):

依赖注入,在Spring框架负责创建Bean对象时,动态的将依赖对象注入到Bean组件中。  

属性注入的三种方式

构造器注入

无参构造
 <bean id="user" class="com.kuang.pojo.User"/>
有参构造
<!-- 第一种根据index参数下标设置 -->
<bean id="userT" class="com.kuang.pojo.UserT">
    <!-- index指构造方法 , 下标从0开始 -->
    <constructor-arg index="0" value="kuangshen2"/>
</bean>
<!-- 第二种根据参数名字设置 -->
<bean id="userT" class="com.kuang.pojo.UserT">
    <!-- name指参数名 -->
    <constructor-arg name="name" value="kuangshen2"/>
</bean>
<!-- 第三种根据参数类型设置 -->
<bean id="userT" class="com.kuang.pojo.UserT">
    <constructor-arg type="java.lang.String" value="kuangshen2"/>
</bean>
value:指定基本数据类型或String类型的数据

ref:指定其它bean类型的数据 

Setter方法注入

配置

  • pojo
 public class Address {
 
     private String address;
 
     public String getAddress() {
         return address;
    }
 
     public void setAddress(String address) {
         this.address = address;
    }
 }
public class Student {
 
     private String name;
     private Address address;
     private String[] books;
     private List<String> hobbys;
     private Map<String,String> card;
     private Set<String> games;
     private String wife;
     private Properties info;
 
     public void setName(String name) {
         this.name = name;
    }
 
     public void setAddress(Address address) {
         this.address = address;
    }
 
     public void setBooks(String[] books) {
         this.books = books;
    }
 
     public void setHobbys(List<String> hobbys) {
         this.hobbys = hobbys;
    }
 
     public void setCard(Map<String, String> card) {
         this.card = card;
    }
 
     public void setGames(Set<String> games) {
         this.games = games;
    }
 
     public void setWife(String wife) {
         this.wife = wife;
    }
 
     public void setInfo(Properties info) {
         this.info = info;
    }
 
     public void show(){
         System.out.println("name="+ name
                 + ",address="+ address.getAddress()
                 + ",books="
        );
         for (String book:books){
             System.out.print("<<"+book+">>\t");
        }
         System.out.println("\n爱好:"+hobbys);
 
         System.out.println("card:"+card);
 
         System.out.println("games:"+games);
 
         System.out.println("wife:"+wife);
 
         System.out.println("info:"+info);
 
    }
 }
注入常量
 <bean id="student" class="com.kuang.pojo.Student">
     <property name="name" value="小明"/>
 </bean>
注入Bean(基础)
 <font color='red'> 这里的值是一个引用,ref </font>
 <bean id="addr" class="com.kuang.pojo.Address">
     <property name="address" value="重庆"/>
 </bean>
 
 <bean id="student" class="com.kuang.pojo.Student">
     <property name="name" value="小明"/>
     <property name="address" ref="addr"/>
 </bean>
注入数组
 <bean id="student" class="com.kuang.pojo.Student">
     <property name="name" value="小明"/>
     <property name="address" ref="addr"/>
     <property name="books">
         <array>
             <value>西游记</value>
             <value>红楼梦</value>
             <value>水浒传</value>
         </array>
     </property>
 </bean>
注入List
<property name="hobbys">
     <list>
         <value>听歌</value>
         <value>看电影</value>
         <value>爬山</value>
     </list>
 </property>
注入Map
<property name="card">
     <map>
         <entry key="中国邮政" value="456456456465456"/>
         <entry key="建设" value="1456682255511"/>
     </map>
 </property>
注入Set
 <property name="games">
     <set>
         <value>LOL</value>
         <value>BOB</value>
         <value>COC</value>
     </set>
 </property>
注入Null
<property name="wife"><null/></property>
注入Properties
 <property name="info">
     <props>
         <prop key="学号">20190604</prop>
         <prop key="性别"></prop>
         <prop key="姓名">小明</prop>
     </props>
 </property>

P命名和C命名注入

P命名空间(类Set注入,必须有Set方法)

<bean id="john-modern" class="com.example.Person" p:name="John Doe" p:spouse-ref="jane"/>
<!--等价于-->
<bean id="john-classic" class="com.example.Person">
    <property name="name" value="John Doe"/>
    <property name="spouse" ref="jane"/>
</bean>

C命名空间(类构造器注入,必须有有参构造)

<bean id="beanOne" class="x.y.ThingOne" 
        c:thingTwo-ref="beanTwo"  
        c:thingThree-ref="beanThree" 
        c:email="something@somewhere.com"/>
<!--推荐-->
<!--等价于-->
<bean id="beanOne" class="x.y.ThingOne">
        <constructor-arg name="thingTwo" ref="beanTwo"/>
        <constructor-arg name="thingThree" ref="beanThree"/>
        <constructor-arg name="email" value="something@somewhere.com"/>
</bean>
<bean id="beanOne" class="x.y.ThingOne" 
    c:_0-ref="beanTwo" 
    c:_1-ref="beanThree"
    c:_2="something@somewhere.com"/>
    <!--等价于-->
<bean id="beanOne" class="x.y.TingOne">
    <constructor-arg index="0" ref="beanTwo"/>
    <constructor-arg index="1" ref="beanThree"/>
    <constructor-arg index="2" value="something@somewhere.com"/>
</bean>

注解注入

@Component("user")
// 相当于配置文件中 <bean id="user" class="当前注解的类"/>
public class User {
    @Value("秦疆")
    // 相当于配置文件中 <property name="name" value="秦疆"/>
    public String name;
}
@Component("user")
public class User {
 
    public String name;
 
    @Value("秦疆")
    public void setName(String name) {
        this.name = name;
    }
}

AOP

**面向切面的编程**:把程序重复的代码抽取出来,在需要执行的时候,使用动态代理技术在不修改源代码的基础上对已有方法进行增强。

**AOP作用**:在程序运行期间,不修改源码对已有方法进行增强。

**AOP优势**:减少重复代码,提高开发效率,维护方便。

**通知**:安全,事务,日志等。分为前置通知(Before)、后置通知(AfterReturning)、异常通知(AfterThrowing)、最终通知(After)和环绕通知(Around)五种。
  • 前置通知(before advice):在连接点前面执行,对连接点不会造成影响(前置通知有异常的话,会对后续操作有影响)

  • 正常返回通知(after returning advice):在连接点正确执行之后执行,如果连接点抛异常,则不执行

  • 异常返回通知(after throw Advice):在连接点抛异常的时候执行

  • 返回通知(after):无论连接点是正确执行还是抛异常,都会执行

  • 环绕通知(around):在连接点前后执行(必须在环绕通知中决定是继续处理还是中断执行,使用PreceedingJoinPonit下的方法决定是继续还是中断)

    连接点(JoinPoint)是Spring允许你使用通知的地方,基本每个方法的前,后(两者都有也行),或抛出异常时都可以是连接点,Spring只支持方法连接点

    切入点(Pointcut)上面说的连接点的基础上,来定义切入点

    切面(Aspect)切面是通知和切入点的结合。

    目标(target)表示目标对象(被代理对象)。被一个或者多个切面所通知的对象。

    代理(proxy)表示代理对象。将通知应用到目标对象之后被动态创建的对象。可以简单地理解为,代理对象为目标对象的业务逻辑功能加上被切入的切面所形成的对象。

    weaving 表示切入,也称为织入。将切面应用到目标对象从而创建一个新的代理对象的过程

通知类

package nuc.edu.cn.advice;

public class CustomerAspect {
      public void before() {
           System.out.println("CustomerAspect before.");
      }
}

接口和实现类

package nuc.edu.cn.service.impl;
public class CustomerServiceImpl implements ICustomerService {
    @Override
    public void saveCustomer() {
          System.out.println("保存客户信息");
    }
}

spring.xml配置aop

		<!-- 配置service -->
    <bean id="customerService" class="nuc.edu.cn.service.impl.CustomerServiceImpl"></bean>
         <!-- 基于xml的aop配置步骤,必须导入aop的jar包 -->

         <!-- 第一步:把通知类交给spring来管理 -->
    <bean id="customerAspect" class="nuc.edu.cn.advice.CustomerAspect"></bean>
 
         <!-- 第二步:导入aop名称空间 ,并且使用aop:config开始aop配置 -->
    <aop:config>
         <!-- 第三步:使用aop:aspect配置切面 ,id属性用于给切面提供一个唯一标识,ref用于引用通知bean的id -->
    	<aop:aspect id="customerAdvice" ref="customerAspect">
         <!-- 第四步: 配置通知的类型,指定增强的方法何时执行。method:用于指定增强的方法名称 -->
		<!-- 切入点表达式:关键字:execution(表达式). 表达式写法: 访问修饰符 返回值 包名.包名...类名.方法名(参数列表)pointcut="execution(* *..*.*(..))" -->
    		<aop:before method="before" pointcut="execution(public void nuc.edu.cn.service.impl.CustomerServiceImpl.saveCustomer())" />
         </aop:aspect>
	</aop:config>

掌握MVC应用方法,能够使用自动注入实现类托管;

mvc

视图解析

视图解析器设置
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
ModelAndView
public ModelAndView detailsForJson() {
	// 模型和视图
	ModelAndView mv = new ModelAndView();
	// 生成JSON视图
	MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
	mv.setView(jsonView);
	// 加入模型
	mv.addObject("user", user);
	return mv;
}
public ModelAndView details(Integer id) {
    // 模型和视图
    ModelAndView mv = new ModelAndView();
    // 定义模型视图
    mv.setViewName("user/details");
    // 加入数据模型
    mv.addObject("user", user);
	return mv;
}
public ModelAndView useModelAndView(Integer id, ModelAndView mv) {
    // 设置数据模型
    mv.addObject("user", user);
    // 设置视图名称
    mv.setViewName("user/details");
    return mv;
}
public ModelAndView useModelMap(Integer id, ModelMap modelMap) {
    ModelAndView mv = new ModelAndView();
    // 设置视图名称
    mv.setViewName("user/details");
    // 设置数据模型,此处modelMap并没有和mv绑定,这步系统会自动处理
    modelMap.put("user", user);
    return mv; 
}

使用参数传入ModelAndView或者实例化ModelAndView

设置视图

mv.setViewName("user/details")

MappingJackson2JsonView()实例化,使用 mv.setView(jsonView)

设置数据

mv.addObject("user", user)

参数传入ModelMap,使用 modelMap.put("user", user)
Model
//传入数据模型参数
@GetMapping("/PModel")
public String useModel(Integer id, Model model) {
    User user = userService.getUserById(id);
    model.addAttribute("user", user);
    // 这里返回字符串,在Spring MVC中,会自动创建ModelAndView且绑定名称
    return "details";
}

设置视图

返回字符串设置

设置数据

参数传入Model,model.addAttribute("user", user)
文件上传
文件上传设置
#指定默认上传的文件夹
spring.servlet.multipart.location=d:/temp1/
#限制单个文件最大大小
spring.servlet.multipart.max-file-size=5242880
#限制所有文件最大大小,这里设置为 20MB
spring.servlet.multipart.max-request-size=20MB
处理单文件上传请求

后端

public String handleFormUpload(MultipartFile file){
    String path = "d:/uploaded/";//保存路径
    // String filename=photo.getOriginalFilename();
    String filename = new
    SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());

     //获取上传文件的后缀suffix
    String suffix = photo.getOriginalFilename().substring(photo.getOriginalFilename().lastIndexOf("."));
    if (!suffix.equals(".jpg")) {
        return dealResultMap(false, "上传失败");
    }
    try {
         //Spring提供了文件操作类FileCopyUtils
        FileCopyUtils.copy(photo.getInputStream(), new FileOutputStream(path + filename + suffix));
    } catch (IOException e) {
    // TODO Auto-generated catch block
    	e.printStackTrace();
    	return dealResultMap(false, "上传失败");
    }
    return dealResultMap(true, "上传成功");
}

前端

<form method="post" action="./multipart" enctype="multipart/form-data">
     <input type="file" name="photo" value="请选择上传的文件" />
     <input type="submit" value="提交" />
</form>
处理多文件上传请求
public String handleFormUpload(MultipartFile[] files){}
拦截器

实现拦截内容

public class Interceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		//System.out.println("处理前");
       return true;// 继续执行
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		//System.out.println("处理后");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		//System.out.println("处理完成");
    }
}

注册拦截规则

@Configuration
public class WebConfig implements WebMvcConfigurer { 
 	@Override 
 	public void addInterceptors(InterceptorRegistry registry) { 
  		// TODO Auto-generated method stub 
  		registry.addInterceptor(new Interceptor())
    		.addPathPatterns("/**") //拦截所有
        	.excludePathPatterns("/login");//放过登录
 	}
}

xml自动注入

可以为bean节点添加增加属性 autowire="byName" 或 autowire="byType" ,会自动查找spring容器中的对应的bean注入,而省去了手动注入的麻烦。

注解自动注入

使用注解

@Autowired

  • 默认是根据类型自动装配。多匹配,按照byName方式进行装配。
  • @Qualifier则可以修改byName的值

@Resource

  • 如果同时指定了name和type,则从Spring上下文中找到唯一匹配的bean进行装配,找不到则抛出异常
  • 如果指定了name,则从Spring上下文中查找名称(id)匹配的bean进行装配,找不到则抛出异常
  • 如果指定了type,则从Spring上下文中找到类型匹配的唯一bean进行装配,找不到或找到多个,都抛出异常
  • 如果既没指定name,也没指定type,则自动按照byName方式进行装配。如果没有匹配,则回退为一个原始类型进行匹配,如果匹配则自动装配。

掌握mybatis的常用配置项,能够使用全局和映射文件方式,以及注解方式使用mybatis;

普通

数据库配置

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/book_manage?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root

全局和映射文件配置

mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

mybatis-config.xml配置

<settings>
    	<!-- 开启驼峰表示法 -->
    <setting name="mapUnderscoreToCamelCase" value="true" />  
</settings>
<typeAliases>
        <!-- 批量导入基本类别名 -->
    <package name="com.nuc.pojo"/>
</typeAliases>

*.xml

	<select id="getBookList" resultMap="book">
        select *
        from book_manage.book
        where name like '%${value}%'
    </select>
	<!--模糊条件需要使用${  }:表示拼接sql串,将接收到的参数内容不加任何修饰拼接到sql中-->
	<!--#{}表示一个占位符号,无MyBatis 默认值,可任意,且与参数名无关
 		${}表示一个拼接符号,使用 MyBatis 默认值 value,即 ${value}。
		使用自定义参数名,前提:在映射器接口方法的参数前加注解@Param("")-->

	<!--keyProperty="hx_1913041319_id" useGeneratedKeys="true" 用于自动递增字段的值回显-->
    <insert id="addBook" parameterType="Hx_1913041319_Book" keyProperty="hx_1913041319_id" useGeneratedKeys="true"> 
        insert into book_manage.book (id, name, price, cover)
        VALUES (#{hx_1913041319_id}, #{hx_1913041319_name}, #{hx_1913041319_price}, #{hx_1913041319_cover})
    </insert>

    <update id="updateBook">
        update book_manage.book cover = #{hx_1913041319_cover}
        where id = #{hx_1913041319_id}
    </update>

    <delete id="deleteBookById">
        delete from book_manage.book where id = #{hx_1913041319_id}
    </delete>

	<!--数据库映射-->
	<resultMap id="book" type="Hx_1913041319_Book">
        <id column="id" property="hx_1913041319_id"></id>
        <result column="name" property="hx_1913041319_name"></result>
        <result column="price" property="hx_1913041319_price"></result>
        <result column="cover" property="hx_1913041319_cover"></result>
    </resultMap>

注解实现

public interface UserMapper {
     //方法具有多个参数,前必须加@param
     @Select("select * from user")
     @Results(id="user",value={
         @Result(id=true,column="id",property="id"),
         @Result(column="name",property="username"),
         @Result(column="pwd",property="password"),
     })
     User getUserById(@Param("id") int id);

     @Insert("insert into user(id,username,password)values(#{id},#{name},#{pwd})")
     @ResultMap("user")
     //引用results
     @options(useGeneratedKeys=true,keyProperty="id" ,keyColumn="id")
     //主键自增
     int addUser(User user);

     @Update("update user set name = #{name},pwd = #{password} where id = #{id}")
     int updateUser(User user);

     @Delete("delete from user where id = #{tid}")
     int deleteUser(@Param("tid") int id);
}

进阶

一对一

按照查询嵌套处理
<!--
     思路:
        1. 查询所有的学生信息
        2. 根据查询出来的学生的tid寻找特定的老师 (子查询)
    -->
<select id="getStudent" resultMap="StudentTeacher">
    select * from student
</select>

<resultMap id="StudentTeacher" type="student">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <!--对象:association 集合:collection-->
    <association property="teacher" column="tid" javaType="teacher" select="getTeacher"/>
</resultMap>

<select id="getTeacher" resultType="teacher">
    select * from teacher where id = #{id}
</select>

20200909144043629

  • javaType:把sql语句查询出的结果集,封装给某个类的某个对象-- 属性类型(指定实体类中的java返回值类型)

  • select:下一条要执行的sql语句

  • property:注入给一级查询结果实体类的某个属性-- 属性名

  • column:在上一次查询的结果集中,用那些列值去执行下一条sql语句(传参)

按照结果嵌套处理 (简单)
 <!--按照结果进行查询-->
    <select id="getStudent2" resultMap="StudentTeacher2">
        select s.id sid , s.name sname, t.name tname
        from student s,teacher t
        where s.tid=t.id
    </select>
    <!--结果封装,将查询出来的列封装到对象属性中-->
    <resultMap id="StudentTeacher2" type="student">
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
        <association property="teacher" javaType="teacher">
            <result property="name" column="tname"></result>
        </association>
    </resultMap>

20200909144059395

一对多

按照查询嵌套处理
<!--子查询:按查询嵌套查询-->
<select id="getTeacher" resultMap="teacherToStudent">
    select id, name from mybatis.teacher where id = #{id}
</select>
<resultMap id="teacherToStudent" type="teacher">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <!--  column="id"是teacher表中的id-->
    <collection property="students" javaType="List" ofType="student"
                column="id" select="getStudentsByTeacherId" />
    <!-- List<student> students -->
</resultMap>
<select id="getStudentsByTeacherId" resultType="student">
    select * from mybatis.student where tid = #{id}
</select>

20200909144117110

  • ofType:映射List或某些指定的pojo泛型的类型
按照结果嵌套处理
<!--联表查询:按结果嵌套查询-->
<select id="getTeacher1" resultMap="teacherAndStudent">
    select  s.id sid,s.name sname,t.name tname,t.id tid
    from mybatis.teacher t,mybatis.student s
    where s.tid=t.id and t.id =#{id}
</select>
<resultMap id="teacherAndStudent" type="teacher">
    <result property="id" column="tid"/>
    <result property="name" column="tname"/>
    <!--集合对象用collection绑定,javaType是返回单个属性,不能返回集合,
返回属性是集合用ofType绑定-->
    <collection property="students" ofType="student">
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
        <result property="tid" column="tid"/>
    </collection>
</resultMap>

掌握前端基本控件及表单的使用方法,能够做到前后端交互;

基本标签

结构标签

<!--定义 HTML 文档 -->
<html>
<!--定义文档的头部 -->
 	<head>
<!--定义文档的标题 -->        
 		<title></title>      
 	</head>
<!--定义文档的主体 -->   
 	<body></body>
 </html>

容器标签

<!--块级标签,独占一行-->
	<div></div>
<!--行级标签,所有内容都在同一行-->
 	<span></span>:

文字标签

<font></font> 
    属性: size:设置字体大小
          color:设置字体颜色
          face:设置字体  
    <i>:显示斜体文本效果
	<b>:呈现粗体文本效果
    <small>:呈现小号字体效果      
	<big>:呈现大号字体效果

标题标签

<h1>这是标题 1</h1>
<h2>这是标题 2</h2>
<h3>这是标题 3</h3>
<h4>这是标题 4</h4>
<h5>这是标题 5</h5>
<h6>这是标题 6</h6>

无序列表

<ul type="square">无序列表
     <li>apple</li>
     <li>banana</li>
     <li>orange</li>
</ul>
    属性:type :circle(空心圆) ,disc(默认,实心圆),square(黑色方块)
	注意:如果想去掉列表默认属性(去掉小圆点),可在css中设置list-style: none;

有序列表

<ol type="A">有序列表
     <li>apple</li>
     <li>orange</li>
     <li>banana</li>
</ol>
	属性:type:1、A、a、I、i(数字、字母、罗马数字)

图片标签

<img/>单标签   
  属性: 
      src:图片地址
      width:宽度
      height:高度
      border:边框
      align:对齐方式
      alt:图片的文字说明(鼠标放在图片上显示文字)
      hspace 和 vspace 设定图片边沿上下左右空白,以免文字或其它图片过于贴近

链接标签

<a>文本或图片</a>
属性: 
    href:跳转页面的地址(支持外网跳转:协议+域名);            
    name:名称,锚点(回到锚点: 顶部,底部,中间)

表格标签

<table border="1" width="200" height="200" align="center" cellspacing="0" >
	<caption>个人信息表</caption>
	<tr >
		<th>姓名</th>
		<th>年龄</th>
		<th>性别</th>
	</tr>
	<tr align="center">
		<td>张三</td>
		<td>18</td>
		<td></td>
	</tr>
</table>

表单标签

form标签

属性:action:表示动作,值为服务器的地址,把表单的数据提交到该地址上处理
     method:请求方式:get 和post
     enctype:表单提交的类型

get提交与post提交

get:
       1.会显示在地址栏,请求参数都在地址后拼接 path?name="李华"&password="123456";
       2.不安全但是效率较高;
       3.get请求大小有限制,大约是2KB;
       使用情况:一般情况用于查询数据。
 post:
       1.地址栏:请求参数单独处理;
       2.安全可靠但是效率低;
       3.post请求大小理论上无限;
       使用情况:一般用于插入修改等操作。

input标签

原型:<input type="" name="" id="" value="" />
type: 
      text 文本框  
      password  密码框   
      radio 表示是单选,实现单选框:name属性必须一致才能实现单选框
      <div>
      	<input type="radio" name="chex"  />
		<input type="radio" name="chex"  />
	  </div>
      checkbox  表示多选 ,同一组中可以选多个,name必须一致,返回值是个数组
      submit   提交
      reset   重置
      button 普通按钮

select下拉菜单

<select>
		<option value ="">请选择年份</option>
		<option value ="">1998</option>
		<option value ="">1999</option>
</select>
<select>
		<option value ="">请选择月份</option>
		<option value ="">08</option>
		<option value ="">01</option>
</select>
<select>
		<option value ="">请选择日</option>
		<option value ="">30</option>
		<option value ="">07</option>
</select>

textarea元素

需要指定输入的区域位置大小

<textarea rows="10" cols="20" >  表示10行20列的文本空间大小

祝考试顺利

posted @   Faetbwac  阅读(1751)  评论(1编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示