web常用属性和springboot热部署/视图配置

1、简单的web常用属性

<input type="text">
	required="required" 			必填

 	readonly="readonly" 			只读
<div> style="display: none;"		隐藏
  
<input type="radio">
	checked="checked" 				按钮-选择
  
<select name="城市"> 
<option value ="HB">湖北 
 	selected="selected"				拉框-默认

2、简单记录spring-boot技术点

2.1 、sping-boot 热部署 ,在pom.xml中添加 devtools 依赖

sping-boot 热部署  springloaded jar包应添加到plugin标签中 "<build>
<dependencies>
       <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
      </dependency>
</dependencies>

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<!-- 设置源文件编译 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<compilerVersion>1.8</compilerVersion>
					<encoding>UTF-8</encoding>
					<skipMain></skipMain>
				</configuration>
			</plugin>

			<!-- 解决资源文件的编码问题 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.0.2</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			
		</plugins>
	</build>

	<!--  设定Maven主仓库为阿里私服 -->
	<repositories>
		<repository>
			<id>repos</id>
			<name>Repository</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public</url>
		</repository>
	</repositories>

	<!--  设定插件仓库 -->
	<pluginRepositories>
		<pluginRepository>
			<id>pluginsRepos</id>
			<name>PluginsRepository</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public</url>
		</pluginRepository>
	</pluginRepositories>

热部署后开启项目 cmd 在eclipse中Run As只能发布项目,不能实现热部署 在项目pom.xml所在文件夹中打开cmd,键入命令 mvn spring-boot:run

application.yml配置文件增加

  #热部署生效
  devtools:
    restart:
      enabled: true
      #设置重启的目录
      additional-paths: src/main/java

2.2、spring-boot双视图配置 jsp+thymeleaf(建议) thymeleaf只解析HTML视图
添加maven依赖: jar包 "jsp = jstl.jar ; "thymeleaf = thymeleaf.jar ;

  <dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
  </dependency>" 
  <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-thymeleaf</artifactId>
     </dependency>" 

关键类: ViewResolverConfiguration

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ITemplateResolver;

/**
 * 主要配置多视图实现的视图解析器相关bean实例,将该视图解析器注册到容器中
 *
 *
 * 其实关键点在于两个:
 * 1、配置order属性
 * 2、配置viewnames属性
 *
 */
@Configuration
public class ViewResolverConfiguration {

 @Configuration//用来定义 DispatcherServlet 应用上下文中的 bean
 @EnableWebMvc
 @ComponentScan(""com.sd"")
 public class WebConfig extends WebMvcConfigurerAdapter {

  //jsp页面的视图解析器,解析到webapp下的jsp/目录下查找对应的jsp页面
  @Bean
  public ViewResolver viewResolver() {
   InternalResourceViewResolver resolver = new InternalResourceViewResolver();
   resolver.setPrefix(""/WEB-INF/"");
   resolver.setSuffix("".jsp"");
   resolver.setViewNames(""*"");
   resolver.setOrder(2);
   return resolver;
  }

  @Bean
  public ITemplateResolver templateResolver() {
   SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
   templateResolver.setTemplateMode(""HTML5"");
   templateResolver.setPrefix(""/"");
   templateResolver.setSuffix("".html"");
   templateResolver.setCharacterEncoding(""utf-8"");
   templateResolver.setCacheable(false);
   return templateResolver;
  }

  @Bean
  public SpringTemplateEngine templateEngine() {
   SpringTemplateEngine templateEngine = new SpringTemplateEngine();
   templateEngine.setTemplateResolver(templateResolver());
   // templateEngine
   return templateEngine;
  }

  /**
   * 对thymeleaf的视图解析器,解析到webapp下的html目录下查找对应的页面
   * @return
   */
  @Bean
  public ThymeleafViewResolver viewResolverThymeLeaf() {
   ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
   viewResolver.setTemplateEngine(templateEngine());
   viewResolver.setCharacterEncoding(""utf-8"");
   viewResolver.setOrder(1);
   viewResolver.setViewNames(new String[]{""html/*"", ""vue/*"",""jsps/*"",""templates/*""});
   return viewResolver;
  }

  @Override
  public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
   configurer.enable();
  }

  /**
   * 配置资源路径
   * @param registry
   */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
   registry.addResourceHandler(""/img/**"").addResourceLocations(""/img/"");
   registry.addResourceHandler(""/static/**"").addResourceLocations(""/static/"");
  }
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值