方法没问题,但获取到的值传不过去
@Component
public class JobCLR implements CommandLineRunner {
protected final Logger logger = LoggerFactory.getLogger(JobCLR.class);
@Autowired
private JobService js;
@Override
public void run(String... args) throws Exception {
System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作<<<<<<<<<<<<<");
/* List<String> jobsListindex=js.queryHotJob(1);*/
List<Jobs> jobsList= js.selectByHeat1();
ModelAndView mav =new ModelAndView("/");
mav.addObject("jobsList",jobsList);
for(Jobs l :jobsList) {
System.out.println(l);
}
}
}
页面
<a class="zxzw_fen clearfix"
th:classappend="${ jobsListindex.index } % 2 == 0 ? '' : 'mr_0'"
href="" th:each="jobsList,jobsListindex:${jobsList}">
<div class="zxzw_fen_01 clearfix">
<b th:utext="|<i>|+${jobsList.jobPosition}+|</i> [|+${jobsList.jobAddress}+|] ${jobsList.jobReleaseTime}|"></b>
<span th:text="${jobsList.jobSalary}">24-36万</span>
</div>
<div class="zxzw_fen_02 clearfix">
<span th:text="${jobsList.jobEmployAddress}"></span>
<i th:text="${jobsList.jobWelfare}">绩效奖金</i> <i>带薪年假</i>
</div>
</a>
以配置文件为application.properties视图为jsp举例
** 在application.properties配置springmvc**
#springmvc
spring.mvc.view.prefix = /WEB-INF/views/
spring.mvc.view.suffix = .jsp
index.jsp 代码举例(哈哈,最简单jsp)
${data}
springboot启动代码举例
@Controller
@SpringBootApplication
public class Application implements CommandLineRunner
{
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
//注入service 举例
@Autowired
CustomerService customerService;
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args)
throws IOException
{
LOGGER.info("★★★★★★★★ now open Browser ★★★★★★★★ ");
//windows系统下自动打开浏览器,可根据需要调整url
Runtime.getRuntime().exec("cmd.exe /c start /min http://127.0.0.1:8080/");
}
@RequestMapping(value = "/")
public ModelAndView index()
{
ModelAndView modelAndView = new ModelAndView("index");
modelAndView.addObject("data", customerService.getAllCustomers());
return modelAndView;
}
}
运行效果
回答完毕, 希望帮到你 !
本人码云 https://gitee.com/00fly/ 欢迎访问!
如果是springboot项目的话其实可以
@RequestMapping(value="/")
以达到一开始页面便能加载数据
虽然low了点
思路二:** jsp里面直接操作**(已经调试通过)
<%@page import="com.fly.hbn.service.CustomerService"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%
ApplicationContext content = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
CustomerService customerService = content.getBean(CustomerService.class);
request.setAttribute("data2", customerService.getAllCustomers());
%>
<hr>
${data2}
运行结果
回答完毕,希望能帮到你!